Skip to content

Commit 2a5c016

Browse files
erijoadmorgan
authored andcommitted
Make subrepo work when run in a worktree
In a worktree (created with git worktree add) there is no .git directory. It is instead a file. To make subrepo work correctly in that case, use the --git-common-dir argument to git rev-parse to find the path to the .git directory. In a regular directory it just prints .git, but in a worktree it prints the full path to the .git directory. Fix #361
1 parent d00edbe commit 2a5c016

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/git-subrepo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bash+:import :std can
2828

2929
VERSION=0.4.0
3030
REQUIRED_GIT_VERSION=2.7.0
31-
GIT_TMP=.git/tmp
31+
GIT_TMP="$(git rev-parse --git-common-dir 2> /dev/null || echo .git)/tmp"
3232

3333
# `git rev-parse` turns this into a getopt parser and a command usage message:
3434
GETOPT_SPEC="\

test/pull-worktree.t

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
source test/setup
6+
7+
use Test::More
8+
9+
clone-foo-and-bar
10+
11+
(
12+
cd $OWNER/foo
13+
git subrepo clone ../bar bar
14+
git worktree add -b test ../wt
15+
) &> /dev/null || die
16+
17+
(
18+
cd $OWNER/bar
19+
modify-files Bar
20+
) &> /dev/null || die
21+
22+
(
23+
cd $OWNER/wt
24+
git subrepo pull --all
25+
) &> /dev/null || die
26+
27+
(
28+
cd $OWNER/foo
29+
git merge test
30+
) &> /dev/null || die
31+
32+
{
33+
is "$(cat $OWNER/foo/bar/Bar)" \
34+
"a new line" \
35+
'bar/Bar content correct'
36+
}
37+
38+
done_testing
39+
40+
teardown

0 commit comments

Comments
 (0)