git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/7] contrib/subtree: Handle '--prefix' argument with a slash appended

From
David Greene <greened@obbligato.org>
Date
Nov 13, 2015, 02:32 UTC
Message-ID
<1447381956-4771-8-git-send-email-greened@obbligato.org>
In-Reply-To
<1447381956-4771-1-git-send-email-greened@obbligato.org>
From: Techlive Zheng <techlivezheng@gmail.com>

'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>
---
 contrib/subtree/git-subtree.sh     |  2 +-
 contrib/subtree/t/t7900-subtree.sh | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 308b777..edf36f8 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -90,7 +90,7 @@ while [ $# -gt 0 ]; do
 		--annotate) annotate="$1"; shift ;;
 		--no-annotate) annotate= ;;
 		-b) branch="$1"; shift ;;
-		-P) prefix="$1"; shift ;;
+		-P) prefix="${1%/}"; shift ;;
 		-m) message="$1"; shift ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 2683d7d..751aee3 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -257,6 +257,26 @@ test_expect_success 'merge the added subproj again, should do nothing' '
 	)
 '
 
+next_test
+test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree add --prefix=subdir/ FETCH_HEAD
+	) &&
+	test_create_commit "$test_count/subproj" sub2 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		git subtree merge --prefix=subdir/ FETCH_HEAD &&
+		check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+	)
+'
+
 #
 # Tests for 'git subtree split'
 #
-- 
2.6.1
Previous: David GreeneNext: Jeff King
Message 8 of 11 in “contrib/subtree: Testsuite cleanup”
  1. 0/7 contrib/subtree: Testsuite cleanupDavid Greene, Nov 13, 2015
  2. 1/7 contrib/subtree: Clean and refactor test codeDavid Greene, Nov 13, 2015
  3. 2/7 contrib/subtree: Add test for missing subtreeDavid Greene, Nov 13, 2015
  4. 3/7 contrib/subtree: Add tests for subtree addDavid Greene, Nov 13, 2015
  5. 4/7 contrib/subtree: Add merge testsDavid Greene, Nov 13, 2015
  6. 5/7 contrib/subtree: Add split testsDavid Greene, Nov 13, 2015
  7. 6/7 contrib/subtree: Make each test self-containedDavid Greene, Nov 13, 2015
  8. 7/7 contrib/subtree: Handle '--prefix' argument with a slash appendedDavid Greene, Nov 13, 2015
  9. Jeff KingNov 13, 2015
  10. Alexey ShumkinNov 13, 2015
  11. David A. GreeneJan 13, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.