Skip to content

Commit

Permalink
Merge pull request #584 from rhubert/rh-no-attic-detached-if-same-commit
Browse files Browse the repository at this point in the history
git: do not move detached HEAD to attic if same commit
  • Loading branch information
jkloetzke authored Sep 5, 2024
2 parents 99b2c94 + cf0b3d1 commit 080fc60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pym/bob/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/black-box/git-scm-switch/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
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

0 comments on commit 080fc60

Please sign in to comment.