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

Re: [PATCH v3] stash: infer "push" when push-specific options are given

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 9, 2026, 20:22 UTC
Message-ID
<xmqqecknsx2t.fsf@gitster.g>
In-Reply-To
<20260405110953.3316-1-deveshigurgaon@gmail.com>
Deveshi Dwivedi <deveshigurgaon@gmail.com> writes:
Show 18 quoted lines
> +test_expect_success 'assume push when options imply push' '
> +	git reset --hard &&
> +	echo changed >file &&
> +	git add file &&
> +	git stash -m "implied push" file &&
> +	git stash pop &&
> +
> +	git add file &&
> +	git stash --staged file &&
> +	git stash pop &&
> +
> +	git add file &&
> +	git stash --keep-index file &&
> +	git stash pop &&
> +
> +	echo untracked >untracked-file &&
> +	git stash --include-untracked untracked-file &&
> +	test_path_is_missing untracked-file &&
A comment on these three lines.
Show 5 quoted lines
> +	git stash pop &&
> +	rm -f untracked-file &&
> +	git reset --hard
> +'
> +

I suspect that they are meant to be "clean-up after we are done with the test, to avoid interfering with the next test", but if so, "clean-up at the very end" is not a very effective strategy to do so. Imagine that one of the previous steps fails, breaking all later commands in the &&- cascade. Sitting at the very end, your clean-up sequence will not run. Unless the tester is running this test script with the "-i" option, the test will move on to the next piece. Installing clean-up handler with test_when_finished may be a cleaner approach.

	test_expect_success 'do this test' '
		test_when_finished "git stash clear; git reset --hard" &&
		git reset --hard &&
		... do all the dirty things in the working tree ...
		test_when_finished "rm -f untracked-file" &&
                echo untracked >untracked-file &&
                git stash --include-untracked untracked-file &&
		test_path_is_missing untracked-file
	'
You can use more than one test_when_finished in a single test.  

It is often done to add an upfront blunt hammer at the beginning to do a clean-up without worrying too much about where exactly in the command sequence a breakage may happen (e.g., we may fail before we run our first "git add", or "git stash", and "git reset --hard" or "git stash clear" may be an unnecessary no-op, but we do not worry too much about the clean-up step doing potentially unnecessary things.

Or you would set up a clean-up handler immediately before you create a thing that you want to make sure you clean up. If the command sequence fails before you echo the string into untracked-file to create it, there is no point preparing to remove it when you are done.

Both approaches are commmonly used.
Show 5 quoted lines
>  test_expect_success 'stash --invalid-option' '
>  	echo bar5 >file &&
>  	echo bar6 >file2 &&
>
> base-commit: 2855562ca6a9c6b0e7bc780b050c1e83c9fcfbd0
Previous: Junio C HamanoNext: Deveshi Dwivedi
Message 12 of 17 in “stash: infer "push" when push-specific options are given”
  1. stash: infer "push" when push-specific options are givenDeveshi Dwivedi, Apr 4, 2026
  2. Mirko FainaApr 4, 2026
  3. stash: infer "push" when push-specific options are givenDeveshi Dwivedi, Apr 4, 2026
  4. Mirko FainaApr 4, 2026
  5. Deveshi DwivediApr 5, 2026
  6. stash: infer "push" when push-specific options are givenDeveshi Dwivedi, Apr 5, 2026
  7. Mirko FainaApr 6, 2026
  8. Phillip WoodApr 7, 2026
  9. Deveshi DwivediApr 9, 2026
  10. Mirko FainaApr 9, 2026
  11. Junio C HamanoApr 9, 2026
  12. Junio C HamanoApr 9, 2026
  13. stash: infer "push" when command line starts with an optionDeveshi Dwivedi, Apr 12, 2026
  14. Phillip WoodApr 13, 2026
  15. Junio C HamanoApr 13, 2026
  16. stash: assume "push" when command line starts with an optionDeveshi Dwivedi, Apr 19, 2026
  17. Phillip WoodApr 21, 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.