git stash pop fails in specific git repository

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

Tried to pop a stash by running `git stash pop 'stash@{0}'`.
Please note that I'm using "stash@{0}" as a reference here.
When using "0", or omitting the reference, `git stash pop` succeeds.
Details below.

What did you expect to happen? (Expected behavior)

The most recent stash to be applied, then dropped.

What happened instead? (Actual behavior)

The stash was not applied or dropped.
An exit code of 1 was returned, with no error message.

Anything else you want to add:

This only happens in a specific git repository, but is reproducible there.
The issue does *not* happen in a fresh git repository.

An example of a fresh git repository and the expected behavior:

```shell
# setup
$ git init
Initialized empty Git repository in /home/user/tmp/new/.git/
$ echo hello >> README.md
$ git add .
$ git commit -m "Init"
[main (root-commit) 3fb3ed1] Init
 1 file changed, 1 insertion(+)
 create mode 100644 README.md

# stash creation
$ echo world >> README.md
$ git stash push
Saved working directory and index state WIP on main: 3fb3ed1 Init

# stash pop succeeds
$ git stash pop 'stash@{0}'
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
Dropped stash@{0} (272c93ac3fe3cf69380a61ccaba0d90509e306f0)
```

This is what happens in the git repository that shows this issue:

```shell
# setup
$ git clone git@xxxxxxxxxx:some/thing.git
$ cd thing
$ git status
On branch production
Your branch is up to date with 'origin/production'.

nothing to commit, working tree clean

# stash creation
$ echo something >> README.md
$ git status
On branch production
Your branch is up to date with 'origin/production'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
$ git stash push
Saved working directory and index state WIP on production: abcd1234
Merge pull request #1234 from some/feature/branch
$ git --no-pager stash list
stash@{0}: WIP on production: abcd1234 Merge pull request #1234 from
some/feature/branch

# stash pop fails
$ git stash pop 'stash@{0}' # no output from this command
$ echo $?
1
```

The same error happens when using these commands:

```shell
$ git stash pop "stash@{0}"
$ git stash pop stash@{0}
```

The error does *not* happen when popping the stash like this:

```shell
$ git stash pop 0 # or "git stash pop" without any ref
On branch production
Your branch is up to date with 'origin/production'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (3f0ed5a45d2eab357cfc47a9ff8a4f86faabf66c)
```

I added some trace environment variables, maybe this helps:

```shell
$ GIT_TRACE=2 GIT_TRACE_PACK_ACCESS=2 GIT_TRACE_PACKET=2
GIT_TRACE_PACKFILE=2 GIT_TRACE_SETUP=2 GIT_TRACE_SHALLOW=2 git stash pop
'stash@{0}'
16:02:21.941329 trace.c:387             setup: git_dir: .git
16:02:21.941358 trace.c:388             setup: git_common_dir: .git
16:02:21.941362 trace.c:389             setup: worktree:
/home/user/tmp/thing
16:02:21.941365 trace.c:390             setup: cwd: /home/user/tmp/thing
16:02:21.941367 trace.c:391             setup: prefix: (null)
16:02:21.941373 chdir-notify.c:65       setup: chdir from
'/home/user/tmp/thing' to '/home/user/tmp/thing'
16:02:21.941379 git.c:455               trace: built-in: git stash pop
'stash@{0}'
error: stash@{0} is not a valid reference
```

Here we see an error message for the first time.
I do not know why this is not shown by the previous commands, maybe
that's related to my shell.
The same error message is shown when running the commands with stderr
redirection:

```shell
$ git stash pop 'stash@{0}' 2>&1
error: stash@{0} is not a valid reference
$ git stash pop "stash@{0}" 2>&1
error: stash@{0} is not a valid reference
$ git stash pop stash@{0} 2>&1
error: stash@{0} is not a valid reference
```

I do not understand this error message, as the reference "stash@{0}"
matches the one from the `git --no-pager stash list` command.

How can I debug the affected git repository to find out more? The
repository is private, so unfortunately I cannot share it.


[System Info]
git version:
git version 2.34.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC
2024 x86_64
compiler info: gnuc: 11.4
libc info: glibc: 2.35
$SHELL (typically, interactive shell): /usr/bin/zsh

Note: I also compiled git version 2.48.1 from source (using `NO_CURL=1
make`), the issue is the same.

Note: switching from zsh to bash does not help, the issue is the same.

[Enabled Hooks]





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux