Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: do not move detached HEAD to attic if same commit #584

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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