Skip to content

Commit d16031c

Browse files
weynhamzpeff
authored andcommitted
contrib/subtree: Handle '--prefix' argument with a slash appended
'git subtree merge' will fail if the argument of '--prefix' has a slash appended. Signed-off-by: Techlive Zheng <[email protected]> Signed-off-by: David A. Greene <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent 4371174 commit d16031c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ while [ $# -gt 0 ]; do
9090
--annotate) annotate="$1"; shift ;;
9191
--no-annotate) annotate= ;;
9292
-b) branch="$1"; shift ;;
93-
-P) prefix="$1"; shift ;;
93+
-P) prefix="${1%/}"; shift ;;
9494
-m) message="$1"; shift ;;
9595
--no-prefix) prefix= ;;
9696
--onto) onto="$1"; shift ;;

contrib/subtree/t/t7900-subtree.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,26 @@ test_expect_success 'merge the added subproj again, should do nothing' '
257257
)
258258
'
259259

260+
next_test
261+
test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
262+
test_create_repo "$test_count" &&
263+
test_create_repo "$test_count/subproj" &&
264+
test_create_commit "$test_count" main1 &&
265+
test_create_commit "$test_count/subproj" sub1 &&
266+
(
267+
cd "$test_count" &&
268+
git fetch ./subproj master &&
269+
git subtree add --prefix=subdir/ FETCH_HEAD
270+
) &&
271+
test_create_commit "$test_count/subproj" sub2 &&
272+
(
273+
cd "$test_count" &&
274+
git fetch ./subproj master &&
275+
git subtree merge --prefix=subdir/ FETCH_HEAD &&
276+
check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
277+
)
278+
'
279+
260280
#
261281
# Tests for 'git subtree split'
262282
#

0 commit comments

Comments
 (0)