{"thread":{"id":"20531","subject":"[PATCH] git stash: Give friendlier error when there is nothing to apply","startedAt":"2009-08-11T11:12:13Z","lastAt":"2009-08-15T01:50:50Z","messageCount":7,"participants":["Ori Avtalion","Thomas Rast","Junio C Hamano","Nanako Shiraishi"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"120224","messageId":"4a81559c.05ae660a.591b.010b@mx.google.com","threadId":"20531","inReplyTo":null,"subject":"[PATCH] git stash: Give friendlier error when there is nothing to apply","fromName":"Ori Avtalion","fromEmail":"ori@avtalion.name","sentAt":"2009-08-11T11:12:13Z","receivedAt":"2009-08-11T11:12:13Z","isPatch":true,"sender":{"key":"ori@avtalion.name","avatar":"https://avatars.githubusercontent.com/u/28355?v=4"},"body":"The old message was scary and included a 'fatal' error from rev-parse:\n     fatal: Needed a single revision\n     : no valid stashed state found\n\nThe new message is identical to the one given by 'git stash branch', and\ngiven *before* the check for a dirty working tree.\n\nPreviously, the command prompted the user to clean a dirty working tree\nwhen there is nothing to apply.\n\nSigned-off-by: Ori Avtalion <ori@avtalion.name>\n---\n git-stash.sh |    2 ++\n 1 files changed, 2 insertions(+), 0 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 03e589f..aa84144 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -162,6 +162,8 @@ show_stash () {\n }\n \n apply_stash () {\n+\thave_stash || die 'Nothing to apply'\n+\n \tgit update-index -q --refresh &&\n \tgit diff-files --quiet --ignore-submodules ||\n \t\tdie 'Cannot apply to a dirty working tree, please stage your changes'\n-- \n1.6.4.73.gc144.dirty\n"},{"id":"120267","messageId":"4a81787d.0e0f660a.5238.4c8b@mx.google.com","threadId":"20531","inReplyTo":"200908111409.04506.trast@student.ethz.ch","subject":"[PATCH] git stash: Give friendlier errors when there is nothing to apply","fromName":"Ori Avtalion","fromEmail":"ori@avtalion.name","sentAt":"2009-08-11T11:12:13Z","receivedAt":"2009-08-11T11:12:13Z","isPatch":true,"sender":{"key":"ori@avtalion.name","avatar":"https://avatars.githubusercontent.com/u/28355?v=4"},"body":"The change makes sure a stash (given or default) exists before\nchecking if the working tree is dirty.\n\nIf the default stash is requested, the old message was scary and\nincluded a 'fatal' error from rev-parse:\n     fatal: Needed a single revision\n     : no valid stashed state found\n\nIt is replaced with a friendlier 'Nothing to apply' error, similar to\n'git stash branch'.\n\nIf a specific stash is specified, the 'Needed a single revision' errors\nfrom rev-parse are suppressed.\n\nSigned-off-by: Ori Avtalion <ori@avtalion.name>\n---\n\nThomas, I added handling for the 'git stash apply <stash>' case based\non your reminder, and also changed the error messages related to it.\n\nAll of the stash tests pass, as before.\n\n git-stash.sh |   27 ++++++++++++++++-----------\n 1 files changed, 16 insertions(+), 11 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 03e589f..d61c9d0 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -162,10 +162,6 @@ show_stash () {\n }\n \n apply_stash () {\n-\tgit update-index -q --refresh &&\n-\tgit diff-files --quiet --ignore-submodules ||\n-\t\tdie 'Cannot apply to a dirty working tree, please stage your changes'\n-\n \tunstash_index=\n \n \twhile test $# != 0\n@@ -184,18 +180,27 @@ apply_stash () {\n \t\tshift\n \tdone\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+\tif test $# = 0\n+\tthen\n+\t\thave_stash || die 'Nothing to apply'\n+\tfi\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 --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+\ts=$(git rev-parse --quiet --verify --default $ref_stash \"$@\") &&\n+\tw_tree=$(git rev-parse --quiet --verify \"$s:\") &&\n+\tb_tree=$(git rev-parse --quiet --verify \"$s^1:\") &&\n+\ti_tree=$(git rev-parse --quiet --verify \"$s^2:\") ||\n \t\tdie \"$*: no valid stashed state found\"\n \n+\tgit update-index -q --refresh &&\n+\tgit diff-files --quiet --ignore-submodules ||\n+\t\tdie 'Cannot apply to a dirty working tree, please stage your changes'\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 \tunstashed_index_tree=\n \tif test -n \"$unstash_index\" && test \"$b_tree\" != \"$i_tree\" &&\n \t\t\ttest \"$c_tree\" != \"$i_tree\"\n-- \n1.6.4.115.g82cf7\n"},{"id":"120236","messageId":"200908111409.04506.trast@student.ethz.ch","threadId":"20531","inReplyTo":"4a81559c.05ae660a.591b.010b@mx.google.com","subject":"Re: [PATCH] git stash: Give friendlier error when there is nothing to apply","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-08-11T12:09:02Z","receivedAt":"2009-08-11T12:09:02Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Ori Avtalion wrote:\n>  apply_stash () {\n> +\thave_stash || die 'Nothing to apply'\n> +\n>  \tgit update-index -q --refresh &&\n>  \tgit diff-files --quiet --ignore-submodules ||\n>  \t\tdie 'Cannot apply to a dirty working tree, please stage your changes'\n> \n\nThis needs a guard against the case where the user says\n\n  git stash apply $some_sha1\n\nbut his refs/stash is empty.  This could be the case, e.g., after\nmistakenly blowing away the reflog with 'git stash clear' and then\ngoing on a recovery hunt through the unreferenced commits.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"120497","messageId":"200908130935.51470.trast@student.ethz.ch","threadId":"20531","inReplyTo":"4a81787d.0e0f660a.5238.4c8b@mx.google.com","subject":"Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-08-13T07:35:50Z","receivedAt":"2009-08-13T07:35:50Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Ori Avtalion wrote:\n> The change makes sure a stash (given or default) exists before\n> checking if the working tree is dirty.\n> \n> If the default stash is requested, the old message was scary and\n> included a 'fatal' error from rev-parse:\n>      fatal: Needed a single revision\n>      : no valid stashed state found\n> \n> It is replaced with a friendlier 'Nothing to apply' error, similar to\n> 'git stash branch'.\n> \n> If a specific stash is specified, the 'Needed a single revision' errors\n> from rev-parse are suppressed.\n> \n> Signed-off-by: Ori Avtalion <ori@avtalion.name>\n> ---\n> \n> Thomas, I added handling for the 'git stash apply <stash>' case based\n> on your reminder, and also changed the error messages related to it.\n> \n> All of the stash tests pass, as before.\n\nAcked-by: Thomas Rast <trast@student.ethz.ch>\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"120650","messageId":"7v3a7ujhqb.fsf@alter.siamese.dyndns.org","threadId":"20531","inReplyTo":"4a81787d.0e0f660a.5238.4c8b@mx.google.com","subject":"Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-08-14T19:52:28Z","receivedAt":"2009-08-14T19:52:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ori Avtalion <ori@avtalion.name> writes:\n\n> The change makes sure a stash (given or default) exists before\n> checking if the working tree is dirty.\n>\n> If the default stash is requested, the old message was scary and\n> included a 'fatal' error from rev-parse:\n>      fatal: Needed a single revision\n>      : no valid stashed state found\n>\n> It is replaced with a friendlier 'Nothing to apply' error, similar to\n> 'git stash branch'.\n>\n> If a specific stash is specified, the 'Needed a single revision' errors\n> from rev-parse are suppressed.\n>\n> Signed-off-by: Ori Avtalion <ori@avtalion.name>\n> Acked-by: Thomas Rast <trast@student.ethz.ch>\n\nI do not see anything that might break existing usage of the command.\nComments?\n\nA tangent; we might want an analogue to \"shortlog -s -n\" but based on\n\"blame\".\n"},{"id":"120664","messageId":"20090815063956.6117@nanako3.lavabit.com","threadId":"20531","inReplyTo":"7v3a7ujhqb.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2009-08-14T21:39:56Z","receivedAt":"2009-08-14T21:39:56Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting Junio C Hamano <gitster@pobox.com>\n\n> Ori Avtalion <ori@avtalion.name> writes:\n>\n>> The change makes sure a stash (given or default) exists before\n>> checking if the working tree is dirty.\n>>\n>> If the default stash is requested, the old message was scary and\n>> included a 'fatal' error from rev-parse:\n>>      fatal: Needed a single revision\n>>      : no valid stashed state found\n>>\n>> It is replaced with a friendlier 'Nothing to apply' error, similar to\n>> 'git stash branch'.\n>>\n>> If a specific stash is specified, the 'Needed a single revision' errors\n>> from rev-parse are suppressed.\n>>\n>> Signed-off-by: Ori Avtalion <ori@avtalion.name>\n>> Acked-by: Thomas Rast <trast@student.ethz.ch>\n>\n> I do not see anything that might break existing usage of the command.\n> Comments?\n\nThe patch looks good to me. I think it was my fault but you can avoid \nadding two extra --quiet by inspecting i_tree (in other words, \"$s^2:\") \nbefore w_tree and b_tree. Because a commit that is a stash exactly has \ntwo parents, it may be good to also make sure 'git rev-parse \"$s^3\"' \nfails.\n\n\ts=$(git rev-parse --verify --default $ref_stash \"$@\") &&\n\t! git rev-parse --quiet --verify \"$s^3\" >/dev/null &&\n\ti_tree=$(git rev-parse --quiet --verify \"$s^2:\") &&\n\tb_tree=$(git rev-parse --verify \"$s^1:\") &&\n\tw_tree=$(git rev-parse --verify \"$s:\") ||\n\t\tdie \"$*: no valid stashed state found\"\n\n> A tangent; we might want an analogue to \"shortlog -s -n\" but based on\n> \"blame\".\n\nI'm sorry, I don't understand what you mean.\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"},{"id":"120681","messageId":"7vmy616e11.fsf@alter.siamese.dyndns.org","threadId":"20531","inReplyTo":"20090815063956.6117@nanako3.lavabit.com","subject":"Re: [PATCH] git stash: Give friendlier errors when there is nothing to apply","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-08-15T01:50:50Z","receivedAt":"2009-08-15T01:50:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nanako Shiraishi <nanako3@lavabit.com> writes:\n\n> Quoting Junio C Hamano <gitster@pobox.com>\n> ...\n>> A tangent; we might want an analogue to \"shortlog -s -n\" but based on\n>> \"blame\".\n>\n> I'm sorry, I don't understand what you mean.\n\nI often use shortlog to find whom to CC to, but sometimes blame output\ngives us a much better picture.\n\n$ git shortlog -s -n git-stash.sh | head -n 6\n    22\tJunio C Hamano\n     4\tBrandon Casey\n     2\tJeff King\n     2\tJohannes Schindelin\n     2\tNanako Shiraishi\n     2\tSZEDER Gábor\n\n$ git blame -w git-stash.sh |\n  sed -e 's/^[0-9a-f]* (\\(.*\\) *200[7-9]-..-.. .*/\\1/' |\n  sort | uniq -c | sort -n -r | head -n 6\n    110 Nanako Shiraishi    \n     86 Junio C Hamano      \n     55 Stephen Boyd        \n     33 Brandon Casey       \n     20 Abhijit Menon-Sen   \n     16 Johannes Schindelin \n"}]}