Skip to content

Commit

Permalink
install: fix post-checkout hook
Browse files Browse the repository at this point in the history
We should skip running post-checkout hook on rebases and merges to not
accidentally break them in the middle of the process. Git doesn't
provide any native mechanisms for hooks to know whether or not this is a
rebase/merge that we are going through, but we can use
`.git/rebase-merge` existance as a marker.

Previous approach has only accounted for branches and was causing issues
when checking-out tags.

Fixes #3241
  • Loading branch information
efiop committed Jan 30, 2020
1 parent 90773ed commit 13ed7a1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ def install(self):
[
# checking out some reference and not specific file.
'[ "$3" = "1" ]',
# check that we are on some branch/tag and not in detached HEAD
# state, so we don't accidentally break a rebase.
'[ "$(git rev-parse --abbrev-ref HEAD)" != "HEAD" ]',
# make sure we are not in the middle of a rebase/merge, so we
# don't accidentally break it with an unsuccessful checkout.
# Note that git hooks are always running in repo root.
"[ ! -d .git/rebase-merge ]",
],
"checkout",
)
Expand Down

0 comments on commit 13ed7a1

Please sign in to comment.