From 21e168e6727e9fdce0462aeb40e1e9e3fbdca3f9 Mon Sep 17 00:00:00 2001 From: Kenneth Lareau Date: Mon, 4 Jun 2018 17:39:42 -0700 Subject: [PATCH 1/2] Add support for Git worktrees Fix some hardcoding of the .git directory, which is different for worktrees (.git is a file that points to a subdirectory in the main repository area) and ensure the 'hooks' directory exists for the worktree; this allows things like 'git gerrit submit' to properly function. --- git-gerrit | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/git-gerrit b/git-gerrit index 41c8227..b42efe8 100755 --- a/git-gerrit +++ b/git-gerrit @@ -1,7 +1,10 @@ #!/bin/bash +# Determine .git directory location (needed for worktrees) +GITCOMMONDIR=$(git rev-parse --git-common-dir) + # Where to store our private working information -DATADIR=.git/gerrit-submit +DATADIR=${GITCOMMONDIR}/gerrit-submit usage() { @@ -14,7 +17,7 @@ usage() cd_to_root() { - cd `git rev-parse --git-dir`/.. + cd $(git rev-parse --show-toplevel) } get_upstream() @@ -171,12 +174,12 @@ gerrit_submit() # Add hook - we could do this at "git gerrit init" time, but when using # the "repo" tool the hooks directory gets reset on "repo sync" so this # is safer - cat <<'EOF' > .git/hooks/prepare-commit-msg + cat <<'EOF' > ${GITCOMMONDIR}/hooks/prepare-commit-msg #!/bin/sh # Added automatically by git-gerrit git gerrit prepare-commit-msg $1 EOF - chmod 755 .git/hooks/prepare-commit-msg + chmod 755 ${GITCOMMONDIR}/hooks/prepare-commit-msg # Determine current working branch; save for prepare-commit-msg hook branch=`git rev-parse --abbrev-ref HEAD` From 32409faf2358f7830754c2c64dc9068b6610da78 Mon Sep 17 00:00:00 2001 From: Kenneth Lareau Date: Mon, 20 Aug 2018 12:37:20 -0700 Subject: [PATCH 2/2] Fix issue with GITCOMMONDIR setting (must be absolute path) --- git-gerrit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-gerrit b/git-gerrit index b42efe8..9266e99 100755 --- a/git-gerrit +++ b/git-gerrit @@ -1,7 +1,7 @@ #!/bin/bash # Determine .git directory location (needed for worktrees) -GITCOMMONDIR=$(git rev-parse --git-common-dir) +GITCOMMONDIR=$(cd $(git rev-parse --git-common-dir) && pwd) # Where to store our private working information DATADIR=${GITCOMMONDIR}/gerrit-submit