Quoting Junio C Hamano <gitster@xxxxxxxxx>: > Jörg Sommer <joerg@xxxxxxxxxxxx> writes: > >> When it should go quick why don't use an alias. git stash can print the >> list and everyone who wants a quick stash can create an alias for this. > > You are taking this completely backwards. The stash mechanism is all > about creating a quickie temporary pair of commits. Anybody who wants > otherwise can use alias or choose not to use stash at all. You are of course right. That was the reason I made git-stash command behave that way in the first place. But I see that some people on the list find this behavior dangerous and I can understand their fears. Until one learns that one can go back to the state before running git-stash by running "git-stash apply" soon after that, it appears to one that the work is lost. How about making this behavior configurable? -- 8< -- [PATCH] Make "git stash" configurable "git stash" without argument originally created an unnamed stash, but some people felt this can be confusing to new users. This introduces config variable stash.quick to control this behavior. The variable can take one of three values: true, false, ask. When set to "true", the command allows to create a quick stash without any user interaction. When set to "false", the command shows the list of stash instead. When set to "ask", the command asks the user. For the first time users, when the variable is not set, the command helps the user to set it interactively. Signed-off-by: Nanako Shiraishi <nanako3@xxxxxxxxxxxxxx> --- git-stash.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 70 insertions(+), 2 deletions(-) diff --git a/git-stash.sh b/git-stash.sh index f16fd9c..4bb7134 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -192,6 +192,69 @@ apply_stash () { fi } +allow_quick_stash () { + + quick=$(git config stash.quick) + if test $? != 0 + then + if ! test -t 0 || ! test -t 1 + then + return 0 + fi + + echo ' +*** First time users *** + +"git stash" can create an unnamed stash entry without user interaction. +This is a quick way to save away your work in progress. Some people +find this behaviour confusing or dangerous to new users. You can +configure the command to list the existing stash entries instead.' + + while : + do + echo ' +Do you want the command without argument to always... + +1. Ask for confirmation +2. Create an unnamed stash +3. List existing stash entries +' + printf 'Which one? [1/2/3] ' + read reply + quick= + case "$reply" in + 1|A*) quick=ask ;; + 2|C*) quick=true ;; + 3|L*) quick=false ;; + *) continue ;; + esac + break + done + git config stash.quick $quick + echo ' +You can reconfigure this by editing your $HOME/.gitconfig file' + + fi + + case "$quick" in + true) return 0 ;; + false) return 1 ;; + ask) : do not return ;; + esac + + if ! test -t 0 || ! test -t 1 + then + return 0 + fi + + printf 'Do you want to create an unnamed stash? [Y/n] ' + read reply + case "$reply" in + [nN]*) return 1 ;; + *) return 0 ;; + esac +} + # Main command set case "$1" in list) @@ -226,11 +289,16 @@ create) create_stash "$*" && echo "$w_commit" ;; *) - if test $# -eq 0 + if test $# -ne 0 + then + usage + fi + if allow_quick_stash then save_stash && git-reset --hard else - usage + echo "*** Stash List ***" + list_stash fi ;; esac -- 1.5.3.7 -- Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/ ---------------------------------------------------------------------- Find out how you can get spam free email. http://www.bluebottle.com/tag/3 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html