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

[PATCH v2] subtree: validate --prefix against commit in split

From
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Date
Jan 15, 2026, 12:24 UTC
Message-ID
<20260115122652.18673-2-pushkarkumarsingh1970@gmail.com>
In-Reply-To
<20260115120936.18491-1-pushkarkumarsingh1970@gmail.com>

git subtree split currently validates --prefix against the working tree. This breaks when splitting an older commit or when the working tree does not contain the subtree, even though the commit does.

For example:
  git subtree split --prefix=pkg <commit>
fails if pkg was removed later, even though it exists in <commit>.

Fix this by validating the prefix against the specified commit using git ls-tree instead of the working tree.

Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
---
 contrib/subtree/git-subtree.sh | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 17106d1a72..a5822b66d5 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -257,6 +257,9 @@ main () {
 		test -e "$arg_prefix" &&
 			die "fatal: prefix '$arg_prefix' already exists."
 		;;
+	split)
+        # checked later against the commit, not the working tree
+        ;;
 	*)
 		test -e "$arg_prefix" ||
 			die "fatal: '$arg_prefix' does not exist; use 'git subtree add'"
@@ -966,6 +969,12 @@ cmd_split () {
 	else
 		die "fatal: you must provide exactly one revision, and optionally a repository.  Got: '$*'"
 	fi
+
+	# Now validate prefix against the commit, not the working tree
+	if ! git ls-tree -d "$rev" -- "$dir" >/dev/null
+	then
+		die "fatal: '$dir' does not exist in commit $rev"
+	fi
 	repository=""
 	if test "$#" = 2
 	then
-- 
2.43.0
Previous: Pushkar SinghNext: Junio C Hamano
Message 2 of 19 in “subtree: validate --prefix against commit in split”
  1. subtree: validate --prefix against commit in splitPushkar Singh, Jan 15, 2026
  2. subtree: validate --prefix against commit in splitPushkar Singh, Jan 15, 2026
  3. Junio C HamanoJan 15, 2026
  4. subtree: validate --prefix against commit in splitPushkar Singh, Jan 15, 2026
  5. Josh SteadmonFeb 2, 2026
  6. Junio C HamanoFeb 2, 2026
  7. Junio C HamanoFeb 2, 2026
  8. [RFH] adding test coverage for contrib/ in CI jobsJunio C Hamano, Feb 3, 2026
  9. Re* [RFH] adding test coverage for contrib/ in CI jobsJunio C Hamano, Feb 3, 2026
  10. Junio C HamanoFeb 3, 2026
  11. Re* [RFH] adding test coverage for contrib/ in CI jobsColin Stagner, Feb 4, 2026
  12. Junio C HamanoFeb 4, 2026
  13. Colin StagnerFeb 5, 2026
  14. Junio C HamanoFeb 5, 2026
  15. Junio C HamanoFeb 5, 2026
  16. Junio C HamanoFeb 3, 2026
  17. Jeff KingFeb 3, 2026
  18. subtree: validate --prefix against commit in splitPushkar Singh, Feb 3, 2026
  19. Junio C HamanoFeb 3, 2026

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.