question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Stashing] Move away from git log and use stash list with --pretty format

See original GitHub issue

Desktop 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.

https://github.com/desktop/desktop/blob/50cb1fa524b9a41ece7bc09e7702ecf231a62061/app/src/lib/git/stash.ts#L29-L45

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
iAmWillShepherdcommented, Apr 19, 2019

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.

0reactions
outofambitcommented, May 29, 2019

I’m happy to close this out in favor of just adding the exit code 128 to the list of expected output.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to list and show the git stash history | TheServerSide
Show your shelved change history with git stash list and show. ... log, which means there are endless enhancements and formatting options.
Read more >
Git stash list with pathspec - Stack Overflow
Answer: You can't pass a pathspec to the listing variant of the git stash command itself, but you can get the list of...
Read more >
git-stash Documentation - Git
The command saves your local modifications away and reverts the working directory to match the HEAD commit. The modifications stashed away by this...
Read more >
Git: Simply Stashing - SitePoint
As long as you write descriptive messages about the stash and be sure to keep your stash list clean, then stashing is a...
Read more >
How to see stashed changes using git stash
The command git stash is used to stash the changes in a dirty working directory away. ... A stash is represented as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found