From cf0b3d11237b8b85f35ea512f4c01238f285ab40 Mon Sep 17 00:00:00 2001 From: Ralf Hubert Date: Thu, 5 Sep 2024 11:25:56 +0200 Subject: [PATCH] git: do not move detached HEAD to attic if same commit If a git-workspace is in a detached HEAD state and the recipe has been updated to point to the same commit there is no need to move this into attic. --- pym/bob/scm/git.py | 2 +- test/black-box/git-scm-switch/run.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pym/bob/scm/git.py b/pym/bob/scm/git.py index d6b5073c8..53b22bfce 100644 --- a/pym/bob/scm/git.py +++ b/pym/bob/scm/git.py @@ -598,7 +598,7 @@ async def switch(self, invoker, oldScm): curCommit = await invoker.checkOutputCommand(["git", "rev-parse", "HEAD"], cwd=self.__dir) - if curCommit != oldCommit: + if curCommit != oldCommit and curCommit != self.__commit: invoker.fail("Cannot switch: user moved to different commit: {} vs. {}".format(curCommit, oldCommit)) # Try to checkout new state in old workspace. If something fails the diff --git a/test/black-box/git-scm-switch/run.sh b/test/black-box/git-scm-switch/run.sh index b7ebcc807..6a679247a 100755 --- a/test/black-box/git-scm-switch/run.sh +++ b/test/black-box/git-scm-switch/run.sh @@ -185,3 +185,29 @@ run_bob dev -DSCM_DIR="$git_dir1" -DSCM_REV="$d1_c1" -DSCM_BRANCH=foobar root2 - ls -la dev/src/root2/1/workspace expect_output "hello world" cat dev/src/root2/1/workspace/test.txt expect_not_exist dev/src/root2/1/attic + +# detached HEAD handling +cleanup +run_bob dev -DSCM_DIR="$git_dir1" -DSCM_REV="$d1_c0" root + +# move to detached HEAD state +pushd dev/src/root/1/workspace +git checkout $d1_c1 +echo canary > canary.txt +popd + +# run update to the same commit. No attic +run_bob dev -DSCM_DIR="$git_dir1" -DSCM_REV="$d1_c1" root +expect_not_exist dev/src/root/1/attic + +# commit the change and update to different commit -> attic +pushd dev/src/root/1/workspace +git config user.email "bob@bob.bob" +git config user.name test +git add . +git commit -m "local commit" +popd + +run_bob dev -DSCM_DIR="$git_dir1" -DSCM_REV="$d1_c2" root +expect_not_exist dev/src/root/1/workspace/canary +expect_exist dev/src/root/1/attic