git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4] subtree: validate --prefix against commit in split

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 3, 2026, 17:37 UTC
Message-ID
<xmqqecn1u3rx.fsf@gitster.g>
In-Reply-To
<20260203164815.68258-2-pushkarkumarsingh1970@gmail.com>
Pushkar Singh <pushkarkumarsingh1970@gmail.com> writes:
> Changes since v3:
> - Fix regression in existing subtree tests by checking prefix existence
>   with git cat-file instead of git ls-tree -d
OK, the check used to run
    git ls-tree -d "$rev" -- "$dir"

which (if I am reading this correctly) succeeded only when "$dir" is an existing directory in "$rev". Now you use

    git cat-file -e "$rev:$dir" 2>/dev/null
and this allows "$dir" to be a non-directory but say a blob.
> - Preserve original error message to keep test 17 passing

Ahh, OK. I didn't check how the test was failing. This message is made to look like the error message we used to get much earlier before calling cmd_split, and now cmd_split detects the condition to give the error message, so it is better to match it. Makes sense.

Show 64 quoted lines
>  contrib/subtree/git-subtree.sh     |  9 +++++++++
>  contrib/subtree/t/t7900-subtree.sh | 22 ++++++++++++++++++++++
>  2 files changed, 31 insertions(+)
>
> 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 316dc5269e..e4f632f3af 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" &&
Previous: Pushkar Singh
Message 19 of 19 in “subtree: validate --prefix against commit in split”
  1. subtree: validate --prefix against commit in splitPushkar Singh, Jan 15, 2026
  2. subtree: validate --prefix against commit in splitPushkar Singh, Jan 15, 2026
  3. Junio C HamanoJan 15, 2026
  4. subtree: validate --prefix against commit in splitPushkar Singh, Jan 15, 2026
  5. Josh SteadmonFeb 2, 2026
  6. Junio C HamanoFeb 2, 2026
  7. Junio C HamanoFeb 2, 2026
  8. [RFH] adding test coverage for contrib/ in CI jobsJunio C Hamano, Feb 3, 2026
  9. Re* [RFH] adding test coverage for contrib/ in CI jobsJunio C Hamano, Feb 3, 2026
  10. Junio C HamanoFeb 3, 2026
  11. Re* [RFH] adding test coverage for contrib/ in CI jobsColin Stagner, Feb 4, 2026
  12. Junio C HamanoFeb 4, 2026
  13. Colin StagnerFeb 5, 2026
  14. Junio C HamanoFeb 5, 2026
  15. Junio C HamanoFeb 5, 2026
  16. Junio C HamanoFeb 3, 2026
  17. Jeff KingFeb 3, 2026
  18. subtree: validate --prefix against commit in splitPushkar Singh, Feb 3, 2026
  19. Junio C HamanoFeb 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.