Skip to content

Commit

Permalink
Fallback to master if no such branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauko Quiroga committed Aug 29, 2021
1 parent 1153afe commit 3fd7d02
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ test: clean check-syntax-errors check-style check-types
test.doc:
@## Usage:
@##
@## make test.doc [branch="--ARG"]
@## make test.doc [branch=BRANCH]
@##
@## Examples:
@##
@## # Will check "master" in openfisca-doc.
@## make test.doc # will check "master" in openfisca-doc
@## make test.doc branch=test-doc # will check "test-doc" in openfisca-doc
@##
@## # Will check "test-doc" in openfisca-doc.
@## make test.doc branch=test-doc # will check "test-doc"
@##
@## # Will check "master" if "asdf1234" does not exist.
@## make test.doc branch=asdf1234 # will fallback to "master"
@##
@$(call help,$@:)
@${MAKE} test.doc.checkout
Expand All @@ -53,14 +59,25 @@ test.doc:
## Update the local copy of the doc.
test.doc.checkout:
@$(call help,$@:)
@[ ! -d doc ] && git clone ${repo} doc 1> /dev/null || :
@[ ! -d doc ] && git clone ${repo} doc || :
@cd doc && { \
git reset --hard ; \
git fetch --all ; \
[ $$(git branch --show-current) != "master" ] && git checkout master || : ; \
[ ${branch} != "master" ] && { git branch -D ${branch} ; git checkout ${branch} ; } || : ; \
git pull --ff-only origin ${branch} ; \
} 1> /dev/null
[ $$(git branch --show-current) != master ] && git checkout master || : ; \
[ ${branch} != "master" ] \
&& { \
{ \
git branch -D ${branch} 2> /dev/null ; \
git checkout ${branch} ; \
} \
&& git pull --ff-only origin ${branch} \
|| { \
>&2 echo "[!] The branch '${branch}' doesn't exist, checking out 'master' instead..." ; \
git pull --ff-only origin master ; \
} \
} \
|| git pull --ff-only origin master ; \
} 1> /dev/null

## Install doc dependencies.
test.doc.install:
Expand Down

0 comments on commit 3fd7d02

Please sign in to comment.