aboutsummaryrefslogtreecommitdiff
path: root/contrib/subtree/git-subtree.sh
diff options
context:
space:
mode:
authorPushkar Singh <pushkarkumarsingh1970@gmail.com>2026-02-03 16:48:16 +0000
committerJunio C Hamano <gitster@pobox.com>2026-02-03 09:26:45 -0800
commita606fcdceb807b93013542e5e4d5f4c233aa6c83 (patch)
treeba8a94c783e2175b5a1e66cff9a49af7bbba9c55 /contrib/subtree/git-subtree.sh
parentd529f3a197364881746f558e5652f0236131eb86 (diff)
downloadgit-a606fcdceb807b93013542e5e4d5f4c233aa6c83.tar.xz
subtree: validate --prefix against commit in split
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 cat-file instead of the working tree. Add a test to ensure this behavior does not regress. Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/subtree/git-subtree.sh')
-rwxr-xr-xcontrib/subtree/git-subtree.sh9
1 files changed, 9 insertions, 0 deletions
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 17106d1a72..d7f9121f2f 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 cat-file -e "$rev:$dir" 2>/dev/null
+ then
+ die "fatal: '$dir' does not exist; use 'git subtree add'"
+ fi
repository=""
if test "$#" = 2
then