aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-02 17:06:51 -0800
committerJunio C Hamano <gitster@pobox.com>2026-03-02 17:06:51 -0800
commit146487360cb0e08ec412b477347670e1a114c6ca (patch)
tree5ce2ffd9e67f31f1e8792946e9bccc1b24b43768
parentdbae219b2271d9dc05769820e47a0178f8d25e58 (diff)
parenta606fcdceb807b93013542e5e4d5f4c233aa6c83 (diff)
downloadgit-146487360cb0e08ec412b477347670e1a114c6ca.tar.xz
Merge branch 'ps/validate-prefix-in-subtree-split'
"git subtree split --prefix=P <commit>" now checks the prefix P against the tree of the (potentially quite different from the current working tree) given commit. * ps/validate-prefix-in-subtree-split: subtree: validate --prefix against commit in split
-rwxr-xr-xcontrib/subtree/git-subtree.sh9
-rwxr-xr-xcontrib/subtree/t/t7900-subtree.sh22
2 files changed, 31 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
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index e7040718f2..8024703cad 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -368,6 +368,28 @@ test_expect_success 'split requires path given by option --prefix must exist' '
)
'
+test_expect_success 'split works when prefix exists in commit but not in working tree' '
+ subtree_test_create_repo "$test_count" &&
+ (
+ cd "$test_count" &&
+
+ # create subtree
+ mkdir pkg &&
+ echo ok >pkg/file &&
+ git add pkg &&
+ git commit -m "add pkg" &&
+ good=$(git rev-parse HEAD) &&
+
+ # remove it from working tree in later commit
+ git rm -r pkg &&
+ git commit -m "remove pkg" &&
+
+ # must still be able to split using the old commit
+ git subtree split --prefix=pkg "$good" >out &&
+ test -s out
+ )
+'
+
test_expect_success 'split rejects flags for add' '
subtree_test_create_repo "$test_count" &&
subtree_test_create_repo "$test_count/sub proj" &&