git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: しらいしななこ <nanako3@bluebottle.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Jörg Sommer" <joerg@alea.gnuu.de>
Subject: Re: git-stash: RFC: Adopt the default behavior to other commands
Date: Wed, 21 Dec 2007 06:40:38 +0900	[thread overview]
Message-ID: <200712202145.lBKLj7Fu015050@mi0.bluebottle.com> (raw)
In-Reply-To: <7vabo7y762.fsf@gitster.siamese.dyndns.org>

Quoting Junio C Hamano <gitster@pobox.com>:
> Jörg Sommer <joerg@alea.gnuu.de> 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@bluebottle.com>

---

 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

  reply	other threads:[~2007-12-20 21:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-17 11:03 git-stash: RFC: Adopt the default behavior to other commands Sebastian Harl
2007-12-17 22:32 ` Benoit Sigoure
2007-12-17 23:00   ` Junio C Hamano
2007-12-17 23:32     ` Benoit Sigoure
2007-12-18  0:31       ` Junio C Hamano
2007-12-18 10:59         ` Sebastian Harl
2007-12-18 12:33           ` Johannes Schindelin
2007-12-18 14:22             ` Andreas Ericsson
2007-12-18 14:47               ` Johannes Schindelin
2007-12-18 15:00                 ` Andreas Ericsson
2007-12-18 15:15                   ` Johannes Schindelin
2007-12-18 15:28                     ` Andreas Ericsson
2007-12-18 15:40                       ` Jakub Narebski
2007-12-18 16:06                         ` Andreas Ericsson
2007-12-18 16:11                           ` Johannes Schindelin
2007-12-18 17:40                             ` Sergei Organov
2007-12-18 18:03                               ` Johannes Schindelin
2007-12-18 23:31                                 ` Martin Langhoff
2007-12-18 15:28               ` Wincent Colaiuta
2007-12-18 15:42         ` Jörg Sommer
2007-12-18 22:13           ` Johannes Schindelin
2007-12-18 22:22           ` Junio C Hamano
2007-12-20 21:40             ` しらいしななこ [this message]
2007-12-20 22:31               ` Junio C Hamano
2007-12-21  7:59                 ` Wincent Colaiuta
2007-12-21  8:40                 ` しらいしななこ
2007-12-18 23:32           ` André Goddard Rosa
2007-12-18 23:41           ` Martin Langhoff
2007-12-19  7:33             ` Wincent Colaiuta
2007-12-19  7:46               ` Martin Langhoff
2007-12-19  8:29                 ` Andreas Ericsson
2007-12-19 12:01                 ` Johannes Schindelin
2007-12-19 12:07                   ` Wincent Colaiuta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200712202145.lBKLj7Fu015050@mi0.bluebottle.com \
    --to=nanako3@bluebottle.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=joerg@alea.gnuu.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).