Skip to content

Commit 6f2012c

Browse files
committed
If someone provides a --prefix that ends with slash, strip the slash.
Prefixes that differ only in the trailing slash should be considered identical. Also update the test to check that this works.
1 parent 39ee6ec commit 6f2012c

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

git-subtree.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ esac
102102
if [ -z "$prefix" ]; then
103103
die "You must provide the --prefix option."
104104
fi
105-
dir="$prefix"
105+
dir="$(dirname "$prefix/.")"
106106

107107
if [ "$command" != "pull" ]; then
108108
revs=$(git rev-parse $default --revs-only "$@") || exit $?
@@ -175,7 +175,7 @@ find_latest_squash()
175175
sq=
176176
main=
177177
sub=
178-
git log --grep="^git-subtree-dir: $dir\$" \
178+
git log --grep="^git-subtree-dir: $dir/*\$" \
179179
--pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
180180
while read a b junk; do
181181
debug "$a $b $junk"
@@ -210,7 +210,7 @@ find_existing_splits()
210210
revs="$2"
211211
main=
212212
sub=
213-
git log --grep="^git-subtree-dir: $dir\$" \
213+
git log --grep="^git-subtree-dir: $dir/*\$" \
214214
--pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
215215
while read a b junk; do
216216
case "$a" in

test.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ git branch subdir
8282

8383
git fetch ../subproj sub1
8484
git branch sub1 FETCH_HEAD
85-
git subtree add --prefix=subdir FETCH_HEAD
85+
git subtree add --prefix=subdir/ FETCH_HEAD
8686

8787
# this shouldn't actually do anything, since FETCH_HEAD is already a parent
8888
git merge -m 'merge -s -ours' -s ours FETCH_HEAD
@@ -118,7 +118,7 @@ create sub9
118118
git commit -m 'sub9'
119119

120120
cd ../mainline
121-
split2=$(git subtree split --annotate='*' --prefix subdir --rejoin)
121+
split2=$(git subtree split --annotate='*' --prefix subdir/ --rejoin)
122122
git branch split2 "$split2"
123123

124124
create subdir/main-sub10

todo

-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
one of the other git tools that git-subtree calls. Should
3737
detect this situation and print the *real* problem.
3838

39-
In fact, the prefix should *not* end with slash, and we
40-
should detect (and fix) it if it does. Otherwise the
41-
log message looks weird.
42-
4339
"pull --squash" should do fetch-synthesize-merge, but instead just
4440
does "pull" directly, which doesn't work at all.
4541

0 commit comments

Comments
 (0)