public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH 0/1] bugfix git subtree split
@ 2026-05-24 21:23 Roland Conybeare
  2026-05-24 21:23 ` [PATCH 1/1] subtree: fix cache_set failure on commit reachable by multiple paths Roland Conybeare
  0 siblings, 1 reply; 2+ messages in thread
From: Roland Conybeare @ 2026-05-24 21:23 UTC (permalink / raw)
  To: git; +Cc: Roland Conybeare

I have a project that combines multiple independent repos
into an unmbrella repo, relying on git subtree.
Encountered a unrecoverable fatal error
from 'git subtree split' with error

    fatal: cache for <hash> already exists!

Problem arises because history to be split contains merge commits
that cause DAG traversal to consider the same umbrella commit on
multiple paths. The fatal triggers when 'git subtree split' tries
to cache the same commit twice; enclosed patch prunes these duplicate
paths.

Roland Conybeare (1):
  subtree: fix cache_set failure on commit reachable by multiple paths

 contrib/subtree/git-subtree.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)


base-commit: 6a4418c36d6bad69a599044b3cf49dcbd049cb45
--
2.50.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] subtree: fix cache_set failure on commit reachable by multiple paths
  2026-05-24 21:23 [PATCH 0/1] bugfix git subtree split Roland Conybeare
@ 2026-05-24 21:23 ` Roland Conybeare
  0 siblings, 0 replies; 2+ messages in thread
From: Roland Conybeare @ 2026-05-24 21:23 UTC (permalink / raw)
  To: git; +Cc: Roland Conybeare

When splitting a subtree, committs that do not intersect prefix
receive identity mapping (oldrev -> oldrev). If such commit
is reachable by multiple paths in the revision DAG, the cache_set()
function may be called twice for the same (oldrev -> newrev) pair.

This triggers fatal error "cache for <hash> already exists"

Bugfix is to make cache_set() idempotent when the same
(oldrev -> newrev) pair appears multiple times.

Signed-off-by: Roland Conybeare <rconybeare@gmail•com>
---
 contrib/subtree/git-subtree.sh | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 791fd8260c..64590e05e0 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -343,7 +343,13 @@ cache_set () {
 		test "$oldrev" != "latest_new" &&
 		test -e "$cachedir/$oldrev"
 	then
-		die "fatal: cache for $oldrev already exists!"
+		existing=$(cat "$cachedir/$oldrev")
+		if test "$existing" = "$newrev"
+		then
+			return
+		else
+			die "fatal: cache for $oldrev already exists!"
+		fi
 	fi
 	echo "$newrev" >"$cachedir/$oldrev"
 }
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-24 21:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-24 21:23 [PATCH 0/1] bugfix git subtree split Roland Conybeare
2026-05-24 21:23 ` [PATCH 1/1] subtree: fix cache_set failure on commit reachable by multiple paths Roland Conybeare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox