2021-02-09 17:05:00 +01:00
|
|
|
|
##
|
|
|
|
|
# SUBREPO
|
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepo-branch-delete: Delete branch $(BRANCH) on remote $(SUBREPO)
|
2021-06-01 01:50:11 +02:00
|
|
|
|
.PHONY: subrepo-branch-delete
|
2022-05-07 15:04:44 +02:00
|
|
|
|
subrepo-branch-delete: myos-user subrepo-check
|
2021-06-01 01:50:11 +02:00
|
|
|
|
ifneq ($(words $(BRANCH)),0)
|
2021-06-16 13:19:52 +02:00
|
|
|
|
[ $$(git ls-remote --heads $(REMOTE) $(BRANCH) 2>/dev/null |wc -l) -eq 1 ] \
|
|
|
|
|
&& $(RUN) git push $(REMOTE) :$(BRANCH)
|
2021-06-01 01:50:11 +02:00
|
|
|
|
endif
|
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepo-check: Define SUBREPO and REMOTE
|
2021-02-09 17:05:00 +01:00
|
|
|
|
.PHONY: subrepo-check
|
|
|
|
|
subrepo-check:
|
|
|
|
|
ifeq ($(words $(ARGS)), 0)
|
|
|
|
|
ifeq ($(words $(SUBREPO)), 0)
|
|
|
|
|
$(error Please provide a SUBREPO)
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
$(eval SUBREPO ?= $(word 1, $(ARGS)))
|
|
|
|
|
$(eval REMOTE := subrepo/$(SUBREPO))
|
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepo-git-diff: Check if monorepo is up to date with subrepo
|
|
|
|
|
# subrepo-push saves the parent commit in file subrepo/.gitrepo
|
|
|
|
|
## it gets parent commit in .gitrepo : awk '$1 == "parent" {print $3}' subrepo/.gitrepo
|
|
|
|
|
## it gets child of parent commit : git rev-list --ancestry-path parent..HEAD |tail -n 1
|
|
|
|
|
## it compares child commit with our tree : git diff --quiet child -- subrepo
|
2021-06-01 01:50:11 +02:00
|
|
|
|
.PHONY: subrepo-git-diff
|
2022-05-07 15:04:44 +02:00
|
|
|
|
subrepo-git-diff: myos-user subrepo-check
|
2021-06-13 02:09:57 +02:00
|
|
|
|
$(eval IGNORE_DRYRUN := true)
|
2021-06-16 13:19:52 +02:00
|
|
|
|
$(eval DIFF = $(shell git diff --quiet $(shell git rev-list --ancestry-path $(shell awk '$$1 == "parent" {print $$3}' $(SUBREPO)/.gitrepo)..HEAD |tail -n 1) -- $(SUBREPO); printf '$$?\n') )
|
2021-06-13 02:09:57 +02:00
|
|
|
|
$(eval IGNORE_DRYRUN := false)
|
2021-06-01 01:50:11 +02:00
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepo-git-fetch: Fetch git remote
|
2021-06-01 01:50:11 +02:00
|
|
|
|
.PHONY: subrepo-git-fetch
|
2022-05-07 15:04:44 +02:00
|
|
|
|
subrepo-git-fetch: myos-user subrepo-check
|
2021-06-16 13:19:52 +02:00
|
|
|
|
$(RUN) git fetch --prune $(REMOTE)
|
2021-02-09 17:05:00 +01:00
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepo-tag-create-%: Create tag TAG to reference branch REMOTE/%
|
2021-02-09 17:05:00 +01:00
|
|
|
|
.PHONY: subrepo-tag-create-%
|
2022-05-07 15:04:44 +02:00
|
|
|
|
subrepo-tag-create-%: myos-user subrepo-check subrepo-git-fetch
|
2021-02-09 17:05:00 +01:00
|
|
|
|
ifneq ($(words $(TAG)),0)
|
2021-06-16 13:19:52 +02:00
|
|
|
|
[ $$(git ls-remote --tags $(REMOTE) $(TAG) |wc -l) -eq 0 ] \
|
|
|
|
|
|| $(call exec,$(RUN) git push $(REMOTE) :refs/tags/$(TAG))
|
|
|
|
|
$(RUN) git push $(REMOTE) refs/remotes/subrepo/$(SUBREPO)/$*:refs/tags/$(TAG)
|
2021-02-09 17:05:00 +01:00
|
|
|
|
endif
|
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepo-push: Push to subrepo
|
2021-02-09 17:05:00 +01:00
|
|
|
|
.PHONY: subrepo-push
|
2022-05-07 15:04:44 +02:00
|
|
|
|
subrepo-push: myos-user subrepo-check subrepo-git-fetch subrepo-git-diff
|
2021-02-09 17:05:00 +01:00
|
|
|
|
# update .gitrepo only on master branch
|
|
|
|
|
ifeq ($(BRANCH),master)
|
|
|
|
|
$(eval UPDATE_SUBREPO_OPTIONS += -u)
|
|
|
|
|
endif
|
2021-06-14 12:52:48 +02:00
|
|
|
|
# if specific branch name, delete remote branch before push and recreate it from master
|
|
|
|
|
ifneq ($(findstring $(firstword $(subst /, ,$(BRANCH))),feature hotfix release story),)
|
2021-06-13 02:09:57 +02:00
|
|
|
|
$(eval IGNORE_DRYRUN := true)
|
2021-06-16 13:19:52 +02:00
|
|
|
|
$(eval DELETE = $(shell sh -c 'git ls-remote --heads $(REMOTE) $(BRANCH) |wc -l') )
|
2021-06-13 02:09:57 +02:00
|
|
|
|
$(eval IGNORE_DRYRUN := false)
|
2021-02-09 17:05:00 +01:00
|
|
|
|
else
|
|
|
|
|
$(eval DELETE = 0)
|
|
|
|
|
endif
|
|
|
|
|
if [ $(DIFF) -eq 0 ]; then \
|
2021-06-14 12:52:48 +02:00
|
|
|
|
$(call INFO,subrepo $(SUBREPO) already up to date); \
|
2021-02-09 17:05:00 +01:00
|
|
|
|
else \
|
|
|
|
|
if [ $(DELETE) -eq 1 ]; then \
|
2021-06-16 13:19:52 +02:00
|
|
|
|
$(RUN) git push $(REMOTE) :$(BRANCH); \
|
|
|
|
|
$(RUN) git push $(REMOTE) refs/remotes/$(REMOTE)/master:refs/heads/$(BRANCH); \
|
2021-02-09 17:05:00 +01:00
|
|
|
|
fi; \
|
2021-06-16 13:19:52 +02:00
|
|
|
|
$(RUN) git subrepo fetch $(SUBREPO) -b $(BRANCH); \
|
|
|
|
|
$(RUN) git subrepo push $(SUBREPO) -b $(BRANCH) $(UPDATE_SUBREPO_OPTIONS); \
|
|
|
|
|
$(RUN) git subrepo clean $(SUBREPO); \
|
2021-02-09 17:05:00 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepos-branch-delete: Fire APPS target
|
2021-02-09 17:05:00 +01:00
|
|
|
|
.PHONY: subrepos-branch-delete
|
|
|
|
|
subrepos-branch-delete: $(APPS) ;
|
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepos-tag-create-%: Fire APPS target
|
2021-02-09 17:05:00 +01:00
|
|
|
|
.PHONY: subrepos-tag-create-%
|
|
|
|
|
subrepos-tag-create-%: $(APPS) ;
|
2021-05-31 20:52:49 +02:00
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepos-update: Fire APPS target and push updates to upstream
|
2021-05-31 20:52:49 +02:00
|
|
|
|
.PHONY: subrepos-update
|
2022-05-07 15:04:44 +02:00
|
|
|
|
subrepos-update: myos-user git-stash $(APPS) git-unstash ## Update subrepos
|
2021-06-16 13:19:52 +02:00
|
|
|
|
$(RUN) git push upstream $(BRANCH)
|
2021-05-31 20:52:49 +02:00
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
|
# target subrepo-update-%: Call subrepo-update target in folder %
|
2021-05-31 20:52:49 +02:00
|
|
|
|
.PHONY: subrepo-update-%
|
|
|
|
|
subrepo-update-%:
|
|
|
|
|
$(if $(wildcard $*/Makefile),$(call make,subrepo-update,$*))
|