[PATCH] git-stash: don't complain when listing in a repo with no stash

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] git-stash: don't complain when listing in a repo with no stash

From: Jeff King <hidden>
Date: 2016-06-15 22:43:19

Previously, the git-log invocation would complain if a repo
had not had any stashes created in it yet:

$ git-init
$ git-stash
fatal: ambiguous argument 'refs/stash': unknown revision or
  path not in the working tree.
Use '--' to separate paths from revisions

Instead, we only call git-log if we actually have a
refs/stash. We could alternatively create the ref when any
stash command is called, but it's better for the 'list'
command to not require write access to the repo.

Signed-off-by: Jeff King <redacted>
---
 git-stash.sh |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index 7644bd5..18d3322 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -76,7 +76,12 @@ save_stash () {
 	printf >&2 'Saved WIP on %s\n' "$msg"
 }
 
+have_stash () {
+	git-rev-parse --verify $ref_stash >/dev/null 2>&1
+}
+
 list_stash () {
+	have_stash || return 0
 	git-log --pretty=oneline -g "$@" $ref_stash |
 	sed -n -e 's/^[.0-9a-f]* refs\///p'
 }
-- 
1.5.2.2.1452.g896f6

Re: [PATCH] git-stash: don't complain when listing in a repo with no stash

From: しらいしななこ <hidden>
Date: 2016-06-15 22:43:19

Quoting Jeff King [off-list ref]:
Previously, the git-log invocation would complain if a repo
had not had any stashes created in it yet:

$ git-init
$ git-stash
fatal: ambiguous argument 'refs/stash': unknown revision or
  path not in the working tree.
Use '--' to separate paths from revisions

Instead, we only call git-log if we actually have a
refs/stash. We could alternatively create the ref when any
stash command is called, but it's better for the 'list'
command to not require write access to the repo.

Signed-off-by: Jeff King <redacted>
Thank you for correcting the bugs I introduced.

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

----------------------------------------------------------------------
Finally - A spam blocker that actually works.
http://www.bluebottle.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help