{"thread":{"id":"15643","subject":"Stash missing, but not. Can apply, but not drop or list the stash.","startedAt":"2008-09-23T21:23:01Z","lastAt":"2008-10-02T23:52:11Z","messageCount":5,"participants":["mattjackets","Brandon Casey"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"91433","messageId":"1222204981.28575.1275592473@webmail.messagingengine.com","threadId":"15643","inReplyTo":null,"subject":"Stash missing, but not. Can apply, but not drop or list the stash.","fromName":"mattjackets","fromEmail":"mattlist@fastmail.fm","sentAt":"2008-09-23T21:23:01Z","receivedAt":"2008-09-23T21:23:01Z","isPatch":false,"sender":{"key":"mattlist@fastmail.fm","avatar":null},"body":"I have a strange stash problem.  There is a single stash in the repo.\n\ngit stash apply 0  --  works, but results in a conflict.  Lets just go\nahead and drop the stash...\n\ngit stash list  --  shows nothing.  huh?  Lets go ahead with the drop\nanyway and hope it works...\n\n$ git stash drop stash@{0}\nfatal: Log .git/logs/refs/stash is empty.\nstash@{0}: not a valid stashed state\n\nsure enough, .git/logs/refs/stash is empty\n\ngit stash clear  --  does nothing\n\nI'm at a loss.  I can apply the stash cleanly to older revisions, and\ngitk still shows the stash branch.  How can I fix this?  is it safe to\nsimply delete the stash branch as if it was any other branch?\n\nThanks,\nMatt\n-- \n  matt\n  mattlist@fastmail.fm\n\n-- \nhttp://www.fastmail.fm - Access all of your messages and folders\n                          wherever you are\n"},{"id":"91440","messageId":"klevRMI-z5Id8iuqn2rqrKQZ8LdPNE4lABeC502X9y1Es5wwQ-s8GA@cipher.nrlssc.navy.mil","threadId":"15643","inReplyTo":"1222204981.28575.1275592473@webmail.messagingengine.com","subject":"Re: Stash missing, but not. Can apply, but not drop or list the stash.","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-09-23T23:08:55Z","receivedAt":"2008-09-23T23:08:55Z","isPatch":false,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"mattjackets wrote:\n> I have a strange stash problem.  There is a single stash in the repo.\n> \n> git stash apply 0  --  works, but results in a conflict.\n\nThe correct form is 'git stash apply stash@{0}'\n\n'git stash apply 0' is doing the right thing for the wrong reason.\nFor example, 'git stash apply 1' would not do the right thing.\n\nThis is unrelated to your issue, but it seems you have uncovered\na flaw which should be fixed.\n\nIn git stash, when your command line above is used, eventually\nthe following command is executed:\n\n    git rev-parse --revs-only --no-flags --default refs/stash 0\n\n'git rev-parse' fails to resolve revision \"0\" and prints out nothing\nand then falls back to printing the revision of \"refs/stash\". This\nis not what is desired by stash.\n\nEither rev-parse needs to error out in this case, or 'git stash' needs\nto be changed so that '--default refs/stash' is not used here. Possibly,\nsomething like what is done inside drop_stash().\n\n>  Lets just go\n> ahead and drop the stash...\n> \n> git stash list  --  shows nothing.  huh?  Lets go ahead with the drop\n> anyway and hope it works...\n> \n> $ git stash drop stash@{0}\n> fatal: Log .git/logs/refs/stash is empty.\n> stash@{0}: not a valid stashed state\n> \n> sure enough, .git/logs/refs/stash is empty\n\nRight, it must exist since you actually got the error message\n'fatal: Log .git/logs/refs/stash is empty', but it contains\nnothing. Not sure how that happened.\n\n> git stash clear  --  does nothing\n\nIt correctly removes .git/refs/stash for me.\n\n> I'm at a loss.  I can apply the stash cleanly to older revisions, and\n> gitk still shows the stash branch.  How can I fix this?  is it safe to\n> simply delete the stash branch as if it was any other branch?\n\nIn this case yes it would be safe to just do 'rm .git/refs/stash', but\nlike I said, 'git stash clear' worked for me.\n\n-brandon\n"},{"id":"91442","messageId":"twy9P1UnbmZHs2ZDeFBjSzrleLQ225-I7ESNrFkwoXZL-mJCTf4hYw@cipher.nrlssc.navy.mil","threadId":"15643","inReplyTo":"klevRMI-z5Id8iuqn2rqrKQZ8LdPNE4lABeC502X9y1Es5wwQ-s8GA@cipher.nrlssc.navy.mil","subject":"[PATCH maint] git-stash.sh: don't default to refs/stash if invalid ref supplied","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-09-23T23:57:09Z","receivedAt":"2008-09-23T23:57:09Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"apply_stash() and show_stash() each call rev-parse with\n'--default refs/stash' as an argument. This option causes rev-parse to\noperate on refs/stash if it is not able to successfully operate on any\nelement of the command line. This includes failure to supply a \"valid\"\nrevision. This has the effect of causing 'stash apply' and 'stash show'\nto operate as if stash@{0} had been supplied when an invalid revision is\nsupplied.\n\ne.g. 'git stash apply stahs@{1}' would fall back to\n     'git stash apply stash@{0}'\n\nThis patch modifies these two functions so that they avoid using the\n--default option of rev-parse.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n\n\nThis should fix the case I mention above, but it does not fix the\ncase where a non-existent reflog entry is specified. In this case\nthe last entry will be selected.\n\n\t$ git stash list\n\tstash@{0}: WIP on master: c050772... small java change\n\tstash@{1}: WIP on master: c050772... small java change\n\tstash@{2}: WIP on master: c050772... small java change\n\tstash@{3}: WIP on master: c050772... small java change\n\t$ git stash apply stash@{10}\n\twarning: Log for 'stash' only has 4 entries.\n\t# On branch master\n\t# Changed but not updated:\n\t... etc.\n\nstash@{3} was applied.\n\nLuckily, the dangerous case has no effect.\n\n\t$ git stash drop stash@{10}\n\tDropped stash@{10} (b7a2467e58109c92d799d059f508f35853d0bff7)\n\t$ git stash list\n\tstash@{0}: WIP on master: c050772... small java change\n\tstash@{1}: WIP on master: c050772... small java change\n\tstash@{2}: WIP on master: c050772... small java change\n\tstash@{3}: WIP on master: c050772... small java change\n\n-brandon\n\n\n git-stash.sh |   17 +++++++++++++++--\n 1 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex d799c76..6bd2572 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -144,7 +144,14 @@ show_stash () {\n \tthen\n \t\tflags=--stat\n \tfi\n-\ts=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\")\n+\n+\tif test $# = 0\n+\tthen\n+\t\tset x \"$ref_stash@{0}\"\n+\t\tshift\n+\tfi\n+\n+\ts=$(git rev-parse --revs-only --no-flags \"$@\")\n \n \tw_commit=$(git rev-parse --verify \"$s\") &&\n \tb_commit=$(git rev-parse --verify \"$s^\") &&\n@@ -163,13 +170,19 @@ apply_stash () {\n \t\tshift\n \tesac\n \n+\tif test $# = 0\n+\tthen\n+\t\tset x \"$ref_stash@{0}\"\n+\t\tshift\n+\tfi\n+\n \t# current index state\n \tc_tree=$(git write-tree) ||\n \t\tdie 'Cannot apply a stash in the middle of a merge'\n \n \t# stash records the work tree, and is a merge between the\n \t# base commit (first parent) and the index tree (second parent).\n-\ts=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\") &&\n+\ts=$(git rev-parse --revs-only --no-flags \"$@\") &&\n \tw_tree=$(git rev-parse --verify \"$s:\") &&\n \tb_tree=$(git rev-parse --verify \"$s^1:\") &&\n \ti_tree=$(git rev-parse --verify \"$s^2:\") ||\n-- \n1.6.0.1.244.gdc19\n"},{"id":"92086","messageId":"DDpCKmlWUqX7hHbNNF45UGo81L7NuUHMbU3vXSfhHU60An5PUqIvRA@cipher.nrlssc.navy.mil","threadId":"15643","inReplyTo":"twy9P1UnbmZHs2ZDeFBjSzrleLQ225-I7ESNrFkwoXZL-mJCTf4hYw@cipher.nrlssc.navy.mil","subject":"regression: stash show -p (was [PATCH maint] git-stash.sh: don't default to refs/stash if invalid ref supplied)","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-10-01T19:53:55Z","receivedAt":"2008-10-01T19:53:55Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"\nThanks to the patch referenced in the subject, 'git stash show -p'\nno longer works if a revision is _not_ supplied.\n\nThis is because the argument list passed to show_stash() is not empty,\nso the default $ref_stash@{0} is not appended.\n\nThis brings me back to an unanswered question, \"Should rev-parse fall\nback to its --default argument when an invalid ref is supplied?\". The\ndocumentation does not imply that it should.\n\n>From Documentation/git-rev-parse.txt:\n\n   --default <arg>::\n        If there is no parameter given by the user, use `<arg>`\n        instead.\n\nCurrently a rev-parse invocation like:\n\n    $ git rev-parse --default HEAD a_non_existent_ref\n\nwill fall back to operating on HEAD. Is this correct? Could there be\nsome part of git that depends on this behavior? filter-branch is now\nthe only script which uses the --default option of rev-parse, not sure\nabout the c code.\n\n-brandon\n\n\n\nBrandon Casey wrote:\n> apply_stash() and show_stash() each call rev-parse with\n> '--default refs/stash' as an argument. This option causes rev-parse to\n> operate on refs/stash if it is not able to successfully operate on any\n> element of the command line. This includes failure to supply a \"valid\"\n> revision. This has the effect of causing 'stash apply' and 'stash show'\n> to operate as if stash@{0} had been supplied when an invalid revision is\n> supplied.\n> \n> e.g. 'git stash apply stahs@{1}' would fall back to\n>      'git stash apply stash@{0}'\n> \n> This patch modifies these two functions so that they avoid using the\n> --default option of rev-parse.\n> \n> Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n> ---\n> \n> \n> This should fix the case I mention above, but it does not fix the\n> case where a non-existent reflog entry is specified. In this case\n> the last entry will be selected.\n> \n> \t$ git stash list\n> \tstash@{0}: WIP on master: c050772... small java change\n> \tstash@{1}: WIP on master: c050772... small java change\n> \tstash@{2}: WIP on master: c050772... small java change\n> \tstash@{3}: WIP on master: c050772... small java change\n> \t$ git stash apply stash@{10}\n> \twarning: Log for 'stash' only has 4 entries.\n> \t# On branch master\n> \t# Changed but not updated:\n> \t... etc.\n> \n> stash@{3} was applied.\n> \n> Luckily, the dangerous case has no effect.\n> \n> \t$ git stash drop stash@{10}\n> \tDropped stash@{10} (b7a2467e58109c92d799d059f508f35853d0bff7)\n> \t$ git stash list\n> \tstash@{0}: WIP on master: c050772... small java change\n> \tstash@{1}: WIP on master: c050772... small java change\n> \tstash@{2}: WIP on master: c050772... small java change\n> \tstash@{3}: WIP on master: c050772... small java change\n> \n> -brandon\n> \n> \n>  git-stash.sh |   17 +++++++++++++++--\n>  1 files changed, 15 insertions(+), 2 deletions(-)\n> \n> diff --git a/git-stash.sh b/git-stash.sh\n> index d799c76..6bd2572 100755\n> --- a/git-stash.sh\n> +++ b/git-stash.sh\n> @@ -144,7 +144,14 @@ show_stash () {\n>  \tthen\n>  \t\tflags=--stat\n>  \tfi\n> -\ts=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\")\n> +\n> +\tif test $# = 0\n> +\tthen\n> +\t\tset x \"$ref_stash@{0}\"\n> +\t\tshift\n> +\tfi\n> +\n> +\ts=$(git rev-parse --revs-only --no-flags \"$@\")\n>  \n>  \tw_commit=$(git rev-parse --verify \"$s\") &&\n>  \tb_commit=$(git rev-parse --verify \"$s^\") &&\n> @@ -163,13 +170,19 @@ apply_stash () {\n>  \t\tshift\n>  \tesac\n>  \n> +\tif test $# = 0\n> +\tthen\n> +\t\tset x \"$ref_stash@{0}\"\n> +\t\tshift\n> +\tfi\n> +\n>  \t# current index state\n>  \tc_tree=$(git write-tree) ||\n>  \t\tdie 'Cannot apply a stash in the middle of a merge'\n>  \n>  \t# stash records the work tree, and is a merge between the\n>  \t# base commit (first parent) and the index tree (second parent).\n> -\ts=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\") &&\n> +\ts=$(git rev-parse --revs-only --no-flags \"$@\") &&\n>  \tw_tree=$(git rev-parse --verify \"$s:\") &&\n>  \tb_tree=$(git rev-parse --verify \"$s^1:\") &&\n>  \ti_tree=$(git rev-parse --verify \"$s^2:\") ||\n"},{"id":"92205","messageId":"PE1YPoO2gOexZnninF0-ua_lZKCzmivC8TnRlA2S101NX3E7meiItQ@cipher.nrlssc.navy.mil","threadId":"15643","inReplyTo":"DDpCKmlWUqX7hHbNNF45UGo81L7NuUHMbU3vXSfhHU60An5PUqIvRA@cipher.nrlssc.navy.mil","subject":"[PATCH] git-stash.sh: fix flawed fix of invalid ref handling (commit da65e7c1)","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-10-02T23:52:11Z","receivedAt":"2008-10-02T23:52:11Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"The referenced commit tried to fix a flaw in stash's handling of a user\nsupplied invalid ref. i.e. 'git stash apply fake_ref@{0}' should fail\ninstead of applying stash@{0}. But, it did so in a naive way by avoiding the\nuse of the --default option of rev-parse, and instead manually supplied the\ndefault revision if the user supplied an empty command line. This prevented\na common usage scenario of supplying flags on the stash command line (i.e.\nnon-empty command line) which would be parsed by lower level git commands,\nwithout supplying a specific revision. This should fall back to the default\nrevision, but now it causes an error. e.g. 'git stash show -p'\n\nThe correct fix is to use the --verify option of rev-parse, which fails\nproperly if an invalid ref is supplied, and still allows falling back to a\ndefault ref when one is not supplied.\n\nConvert stash-drop to use --verify while we're at it, since specifying\nmultiple revisions for any of these commands is also an error and --verify\nmakes it so.\n\nSigned-off-by: Brandon Casey <casey@nrlssc.navy.mil>\n---\n\n\nThe patch is simpler than it looks, since it includes a revert of my\noriginal patch.\n\nHere is 'git diff da65e7c1^:git-stash.sh git-stash.sh':\n\n @@ -144,17 +144,16 @@ show_stash () {\n        then\n                flags=--stat\n        fi\n-       s=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\")\n \n-       w_commit=$(git rev-parse --verify \"$s\") &&\n-       b_commit=$(git rev-parse --verify \"$s^\") &&\n+       w_commit=$(git rev-parse --verify --default $ref_stash \"$@\") &&\n+       b_commit=$(git rev-parse --verify \"$w_commit^\") &&\n        git diff $flags $b_commit $w_commit\n }\n \n @@ -169,7 +168,7 @@ apply_stash () {\n \n        # stash records the work tree, and is a merge between the\n        # base commit (first parent) and the index tree (second parent).\n-       s=$(git rev-parse --revs-only --no-flags --default $ref_stash \"$@\") &&\n+       s=$(git rev-parse --verify --default $ref_stash \"$@\") &&\n        w_tree=$(git rev-parse --verify \"$s:\") &&\n        b_tree=$(git rev-parse --verify \"$s^1:\") &&\n        i_tree=$(git rev-parse --verify \"$s^2:\") ||\n @@ -229,7 +228,7 @@ drop_stash () {\n                shift\n        fi\n        # Verify supplied argument looks like a stash entry\n-       s=$(git rev-parse --revs-only --no-flags \"$@\") &&\n+       s=$(git rev-parse --verify \"$@\") &&\n        git rev-parse --verify \"$s:\"   > /dev/null 2>&1 &&\n        git rev-parse --verify \"$s^1:\" > /dev/null 2>&1 &&\n        git rev-parse --verify \"$s^2:\" > /dev/null 2>&1 ||\n\nI already messed this up once, so a review is appreciated. Any reason\n--verify wasn't used in the first place?\n\nI know why it wasn't used in drop_stash(), it's because I just copied it\nfrom apply_stash().\n\n-brandon\n\n\n git-stash.sh |   22 ++++------------------\n 1 files changed, 4 insertions(+), 18 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 42f626f..b9ace99 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -145,16 +145,8 @@ show_stash () {\n \t\tflags=--stat\n \tfi\n \n-\tif test $# = 0\n-\tthen\n-\t\tset x \"$ref_stash@{0}\"\n-\t\tshift\n-\tfi\n-\n-\ts=$(git rev-parse --revs-only --no-flags \"$@\")\n-\n-\tw_commit=$(git rev-parse --verify \"$s\") &&\n-\tb_commit=$(git rev-parse --verify \"$s^\") &&\n+\tw_commit=$(git rev-parse --verify --default $ref_stash \"$@\") &&\n+\tb_commit=$(git rev-parse --verify \"$w_commit^\") &&\n \tgit diff $flags $b_commit $w_commit\n }\n \n@@ -170,19 +162,13 @@ apply_stash () {\n \t\tshift\n \tesac\n \n-\tif test $# = 0\n-\tthen\n-\t\tset x \"$ref_stash@{0}\"\n-\t\tshift\n-\tfi\n-\n \t# current index state\n \tc_tree=$(git write-tree) ||\n \t\tdie 'Cannot apply a stash in the middle of a merge'\n \n \t# stash records the work tree, and is a merge between the\n \t# base commit (first parent) and the index tree (second parent).\n-\ts=$(git rev-parse --revs-only --no-flags \"$@\") &&\n+\ts=$(git rev-parse --verify --default $ref_stash \"$@\") &&\n \tw_tree=$(git rev-parse --verify \"$s:\") &&\n \tb_tree=$(git rev-parse --verify \"$s^1:\") &&\n \ti_tree=$(git rev-parse --verify \"$s^2:\") ||\n@@ -242,7 +228,7 @@ drop_stash () {\n \t\tshift\n \tfi\n \t# Verify supplied argument looks like a stash entry\n-\ts=$(git rev-parse --revs-only --no-flags \"$@\") &&\n+\ts=$(git rev-parse --verify \"$@\") &&\n \tgit rev-parse --verify \"$s:\"   > /dev/null 2>&1 &&\n \tgit rev-parse --verify \"$s^1:\" > /dev/null 2>&1 &&\n \tgit rev-parse --verify \"$s^2:\" > /dev/null 2>&1 ||\n-- \n1.6.0.2.323.g7c850\n"}]}