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

Re: [PATCH v5 1/2] t7501: add tests for --include and --only

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 16, 2024, 15:56 UTC
Message-ID
<xmqq1qah46i0.fsf@gitster.g>
In-Reply-To
<20240113042254.38602-2-shyamthakkar001@gmail.com>
Ghanshyam Thakkar <shyamthakkar001@gmail.com> writes:
> +test_expect_success 'fail to commit untracked pathspec (even with --include/--only)' '

"untracked pathspec" is a nonsense word. We do not track pathspec; you may use pathspec to specify which path(s) to work on. I think this is more about untracked files being ignored for the purpose of "-i" and "-o".

You used to call this "untracked file", which probably makes more sense.

> +	# TODO: as for --include, the below command will fail because nothing is
> +	# staged. If something was staged, it would not fail even if the
> +	# pathspec was untracked (however, pathspec will remain untracked and
> +	# staged changes would be committed.) In either cases, no error is

Both uses of "pathspec" here are nonsense. Saying "even though the pathspec does not match any tracked path" is OK. "(however, the untracked path that match the pathspec are not added and only the changes in the index gets commit)" is also OK.

Show 7 quoted lines
> +	# returned to stderr like in (-o and without -o/-i) cases. In a
> +	# similar manner, "git add -u baz" also does not error out.
> +	# 
> +	# Therefore, the below test is just to document the current behavior
> +	# and is not an endorsement to the current behavior, and we may 
> +	# want to fix this. And when that happens, this test should be
> +	# updated accordingly.
OK.
Show 19 quoted lines
> @@ -117,6 +143,55 @@ test_expect_success '--long with stuff to commit returns ok' '
>  	git commit -m next -a --long
>  '
>  
> +for opt in "" "-o" "--only"
> +do 
> +	test_expect_success 'exclude additional staged changes when given pathspec' '
> +		echo content >>file &&
> +		echo content >>baz &&
> +		git add baz &&
> +		git commit $opt -m "file" file &&
> +
> +		git diff --name-only >actual &&
> +		test_must_be_empty actual &&
> +
> +		git diff --name-only --staged >actual &&
> +		test_cmp - actual <<-EOF &&
> +		baz
> +		EOF
It is probably more common to say
		test_write_lines baz >expect &&
		git diff --name-only --cached >actual &&
		test_cmp expect actual

especially when the expected pattern is a file with short lines, instead of here-text. It makes it easier to debug tests, too, because after "sh t7501-*.sh -i" fails, you can go to the trash directory and the expectation as well as the actual output are there in files.

> +		git diff --name-only HEAD^ HEAD >actual &&
> +		test_cmp - actual <<-EOF
> +		file
> +		EOF
Ditto.

This tests the most important aspect of "-o"; even when the index has other changes relative to HEAD already, they are skipped over and only the changes to paths that match the given pathspec are committed, and this test demonstrates it. Well done.

Show 16 quoted lines
> +test_expect_success '-i/--include includes staged changes' '
> +	echo content >>file &&
> +	echo content >>baz &&
> +	git add file &&
> +	
> +	# baz is in the index, therefore, it will be committed
> +	git commit --include -m "file and baz" baz  &&
> +
> +	git diff --name-only HEAD >remaining &&
> +	test_must_be_empty remaining &&
> +
> +	git diff --name-only HEAD^ HEAD >changes &&
> +	test_cmp - changes <<-EOF
> +	baz
> +	file
> +	EOF

Again with "test_write_lines baz file >expect", this test becomes a bit shorter.

This tests the most important aspect of "-i"; changes to the paths that match the given pathspec are added to the index, and recorded together with changes added to the index already to the commit. Well done.

Show 13 quoted lines
> +'
> +
> +test_expect_success '--include and --only do not mix' '
> +	test_when_finished "git reset --hard" &&
> +	echo content >>file &&
> +	echo content >>baz &&
> +	test_must_fail git commit --include --only -m "file baz" file baz 2>actual &&
> +	test_grep -e "fatal: options .-i/--include. and .-o/--only. cannot be used together" actual
> +'
> +
>  test_expect_success 'commit message from non-existing file' '
>  	echo more bongo: bongo bongo bongo bongo >file &&
>  	test_must_fail git commit -F gah -a
Very nicely done.
Thanks.
Previous: Junio C HamanoNext: Ghanshyam Thakkar
Message 23 of 37 in “[GSOC] t7501: Add tests for various index usages, -i and -o, of commit command and amending commit to add signoff.”
  1. 0/2 [GSOC] t7501: Add tests for various index usages, -i and -o, of commit command and amending commit to add signoff.Ghanshyam Thakkar, Jan 9, 2024
  2. 1/2 t7501: Add tests for various index usages, -i and -o, of commit command.Ghanshyam Thakkar, Jan 9, 2024
  3. Christian CouderJan 9, 2024
  4. Ghanshyam ThakkarJan 9, 2024
  5. Junio C HamanoJan 9, 2024
  6. 2/2 t7501: Add test for amending commit to add signoff.Ghanshyam Thakkar, Jan 9, 2024
  7. Phillip WoodJan 9, 2024
  8. Ghanshyam ThakkarJan 9, 2024
  9. Junio C HamanoJan 9, 2024
  10. Christian CouderJan 9, 2024
  11. 0/2 t7501: add tests for --include, --only,Ghanshyam Thakkar, Jan 9, 2024
  12. 0/2 t7501: add tests for --include, --only andGhanshyam Thakkar, Jan 10, 2024
  13. 0/2 t7501: add tests for --include, --only, --signoffGhanshyam Thakkar, Jan 12, 2024
  14. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 12, 2024
  15. Junio C HamanoJan 12, 2024
  16. Ghanshyam ThakkarJan 13, 2024
  17. Junio C HamanoJan 13, 2024
  18. Ghanshyam ThakkarJan 13, 2024
  19. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 12, 2024
  20. 0/2 t7501: add tests for --include, --only, --signoffGhanshyam Thakkar, Jan 13, 2024
  21. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 13, 2024
  22. Junio C HamanoJan 16, 2024
  23. Junio C HamanoJan 16, 2024
  24. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 13, 2024
  25. 0/2 t7501: add tests for --include, --only, --signoffGhanshyam Thakkar, Jan 17, 2024
  26. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 17, 2024
  27. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 17, 2024
  28. Junio C HamanoJan 17, 2024
  29. 1/2 t7501: add tests for --include and --onlyGhanshyam Thakkar, Jan 10, 2024
  30. Junio C HamanoJan 10, 2024
  31. Ghanshyam ThakkarJan 11, 2024
  32. phillip.wood123@gmail.comJan 11, 2024
  33. 2/2 t7501: add tests for --amend --signoffGhanshyam Thakkar, Jan 10, 2024
  34. phillip.wood123@gmail.comJan 11, 2024
  35. 1/2 t7501: add tests for --include, --only of commitGhanshyam Thakkar, Jan 9, 2024
  36. Junio C HamanoJan 9, 2024
  37. 2/2 t7501: add test for --amend with --signoffGhanshyam Thakkar, Jan 9, 2024

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.