From: Pushkar Singh Date: Thu, 15 Jan 2026 12:24:35 GMT Subject: [PATCH v2] subtree: validate --prefix against commit in split 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 fails if pkg was removed later, even though it exists in . Fix this by validating the prefix against the specified commit using git ls-tree instead of the working tree. Signed-off-by: Pushkar Singh --- 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