git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Adds 'stash.index' configuration option

From
Junio C Hamano <gitster@pobox.com>
Date
May 12, 2011, 00:26 UTC
Message-ID
<7vboz8epbp.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vfwoker7i.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
>> Setting 'stash.index' config option changes 'git-stash pop|apply' to behave
>> as if '--index' switch is always supplied.

One thing I forgot to say. "stash.index" invites "index _what_?" Naming it to "stash.useIndex" may avoid such reaction.

Also, the current code has this comment:
    #   INDEX_OPTION is set to --index if --index is specified.

but it probably makes sense to change it (in the first patch in the series that adds --no-index support) to a boolean whose value can be either true or empty.

The reason why the very original code used INDEX_OPTION=--index may be because it did something like "git some-cmd $INDEX_OPTION", but that is not what the current code does, and using "either '--index' or ''" as a form of boolean is confusing.

In other words, something like....
 git-stash.sh |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index 0a94036..eed2d1e 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -239,7 +239,7 @@ show_stash () {
 #   i_tree is set to the index tree
 #
 #   GIT_QUIET is set to t if -q is specified
-#   INDEX_OPTION is set to --index if --index is specified.
+#   INDEX_OPTION is set to 'true' if applying/popping also to the index.
 #   FLAGS is set to the remaining flags
 #
 # dies if:
@@ -271,14 +271,17 @@ parse_flags_and_rev()
 	for opt
 	do
 		case "$opt" in
-			-q|--quiet)
-				GIT_QUIET=-t
+		-q|--quiet)
+			GIT_QUIET=-t
+			;;
+		--index)
+			INDEX_OPTION=true
 			;;
-			--index)
-				INDEX_OPTION=--index
+		--no-index)
+			INDEX_OPTION=
 			;;
-			-*)
-				FLAGS="${FLAGS}${FLAGS:+ }$opt"
+		-*)
+			FLAGS="${FLAGS}${FLAGS:+ }$opt"
 			;;
 		esac
 	done
@@ -286,15 +289,15 @@ parse_flags_and_rev()
 	set -- $REV
 
 	case $# in
-		0)
-			have_stash || die "No stash found."
-			set -- ${ref_stash}@{0}
+	0)
+		have_stash || die "No stash found."
+		set -- ${ref_stash}@{0}
 		;;
-		1)
-			:
+	1)
+		:
 		;;
-		*)
-			die "Too many revisions specified: $REV"
+	*)
+		die "Too many revisions specified: $REV"
 		;;
 	esac
 
@@ -342,8 +345,8 @@ apply_stash () {
 		die 'Cannot apply a stash in the middle of a merge'
 
 	unstashed_index_tree=
-	if test -n "$INDEX_OPTION" && test "$b_tree" != "$i_tree" &&
-			test "$c_tree" != "$i_tree"
+	if test true = "$INDEX_OPTION" &&
+		test "$b_tree" != "$i_tree" && test "$c_tree" != "$i_tree"
 	then
 		git diff-tree --binary $s^2^..$s^2 | git apply --cached
 		test $? -ne 0 &&
@@ -387,7 +390,7 @@ apply_stash () {
 	else
 		# Merge conflict; keep the exit status from merge-recursive
 		status=$?
-		if test -n "$INDEX_OPTION"
+		if test true = "$INDEX_OPTION"
 		then
 			echo >&2 'Index was not unstashed.'
 		fi




	
Previous: Junio C HamanoNext: David Pisoni
Message 3 of 14 in “Adds 'stash.index' configuration option”
  1. Adds 'stash.index' configuration optionDavid Pisoni, May 11, 2011
  2. Junio C HamanoMay 11, 2011
  3. Junio C HamanoMay 12, 2011
  4. David PisoniMay 12, 2011
  5. Junio C HamanoMay 12, 2011
  6. Michael J GruberMay 12, 2011
  7. Jeff KingMay 12, 2011
  8. Michael J GruberMay 12, 2011
  9. Jeff KingMay 12, 2011
  10. RFC proposal: set git defaults options from configMichael J Gruber, May 12, 2011
  11. David PisoniMay 12, 2011
  12. Jeff KingMay 16, 2011
  13. Jeff KingMay 16, 2011
  14. Michael J GruberMay 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.