Skip to content

Commit 21e168e

Browse files
author
Kenneth Lareau
committed
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.
1 parent 2a4a1fd commit 21e168e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

git-gerrit

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/bash
22

3+
# Determine .git directory location (needed for worktrees)
4+
GITCOMMONDIR=$(git rev-parse --git-common-dir)
5+
36
# Where to store our private working information
4-
DATADIR=.git/gerrit-submit
7+
DATADIR=${GITCOMMONDIR}/gerrit-submit
58

69
usage()
710
{
@@ -14,7 +17,7 @@ usage()
1417

1518
cd_to_root()
1619
{
17-
cd `git rev-parse --git-dir`/..
20+
cd $(git rev-parse --show-toplevel)
1821
}
1922

2023
get_upstream()
@@ -171,12 +174,12 @@ gerrit_submit()
171174
# Add hook - we could do this at "git gerrit init" time, but when using
172175
# the "repo" tool the hooks directory gets reset on "repo sync" so this
173176
# is safer
174-
cat <<'EOF' > .git/hooks/prepare-commit-msg
177+
cat <<'EOF' > ${GITCOMMONDIR}/hooks/prepare-commit-msg
175178
#!/bin/sh
176179
# Added automatically by git-gerrit
177180
git gerrit prepare-commit-msg $1
178181
EOF
179-
chmod 755 .git/hooks/prepare-commit-msg
182+
chmod 755 ${GITCOMMONDIR}/hooks/prepare-commit-msg
180183

181184
# Determine current working branch; save for prepare-commit-msg hook
182185
branch=`git rev-parse --abbrev-ref HEAD`

0 commit comments

Comments
 (0)