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 <techlivezheng@gmail.com> Signed-off-by: David A. Greene <greened@obbligato.org> Signed-off-by: Jeff King <peff@peff.net>

Techlive Zheng committed Nov 12, 2015 at 20:32 UTC d16031caf106dda2da52f10ef809cf4bfc83f7be
2 files changed +21 -1
contrib/subtree/git-subtree.sh
+1 -1
@@ -90,7 +90,7 @@ while [ $# -gt 0 ]; do
90 --annotate) annotate="$1"; shift ;;
91 --no-annotate) annotate= ;;
92 -b) branch="$1"; shift ;;
93 - -P) prefix="$1"; shift ;;
93 + -P) prefix="${1%/}"; shift ;;
94 -m) message="$1"; shift ;;
95 --no-prefix) prefix= ;;
96 --onto) onto="$1"; shift ;;
contrib/subtree/t/t7900-subtree.sh
+20
@@ -257,6 +257,26 @@ test_expect_success 'merge the added subproj again, should do nothing' '
257 )
258 '
259
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 +
280 #
281 # Tests for 'git subtree split'
282 #