Skip to content

Commit 8697c2f

Browse files
committed
Merge branch 'ps/validate-prefix-in-subtree-split' into seen
"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
2 parents a09cd4e + a606fcd commit 8697c2f

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

contrib/subtree/git-subtree.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ main () {
257257
test -e "$arg_prefix" &&
258258
die "fatal: prefix '$arg_prefix' already exists."
259259
;;
260+
split)
261+
# checked later against the commit, not the working tree
262+
;;
260263
*)
261264
test -e "$arg_prefix" ||
262265
die "fatal: '$arg_prefix' does not exist; use 'git subtree add'"
@@ -966,6 +969,12 @@ cmd_split () {
966969
else
967970
die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
968971
fi
972+
973+
# Now validate prefix against the commit, not the working tree
974+
if ! git cat-file -e "$rev:$dir" 2>/dev/null
975+
then
976+
die "fatal: '$dir' does not exist; use 'git subtree add'"
977+
fi
969978
repository=""
970979
if test "$#" = 2
971980
then

contrib/subtree/t/t7900-subtree.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,28 @@ test_expect_success 'split requires path given by option --prefix must exist' '
368368
)
369369
'
370370

371+
test_expect_success 'split works when prefix exists in commit but not in working tree' '
372+
subtree_test_create_repo "$test_count" &&
373+
(
374+
cd "$test_count" &&
375+
376+
# create subtree
377+
mkdir pkg &&
378+
echo ok >pkg/file &&
379+
git add pkg &&
380+
git commit -m "add pkg" &&
381+
good=$(git rev-parse HEAD) &&
382+
383+
# remove it from working tree in later commit
384+
git rm -r pkg &&
385+
git commit -m "remove pkg" &&
386+
387+
# must still be able to split using the old commit
388+
git subtree split --prefix=pkg "$good" >out &&
389+
test -s out
390+
)
391+
'
392+
371393
test_expect_success 'split rejects flags for add' '
372394
subtree_test_create_repo "$test_count" &&
373395
subtree_test_create_repo "$test_count/sub proj" &&

0 commit comments

Comments
 (0)