[Stashing] Move away from git log and use stash list with --pretty format
See original GitHub issueDesktop currently uses git log -g refs/stash --pretty="%H@%gs"
to get the list of stash entries in a repo. This was done because Desktop relies on the commit SHA of the stash entry to uniquely identify them.
While not necessarily harmful, this causes errors to be logged in the console when .git/logs/refs/stash
is not present. Since the file only exists when there is at least one stash, this error can get logged often and pollute the logs.
https://github.com/desktop/desktop/pull/7210#issuecomment-480456627
Using git stash list --pretty=%H@%gs
will accomplish the same goal as using git log -g refs/stash
with the added benefit that it will not fail when .git/logs/refs/stash
does not exist.
$ git stash list --pretty=%H@%gs
7c4cced8d4763a0538bc6c0a6f05f7e050cd3a4b@WIP on linux: 5b1f0a6b3 tidy up badges
$ git stash drop
Dropped refs/stash@{0} (7c4cced8d4763a0538bc6c0a6f05f7e050cd3a4b)
$ git stash list --pretty=%H@%gs
$ echo $?
0
$ git log -g --pretty=%H%gs refs/stash
fatal: ambiguous argument 'refs/stash': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Shoutout to @shiftkey for letting me know git stash list
accepts a pretty format! 🥇
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top GitHub Comments
I see, I had forgotten to consider the performance implication. I’m happy to close this out in favor of just adding the exit code
128
to the list of expected output. While guarding for future changes to the implementation would be cool, I’d prefer waiting until it becomes a problem and avoid the performance hit.cc/ @shiftkey for thoughts on keeping the current implementation.
it looks like this was done in https://github.com/desktop/desktop/commit/6eae14970d20f5446a4274e0bcc0d84fdad731bb (via https://github.com/desktop/desktop/pull/7268), so i’m going to close this.