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

Re: [BUG] git stash pop --quiet deletes files in git 2.24.0

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Nov 7, 2019, 18:49 UTC
Message-ID
<20191107184912.GA3115@cat>
In-Reply-To
<CAMcnqp22tEFva4vYHYLzY83JqDHGzDbDGoUod21Dhtnvv=h_Pg@mail.gmail.com>
On 11/07, Grzegorz Rajchman wrote:
> Hi, this is the first time I report an issue in git so I hope I'm
> doing it right.

Thanks for the report. You are indeed doing this right, and the included reproduction is very helpful.

I broke this in 34933d0eff ("stash: make sure to write refreshed cache", 2019-09-11), which wasn't caught by the tests, nor by me as I don't use the --quiet flag normally.

Below is a fix for this, but I want to understand the problem a bit better and write some tests before sending a patch.

index ab30d1e920..2dd9c9bbcd 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -473,22 +473,20 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
 
                if (reset_tree(&c_tree, 0, 1)) {
                        strbuf_release(&out);
                        return -1;
                }
 
                ret = update_index(&out);
                strbuf_release(&out);
                if (ret)
                        return -1;
-
-               discard_cache();
        }
 
        if (quiet) {
                if (refresh_and_write_cache(REFRESH_QUIET, 0, 0))
                        warning("could not refresh index");
        } else {
                struct child_process cp = CHILD_PROCESS_INIT;
 
                /*
                 * Status is quite simple and could be replaced with calls to


> I have experienced some unexpected behaviour with git stash pop
> --quiet in git 2.24.0. I use stash in a pre-commit hook script. In it,
> I stash non-staged changes to keep the working directory clean while
> running some linters, then I restore the stash by running pop, but
> after the recent git update I noticed that it stages all previously
> checked files as deleted.
> 
> Steps to reproduce:
> 
>   mkdir test-git-stash
>   cd test-git-stash/
>   git init
>   echo foo > foo.txt
>   git add . && git commit -m 'init'
>   echo bar > foo.txt
>   git stash save --quiet --include-untracked --keep-index
>   git stash pop --quiet
>   git status
> 
> This will unexpectedly output:
> 
>   On branch master
>   Changes to be committed:
>     (use "git restore --staged <file>..." to unstage)
>       deleted:    foo.txt
> 
>   Untracked files:
>     (use "git add <file>..." to include in what will be committed)
>       foo.txt
> 
> Notice that foo.txt was staged as deleted whilst still being present
> on the disk.
> 
> However, if I remove --quiet flag from stash pop:
> 
>   git restore --staged foo.txt
>   git stash save --quiet --include-untracked --keep-index
>   git stash pop
>   git status
> 
> Then it works as expected. It used to work as expected in git prior to 2.24.0
> 
> My OS is Ubuntu 19.04.
Previous: Grzegorz RajchmanNext: Junio C Hamano
Message 2 of 13 in “[BUG] git stash pop --quiet deletes files in git 2.24.0”
  1. Grzegorz RajchmanNov 7, 2019
  2. Thomas GummererNov 7, 2019
  3. Junio C HamanoNov 8, 2019
  4. Thomas GummererNov 8, 2019
  5. Junio C HamanoNov 10, 2019
  6. Thomas GummererNov 11, 2019
  7. Junio C HamanoNov 12, 2019
  8. Thomas GummererNov 13, 2019
  9. Junio C HamanoNov 13, 2019
  10. stash: make sure we have a valid index before writing itThomas Gummerer, Nov 13, 2019
  11. Junio C HamanoNov 14, 2019
  12. 1/2 t3903: avoid git commands inside command substitutionThomas Gummerer, Nov 13, 2019
  13. 2/2 stash: make sure we have a valid index before writing itThomas Gummerer, Nov 13, 2019

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.