From 9d0c9c63880561fccd3368ba32d7157d197f20e7 Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:45:57 -0400 Subject: [PATCH 1/4] Update README with "common" remote Add instructions for adding subtree using a remote called "common". You need the remote to properly contribute back upstream from a child project. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8aa1cbe..aa433cb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ ```bash # Add the subtree as a remote -git subtree add --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main --squash +git remote add common git@gitlab.ducoterra.net:services/common.git +git subtree add --prefix .gitlab common main # Now you can run the following to update make make-update From d86b5052a8c5947bbd7bb6ca47128bc0d54b571c Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:46:53 -0400 Subject: [PATCH 2/4] Add PROJECT_NAME and VERSION Add PROJECT_NAME and VERSION variables to Makefile. --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4eb7ed6..d504165 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ SHELL := /bin/bash -IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) +PROJECT_NAME ?= $(shell git config --local remote.origin.url|sed -n 's#.*/\([^.]*\)\.git#\1#p') +VERSION ?= $(shell cat VERSION) +IMAGE ?= $(shell cat IMAGE):$(VERSION) IMAGE_LATEST ?= $(shell cat IMAGE):latest PWD ?= $(shell pwd) STASH ?= "common-update-stash" From 3c91292feac91a14185bd2fca8b5981412d2903b Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:47:29 -0400 Subject: [PATCH 3/4] Make user stash their own damn changes Stashing is so annoying to deal with in a scripted way. Just force the user to stash their own changes. Only subtree pull if it's possible. --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d504165..6e1f49f 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,7 @@ make-stash-drop: .PHONY: make-update make-update: - @git stash save $(STASH) - -git subtree pull --prefix .gitlab git@gitlab.ducoterra.net:services/common.git main - @if [ ! -z "$$(git stash list | grep -r 'stash@{0}.*common')" ]; then git stash pop; fi + @git subtree pull --prefix .gitlab --message "Merge update from Common" -q common main .PHONY: make-push make-push: warning From c3e6d733c669cfa97f383ee00fd1479f1f65371f Mon Sep 17 00:00:00 2001 From: ducoterra Date: Tue, 2 Nov 2021 11:48:15 -0400 Subject: [PATCH 4/4] Switch to "subtree split" push strategy Split the subtree into a new branch before pushing to common. This creates a new branch automatically and ensures no weird histories get committed to common. --- Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 6e1f49f..20a9590 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,5 @@ make-update: .PHONY: make-push make-push: warning @make make-update - @git remote add common git@gitlab.ducoterra.net:services/common.git - @git subtree push --prefix .gitlab common main - @git remote remove common - @make make-update + @git subtree split --branch common/$(PROJECT_NAME) --prefix .gitlab + @git push common common/$(PROJECT_NAME):common/$(PROJECT_NAME)