Skip to content

Commit 4205137

Browse files
pushkarscriptsgitster
authored andcommitted
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 ls-tree instead of the working tree. Signed-off-by: Pushkar Singh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d529f3a commit 4205137

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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 ls-tree -d "$rev" -- "$dir" >/dev/null
975+
then
976+
die "fatal: '$dir' does not exist in commit $rev"
977+
fi
969978
repository=""
970979
if test "$#" = 2
971980
then

0 commit comments

Comments
 (0)