From 6ab85c2fbf66dc9932dfabad620b11e8f7bd9b81 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 30 Jan 2020 02:09:27 +0200 Subject: [PATCH 1/2] install: fix post-checkout hook 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 --- dvc/scm/git/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index ad1fcb2da2..63fc63506c 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -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 dvc checkout. + # Note that git hooks are always running in repo root. + '[ ! -d .git/rebase-merge ]' ], "checkout", ) From a04acced6e19f3b9808b06d91442760ea0eba830 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 30 Jan 2020 00:17:11 +0000 Subject: [PATCH 2/2] Restyled by black --- dvc/scm/git/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index 63fc63506c..2dd55d38e5 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -278,7 +278,7 @@ def install(self): # make sure we are not in the middle of a rebase/merge, so we # don't accidentally break it with an unsuccessful dvc checkout. # Note that git hooks are always running in repo root. - '[ ! -d .git/rebase-merge ]' + "[ ! -d .git/rebase-merge ]", ], "checkout", )