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

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

From
Techlive Zheng <techlivezheng@gmail.com>
Date
Jan 13, 2013, 01:52 UTC
Message-ID
<1358041958-1998-8-git-send-email-techlivezheng@gmail.com>
In-Reply-To
<1358041958-1998-1-git-send-email-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>
---
 contrib/subtree/git-subtree.sh     |  2 +-
 contrib/subtree/t/t7900-subtree.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 018ee32..574ff04 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -83,7 +83,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 1492303..8e09606 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -238,6 +238,25 @@ test_expect_success 'merge new subproj history into subdir/ with --squash and --
     )
 '
 
+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 &&
+        test_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+    )
+'
+
 #
 # Tests for 'git subtree split'
 #
-- 
1.8.1
Previous: Techlive ZhengNext: Techlive Zheng
Message 9 of 18 in “mutiple improvements”
  1. 0/7 mutiple improvementsTechlive Zheng, Jan 13, 2013
  2. 1/7 contrib/subtree: Add vim modelineTechlive Zheng, Jan 13, 2013
  3. 2/7 contrib/subtree: Ignore testing directoryTechlive Zheng, Jan 13, 2013
  4. 3/7 contrib/subtree: Remove test number commentsTechlive Zheng, Jan 13, 2013
  5. 4/7 contrib/subtree: Code cleaning and refactoringTechlive Zheng, Jan 13, 2013
  6. 郑文辉 (Techlive Zheng)Jan 14, 2013
  7. 5/7 contrib/subtree: Make each test self-containedTechlive Zheng, Jan 13, 2013
  8. 6/7 contrib/subtree: Use %B for the split commit messageTechlive Zheng, Jan 13, 2013
  9. 7/7 contrib/subtree: Handle '--prefix' argument with a slash appendedTechlive Zheng, Jan 13, 2013
  10. 0/8 contrib/subtree: Reroll to follow Git's whitespace policyTechlive Zheng, Jan 14, 2013
  11. 1/8 contrib/subtree: Fix whitespacesTechlive Zheng, Jan 14, 2013
  12. 2/8 contrib/subtree: Add vim modelineTechlive Zheng, Jan 14, 2013
  13. 3/8 contrib/subtree: Ignore testing directoryTechlive Zheng, Jan 14, 2013
  14. 4/8 contrib/subtree: Remove test number commentsTechlive Zheng, Jan 14, 2013
  15. 5/8 contrib/subtree: Code cleaning and refactoringTechlive Zheng, Jan 14, 2013
  16. 6/8 contrib/subtree: Make each test self-containedTechlive Zheng, Jan 14, 2013
  17. 7/8 contrib/subtree: Use %B for the split commit messageTechlive Zheng, Jan 14, 2013
  18. 8/8 contrib/subtree: Handle '--prefix' argument with a slash appendedTechlive Zheng, Jan 14, 2013

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.