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

[PATCH v3] contrib/subtree: fix "subtree split" skipped-merge bug

From
Dave Ware <davidw@realtimegenomics.com>
Date
Dec 8, 2015, 20:39 UTC
Message-ID
<1449607160-20608-1-git-send-email-davidw@realtimegenomics.com>
In-Reply-To
<CAPig+cR36772YDc5RQRwXP3+ucVWumim9HYTXVMuGXN2cnQ7Ow@mail.gmail.com>

A bug occurs in 'git-subtree split' where a merge is skipped even when both parents act on the subtree, provided the merge results in a tree identical to one of the parents. Fix by copying the merge if at least one parent is non-identical, and the non-identical parent is not an ancestor of the identical parent.

Also, add a test case which checks that a descendant can be pushed to its ancestor in this case.

Signed-off-by: Dave Ware <davidw@realtimegenomics.com>
---
Notes:
    Many thanks to Eric Sunshine for his adivce on this patch
    Changes since v2:
    - Minor improvements to commit message
    - Changed space indentation to tab indentation in test case
    - Changed use of rev-list for obtaining commit id to use rev-parse instead
    Changes since v1:
    - Minor improvements to commit message
    - Added sign off
    - Moved test case from own file into t7900-subtree.sh
    - Added subshell to test around 'cd'
    - Moved record of commit for cherry-pick to variable instead of dumping into file
    
    [v2]: http://thread.gmane.org/gmane.comp.version-control.git/282065/focus=282121
    [v1]: http://thread.gmane.org/gmane.comp.version-control.git/282065
 contrib/subtree/git-subtree.sh     | 12 +++++++--
 contrib/subtree/t/t7900-subtree.sh | 52 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 9f06571..b837531 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -479,8 +479,16 @@ copy_or_skip()
 			p="$p -p $parent"
 		fi
 	done
-	
-	if [ -n "$identical" ]; then
+
+	copycommit=
+	if [ -n "$identical" ] && [ -n "$nonidentical" ]; then
+		extras=$(git rev-list --boundary $identical..$nonidentical)
+		if [ -n "$extras" ]; then
+			# we need to preserve history along the other branch
+			copycommit=1
+		fi
+	fi
+	if [ -n "$identical" ] && [ -z "$copycommit" ]; then
 		echo $identical
 	else
 		copy_commit $rev $tree "$p" || exit $?
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 9051982..710278c 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -468,4 +468,56 @@ test_expect_success 'verify one file change per commit' '
 	))
 '
 
+test_expect_success 'subtree descendent check' '
+	mkdir git_subtree_split_check &&
+	(
+		cd git_subtree_split_check &&
+		git init &&
+
+		mkdir folder &&
+
+		echo a >folder/a &&
+		git add . &&
+		git commit -m "first commit" &&
+
+		git branch branch &&
+
+		echo 0 >folder/0 &&
+		git add . &&
+		git commit -m "adding 0 to folder" &&
+
+		echo b >folder/b &&
+		git add . &&
+		git commit -m "adding b to folder" &&
+		cherry=$(git rev-parse HEAD) &&
+
+		git checkout branch &&
+		echo text >textBranch.txt &&
+		git add . &&
+		git commit -m "commit to fiddle with branch: branch" &&
+
+		git cherry-pick $cherry &&
+		git checkout master &&
+		git merge -m "merge" branch &&
+
+		git branch noop_branch &&
+
+		echo d >folder/d &&
+		git add . &&
+		git commit -m "adding d to folder" &&
+
+		git checkout noop_branch &&
+		echo moreText >anotherText.txt &&
+		git add . &&
+		git commit -m "irrelevant" &&
+
+		git checkout master &&
+		git merge -m "second merge" noop_branch &&
+
+		git subtree split --prefix folder/ --branch subtree_tip master &&
+		git subtree split --prefix folder/ --branch subtree_branch branch &&
+		git push . subtree_tip:subtree_branch
+	)
+	'
+
 test_done
-- 
1.9.1
Previous: Eric SunshineNext: Junio C Hamano
Message 5 of 22 in “git subtree bug produces divergent descendants”
  1. David WareDec 6, 2015
  2. Eric SunshineDec 7, 2015
  3. contrib/subtree: fix "subtree split" skipped-merge bug.Dave Ware, Dec 7, 2015
  4. Eric SunshineDec 8, 2015
  5. contrib/subtree: fix "subtree split" skipped-merge bugDave Ware, Dec 8, 2015
  6. Junio C HamanoDec 8, 2015
  7. David WareDec 9, 2015
  8. contrib/subtree: fix "subtree split" skipped-merge bugDave Ware, Dec 9, 2015
  9. Eric SunshineDec 9, 2015
  10. contrib/subtree: fix "subtree split" skipped-merge bugDave Ware, Dec 9, 2015
  11. David A. GreeneJan 13, 2016
  12. David WareJan 13, 2016
  13. David A. GreeneJan 14, 2016
  14. David WareJan 14, 2016
  15. David A. GreeneJan 17, 2016
  16. contrib/subtree: fix "subtree split" skipped-merge bugDave Ware, Jan 14, 2016
  17. contrib/subtree: fix "subtree split" skipped-merge bugDave Ware, Jan 15, 2016
  18. Eric SunshineJan 15, 2016
  19. Junio C HamanoJan 15, 2016
  20. Eric SunshineJan 15, 2016
  21. David A. GreeneJan 17, 2016
  22. David WareDec 7, 2015

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.