diff --git a/shrinkwrap/utils/config.py b/shrinkwrap/utils/config.py index 2e03147beae0e7dbab43d3a0712971affe724564..d23333cf57bdd947102974b5121d1dbc6e3a13fb 100644 --- a/shrinkwrap/utils/config.py +++ b/shrinkwrap/utils/config.py @@ -926,12 +926,12 @@ def build_graph(configs, echo, nosync, force_sync): # We don't update any submodule before `git submodule sync`, # to handle the case where a remote changes the submodule's URL. # `git checkout` handles most cases, but doesn't update a local - # branch. So if gitrev is not a tag, do a `git reset`. + # branch. So if gitrev is a branch, do a `git reset` as well. sync_cmd_when_exists = f''' git remote set-url origin {gitremote} git fetch {gitargs}--prune --prune-tags --force --recurse-submodules=off origin git checkout {gitargs}--force {gitrev} - [ $(git tag -l {gitrev}) ] || git reset {gitargs}--hard origin/{gitrev} + git show-ref -q --heads {gitrev} && git reset {gitargs}--hard origin/{gitrev} git submodule {gitargs}sync --recursive git submodule {gitargs}update --init --checkout --recursive --force '''.strip() diff --git a/test/test-sync.sh b/test/test-sync.sh index 6de6563b5db4d604cf76c311866fd68998fcb812..ea26665c9f5f5331d7515a6e16e0a81a23aa77bb 100755 --- a/test/test-sync.sh +++ b/test/test-sync.sh @@ -155,7 +155,7 @@ TESTS Tag and branch update { pushd $T/repo1 echo -n "repo 1 commit 2" > README - git commit -a -m "commit 1" + git commit -a -m "commit 2" git tag v0.1 popd } >> $LOG @@ -240,7 +240,7 @@ TESTS Tag and branch udpates with --force-sync { pushd $T/repo1 echo -n "repo 1 commit 3" > README - git commit -a -m "commit 1" + git commit -a -m "commit 3" git tag v0.2 popd } >> $LOG @@ -539,4 +539,27 @@ OK "config sync=force updates" -o $T/overlay.yaml CONTENT $SHRINKWRAP_BUILD/source/base/test1/README "repo 1 commit 5" +################################################################################ +TESTS hash sync + +# Obtain hash of a specific commit +old_hash=$(git -C $T/repo1 show-ref --hash v0.1) + +cat << EOF > $T/overlay.yaml +build: + test1: + repo: + revision: $old_hash +EOF + +OK "switch to old git hash" -o $T/overlay.yaml +CONTENT $SHRINKWRAP_BUILD/source/base/test1/README "repo 1 commit 2" +OK "switch to main" +CONTENT $SHRINKWRAP_BUILD/source/base/test1/README "repo 1 commit 5" + +OK "switch to old git hash with --force-sync" -o $T/overlay.yaml --force-sync=test1 +CONTENT $SHRINKWRAP_BUILD/source/base/test1/README "repo 1 commit 2" +OK "switch to main with --force-sync" --force-sync=test1 +CONTENT $SHRINKWRAP_BUILD/source/base/test1/README "repo 1 commit 5" + echo ALL TESTS PASS