threads / bug / 40945

git subtree bug produces divergent descendants

Subject: git subtree bug produces divergent descendants

## tl;dr

2 messages between Dec 6, 2015 and Dec 6, 2015.

replies: 1people: 1as markdown or json

David Ware· Dec 6, 2015, 20:41 UTC · lore

My group has run into a bug with "git-subtree split". Under some circumstances a split created from a descendant of another earlier split is not a descendant of that earlier split (thus blocking pushes). We originally noticed this on v1.9.1 but have also checked it on v2.6.3

When scanning the commits to produce the subtree it seems to skip creating a new commit if any of the parent commits have the same tree and instead uses that tree in its place. This is fine when the cause is a branch that did not cause any changes to the subtree. However it creates an issue when the cause is both branches ending up with the same tree through identical alterations (or more likely, one of the branches has just a subset of the alterations on the other, such as a branch just containing cherry-picks).

The attached bash script (makerepo.sh) reproduces the problem. To use create an empty directory and run the script in it. The resulting 'master' branch has had the latest commits on the 'branch' branch merged into it, so it follows that a subtree on 'folder/' at 'master' should contain all the commits of a subtree on 'folder/' at 'branch'. (These subtrees have been produced at 'subtree_tip' and 'subtree_branch' respectively.)

The attached patch (against v2.6.3) fixes the issue for the cases we've encountered, however since we're not particularly familiar with git internals we may not have approached this optimally. We suspect it could be improved to also handle the cases where there are more than 2 parents.

Cheers, Dave Ware

From 4bdcd742e5f21d7af57de3e307741efede7d2c6c Mon Sep 17 00:00:00 2001
From: Dave Ware <davidw@netvalue.net.nz>
Date: Fri, 4 Dec 2015 16:30:03 +1300
Subject: [PATCH] Fix bug in git-subtree split.
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. Fixed 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.
---
 contrib/subtree/git-subtree.sh | 12 ++++++++++--
 1 file changed, 10 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 $?
-- 
1.9.1
David Ware· Dec 6, 2015, 22:18 UTC · re: David Ware · lore

Re: git subtree bug produces divergent descendants

Sorry for the double post, I received a mail blocking notification message (due to the attached .sh file) and erroneously thought this message had been blocked from the entire list. My later one includes the test case as part of the attached patch.

Cheers, Dave Ware

On Mon, Dec 7, 2015 at 9:41 AM, David Ware <davidw@realtimegenomics.com> wrote:
Show 31 quoted lines
> My group has run into a bug with "git-subtree split". Under some
> circumstances a split created from a descendant of another earlier
> split is not a descendant of that earlier split (thus blocking
> pushes). We originally noticed this on v1.9.1 but have also checked it
> on v2.6.3
>
> When scanning the commits to produce the subtree it seems to skip
> creating a new commit if any of the parent commits have the same tree
> and instead uses that tree in its place. This is fine when the cause
> is a branch that did not cause any changes to the subtree.  However it
> creates an issue when the cause is both branches ending up with the
> same tree through identical alterations (or more likely, one of the
> branches has just a subset of the alterations on the other, such as a
> branch just containing cherry-picks).
>
> The attached bash script (makerepo.sh) reproduces the problem. To use
> create an empty directory and run the script in it. The resulting
> 'master' branch has had the latest commits on the 'branch' branch
> merged into it, so it follows that a subtree on 'folder/' at 'master'
> should contain all the commits of a subtree on 'folder/' at 'branch'.
> (These subtrees have been produced at 'subtree_tip' and
> 'subtree_branch' respectively.)
>
> The attached patch (against v2.6.3) fixes the issue for the cases
> we've encountered, however since we're not particularly familiar with
> git internals we may not have approached this optimally. We suspect it
> could be improved to also handle the cases where there are more than 2
> parents.
>
> Cheers,
> Dave Ware

← back to recent threads