{"thread":{"id":"64858","subject":"[PATCH v4 0/1] subtree: validate --prefix against commit in split","startedAt":"2026-01-23T14:27:28Z","lastAt":"2026-01-23T17:37:28Z","messageCount":3,"participants":["Pushkar Singh","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":1},"messages":[{"id":"534541","messageId":"20260123142658.15516-2-pushkarkumarsingh1970@gmail.com","threadId":"64858","inReplyTo":null,"subject":"[PATCH v4 0/1] subtree: validate --prefix against commit in split","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-01-23T14:26:56Z","receivedAt":"2026-01-23T14:27:28Z","isPatch":true,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"Changes in v4:\n * fix indentation in the case statement\n * add a regression test to ensure --prefix is validated against the\n   target commit rather than the working tree\n\nNo functional changes beyond the above.\n\nPushkar Singh (1):\n  subtree: validate --prefix against commit in split\n\n contrib/subtree/git-subtree.sh     |  9 +++++++++\n contrib/subtree/t/t7900-subtree.sh | 22 ++++++++++++++++++++++\n 2 files changed, 31 insertions(+)\n\n-- \n2.43.0\n\n"},{"id":"534548","messageId":"20260123143552.15572-2-pushkarkumarsingh1970@gmail.com","threadId":"64858","inReplyTo":"20260123142658.15516-2-pushkarkumarsingh1970@gmail.com","subject":"[PATCH v4 1/1] subtree: validate --prefix against commit in split","fromName":"Pushkar Singh","fromEmail":"pushkarkumarsingh1970@gmail.com","sentAt":"2026-01-23T14:35:53Z","receivedAt":"2026-01-23T14:37:43Z","isPatch":true,"sender":{"key":"pushkarkumarsingh1970@gmail.com","avatar":"https://avatars.githubusercontent.com/u/173247767?v=4"},"body":"git subtree split currently validates --prefix against the working tree.\nThis breaks when splitting an older commit or when the working tree does\nnot contain the subtree, even though the commit does.\n\nFor example:\n\n  git subtree split --prefix=pkg <commit>\n\nfails if pkg was removed later, even though it exists in <commit>.\n\nFix this by validating the prefix against the specified commit using\ngit ls-tree instead of the working tree.\n\nAdd a test to ensure this behavior does not regress.\n\nAddress review feedback by fixing indentation and adding regression test.\n\nSigned-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com>\n---\n contrib/subtree/git-subtree.sh     |  9 +++++++++\n contrib/subtree/t/t7900-subtree.sh | 22 ++++++++++++++++++++++\n 2 files changed, 31 insertions(+)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 17106d1a72..324ed38148 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -257,6 +257,9 @@ main () {\n \t\ttest -e \"$arg_prefix\" &&\n \t\t\tdie \"fatal: prefix '$arg_prefix' already exists.\"\n \t\t;;\n+\tsplit)\n+\t\t# checked later against the commit, not the working tree\n+\t\t;;\n \t*)\n \t\ttest -e \"$arg_prefix\" ||\n \t\t\tdie \"fatal: '$arg_prefix' does not exist; use 'git subtree add'\"\n@@ -966,6 +969,12 @@ cmd_split () {\n \telse\n \t\tdie \"fatal: you must provide exactly one revision, and optionally a repository.  Got: '$*'\"\n \tfi\n+\n+\t# Now validate prefix against the commit, not the working tree\n+\tif ! git ls-tree -d \"$rev\" -- \"$dir\" >/dev/null\n+\tthen\n+\t\tdie \"fatal: '$dir' does not exist in commit $rev\"\n+\tfi\n \trepository=\"\"\n \tif test \"$#\" = 2\n \tthen\ndiff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh\nindex 316dc5269e..e4f632f3af 100755\n--- a/contrib/subtree/t/t7900-subtree.sh\n+++ b/contrib/subtree/t/t7900-subtree.sh\n@@ -368,6 +368,28 @@ test_expect_success 'split requires path given by option --prefix must exist' '\n \t)\n '\n \n+test_expect_success 'split works when prefix exists in commit but not in working tree' '\n+\tsubtree_test_create_repo \"$test_count\" &&\n+\t(\n+\t\tcd \"$test_count\" &&\n+\n+\t\t# create subtree\n+\t\tmkdir pkg &&\n+\t\techo ok >pkg/file &&\n+\t\tgit add pkg &&\n+\t\tgit commit -m \"add pkg\" &&\n+\t\tgood=$(git rev-parse HEAD) &&\n+\n+\t\t# remove it from working tree in later commit\n+\t\tgit rm -r pkg &&\n+\t\tgit commit -m \"remove pkg\" &&\n+\n+\t\t# must still be able to split using the old commit\n+\t\tgit subtree split --prefix=pkg \"$good\" >out &&\n+\t\ttest -s out\n+\t)\n+'\n+\n test_expect_success 'split rejects flags for add' '\n \tsubtree_test_create_repo \"$test_count\" &&\n \tsubtree_test_create_repo \"$test_count/sub proj\" &&\n-- \n2.43.0\n\n"},{"id":"534569","messageId":"xmqqwm18grhm.fsf@gitster.g","threadId":"64858","inReplyTo":"20260123142658.15516-2-pushkarkumarsingh1970@gmail.com","subject":"Re: [PATCH v4 0/1] subtree: validate --prefix against commit in split","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-01-23T17:37:25Z","receivedAt":"2026-01-23T17:37:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pushkar Singh <pushkarkumarsingh1970@gmail.com> writes:\n\n> Changes in v4:\n>  * fix indentation in the case statement\n>  * add a regression test to ensure --prefix is validated against the\n>    target commit rather than the working tree\n>\n> No functional changes beyond the above.\n\nThis seems to be identical to v3, which already had the fix to the\ncase and addition of tests.\n\nhttps://lore.kernel.org/git/20260115175403.3971-3-pushkarkumarsingh1970@gmail.com/\n\n"}]}