From 13ed7a1c32d9fc084dbefb6e74c421220d1a5d60 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 30 Jan 2020 02:09:27 +0200 Subject: [PATCH] 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..7d7f17648d 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 checkout. + # Note that git hooks are always running in repo root. + "[ ! -d .git/rebase-merge ]", ], "checkout", )