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

Re: [PATCH v2 5/5] stash: make internal resets quiet and refresh index

From
Victoria Dye <vdye@github.com>
Date
Mar 14, 2022, 23:54 UTC
Message-ID
<cccf5552-a753-b472-0e22-d7f45542d424@github.com>
In-Reply-To
<xmqqtuc0qq0w.fsf@gitster.g>
Junio C Hamano wrote:
Show 76 quoted lines
> "Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: Victoria Dye <vdye@github.com>
>>
>> Add the options '-q' and '--refresh' to the 'git reset' executed in
>> 'reset_head()', and '--refresh' to the 'git reset -q' executed in
>> 'do_push_stash(...)'.
>>
>> 'stash' is implemented such that git commands invoked  as part of it (e.g.,
>> 'clean', 'read-tree', 'reset', etc.) have their informational output
>> silenced. However, the 'reset' in 'reset_head()' is *not* called with '-q',
>> leading to the potential for a misleading printout from 'git stash apply
>> --index' if the stash included a removed file:
>>
>> Unstaged changes after reset: D      <deleted file>
>>
>> Not only is this confusing in its own right (since, after the reset, 'git
>> stash' execution would stage the deletion in the index), it would be printed
>> even when the stash was applied with the '-q' option. As a result, the
>> messaging is removed entirely by calling 'git status' with '-q'.
>>
>> Additionally, because the default behavior of 'git reset -q' is to skip
>> refreshing the index, but later operations in 'git stash' subcommands expect
>> a non-stale index, enable '--refresh' as well.
>>
>> Signed-off-by: Victoria Dye <vdye@github.com>
>> ---
>>  builtin/stash.c  |  5 +++--
>>  t/t3903-stash.sh | 12 ++++++++++++
>>  2 files changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/builtin/stash.c b/builtin/stash.c
>> index 3e8af210fde..91407d9bbe0 100644
>> --- a/builtin/stash.c
>> +++ b/builtin/stash.c
>> @@ -310,7 +310,7 @@ static int reset_head(void)
>>  	 * API for resetting.
>>  	 */
>>  	cp.git_cmd = 1;
>> -	strvec_push(&cp.args, "reset");
>> +	strvec_pushl(&cp.args, "reset", "--quiet", "--refresh", NULL);
>>  
>>  	return run_command(&cp);
>>  }
>> @@ -1633,7 +1633,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
>>  			struct child_process cp = CHILD_PROCESS_INIT;
>>  
>>  			cp.git_cmd = 1;
>> -			strvec_pushl(&cp.args, "reset", "-q", "--", NULL);
>> +			strvec_pushl(&cp.args, "reset", "-q", "--refresh", "--",
>> +				     NULL);
>>  			add_pathspecs(&cp.args, ps);
>>  			if (run_command(&cp)) {
>>  				ret = -1;
>> diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
>> index f36e121210e..17f2ad2344c 100755
>> --- a/t/t3903-stash.sh
>> +++ b/t/t3903-stash.sh
>> @@ -261,6 +261,18 @@ test_expect_success 'apply -q is quiet' '
>>  	test_must_be_empty output.out
>>  '
>>  
>> +test_expect_success 'apply --index -q is quiet' '
>> +	# Added file, deleted file, modified file all staged for commit
>> +	echo foo >new-file &&
>> +	echo test >file &&
>> +	git add new-file file &&
>> +	git rm other-file &&
>> +
>> +	git stash &&
> 
> Hpmh.  The hunk that updates reset_head() does get exercised by
> "apply --index", so testing that is OK, but we are also patching
> "do_push_stash()" to be quiet, so don't we care the chattyness of
> this step, too?
> 

The '-q' option was already present in the reset in 'do_push_stash()', but I did add the '--refresh' option to ensure that (for example) 'git stash push --staged' refreshes the index. With that in mind...

> In these steps, we also want the same "did the command refresh the
> index?" tests, no?
> 

yes, both cases where '--refresh' was added should be tested (since both will fail if they don't include that option). I'll add them in the next iteration.

Show 11 quoted lines
>> +	git stash apply --index -q >output.out 2>&1 &&
>> +	test_must_be_empty output.out
>> +'
>> +
>>  test_expect_success 'save -q is quiet' '
>>  	git stash save --quiet >output.out 2>&1 &&
>>  	test_must_be_empty output.out
> 
> Other than these nits I noticed, the overall idea of the topic is
> well presented.  Thanks for working on this.
> 
Previous: Junio C HamanoNext: Derrick Stolee
Message 25 of 39 in “Separate '--skip-refresh' from '--quiet' in 'reset', use '--quiet' internally in 'stash'”
  1. 0/5 Separate '--skip-refresh' from '--quiet' in 'reset', use '--quiet' internally in 'stash'Victoria Dye via GitGitGadget, Mar 12, 2022
  2. 1/5 reset: revise index refresh adviceVictoria Dye via GitGitGadget, Mar 12, 2022
  3. 2/5 reset: introduce --[no-]refresh option to --mixedVictoria Dye via GitGitGadget, Mar 12, 2022
  4. Derrick StoleeMar 14, 2022
  5. Derrick StoleeMar 14, 2022
  6. Victoria DyeMar 14, 2022
  7. 3/5 reset: replace '--quiet' with '--no-refresh' in performance adviceVictoria Dye via GitGitGadget, Mar 12, 2022
  8. 4/5 reset: suppress '--no-refresh' advice if logging is silencedVictoria Dye via GitGitGadget, Mar 12, 2022
  9. 5/5 stash: make internal resets quiet and refresh indexVictoria Dye via GitGitGadget, Mar 12, 2022
  10. Derrick StoleeMar 14, 2022
  11. Victoria DyeMar 14, 2022
  12. Victoria DyeMar 12, 2022
  13. Junio C HamanoMar 14, 2022
  14. Derrick StoleeMar 14, 2022
  15. 0/5 Allow 'reset --quiet' to refresh the index, use 'reset --quiet' in 'stash'Victoria Dye via GitGitGadget, Mar 14, 2022
  16. 2/5 reset: introduce --[no-]refresh option to --mixedVictoria Dye via GitGitGadget, Mar 14, 2022
  17. Junio C HamanoMar 14, 2022
  18. Victoria DyeMar 14, 2022
  19. 1/5 reset: revise index refresh adviceVictoria Dye via GitGitGadget, Mar 14, 2022
  20. 4/5 reset: suppress '--no-refresh' advice if logging is silencedVictoria Dye via GitGitGadget, Mar 14, 2022
  21. Junio C HamanoMar 14, 2022
  22. 3/5 reset: replace '--quiet' with '--no-refresh' in performance adviceVictoria Dye via GitGitGadget, Mar 14, 2022
  23. 5/5 stash: make internal resets quiet and refresh indexVictoria Dye via GitGitGadget, Mar 14, 2022
  24. Junio C HamanoMar 14, 2022
  25. Victoria DyeMar 14, 2022
  26. Derrick StoleeMar 14, 2022
  27. Junio C HamanoMar 14, 2022
  28. 0/5 Allow 'reset --quiet' to refresh the index, use 'reset --quiet' in 'stash'Victoria Dye via GitGitGadget, Mar 15, 2022
  29. 1/5 reset: revise index refresh adviceVictoria Dye via GitGitGadget, Mar 15, 2022
  30. 3/5 reset: replace '--quiet' with '--no-refresh' in performance adviceVictoria Dye via GitGitGadget, Mar 15, 2022
  31. 2/5 reset: introduce --[no-]refresh option to --mixedVictoria Dye via GitGitGadget, Mar 15, 2022
  32. Phillip WoodMar 18, 2022
  33. Junio C HamanoMar 18, 2022
  34. Victoria DyeMar 18, 2022
  35. 4/5 reset: suppress '--no-refresh' advice if logging is silencedVictoria Dye via GitGitGadget, Mar 15, 2022
  36. 5/5 stash: make internal resets quiet and refresh indexVictoria Dye via GitGitGadget, Mar 15, 2022
  37. Junio C HamanoMar 15, 2022
  38. Victoria DyeMar 16, 2022
  39. Junio C HamanoMar 16, 2022

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.