git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Adds 'stash.index' configuration option
@ 2011-05-11 22:57 David Pisoni
  2011-05-11 23:46 ` Junio C Hamano
  2011-05-12  7:14 ` Michael J Gruber
  0 siblings, 2 replies; 14+ messages in thread
From: David Pisoni @ 2011-05-11 22:57 UTC (permalink / raw)
  To: GIt Mailing List, Git Maintainer


Setting 'stash.index' config option changes 'git-stash pop|apply' to  
behave
as if '--index' switch is always supplied.
'git-stash pop|apply' provides a --no-index switch to circumvent  
config default.

Signed-off-by: David Pisoni <dpisoni@gmail.com>
---
Documentation/config.txt    |    5 +++++
Documentation/git-stash.txt |   10 +++++++---
git-stash.sh                |    7 ++++++-
t/t3903-stash.sh            |   28 ++++++++++++++++++++++++++++
4 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 285c7f7..d794c40 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1746,6 +1746,11 @@ showbranch.default::
	The default set of branches for linkgit:git-show-branch[1].
	See linkgit:git-show-branch[1].

+stash.index::
+    A boolean to make linkgit:git-stash[1] default to the behavior of  
--index
+	when applying a stash to the working copy.  Can be circumvented by  
using
+	--no-index switch to linkgit:git-stash[1].  Defaults to false.
+
status.relativePaths::
	By default, linkgit:git-status[1] shows paths relative to the
	current directory. Setting this variable to `false` shows paths
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 15f051f..de086ee 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -11,7 +11,7 @@ SYNOPSIS
'git stash' list [<options>]
'git stash' show [<stash>]
'git stash' drop [-q|--quiet] [<stash>]
-'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
+'git stash' ( pop | apply ) [--[no-]index] [-q|--quiet] [<stash>]
'git stash' branch <branchname> [<stash>]
'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]  
[<message>]]
'git stash' clear
@@ -89,7 +89,7 @@ show [<stash>]::
	it will accept any format known to 'git diff' (e.g., `git stash show
	-p stash@\{1}` to view the second most recent stash in patch form).

-pop [--index] [-q|--quiet] [<stash>]::
+pop [--[no-]index] [-q|--quiet] [<stash>]::

	Remove a single stashed state from the stash list and apply it
	on top of the current working tree state, i.e., do the inverse
@@ -105,10 +105,14 @@ tree's changes, but also the index's ones.  
However, this can fail, when you
have conflicts (which are stored in the index, where you therefore can  
no
longer apply the changes as they were originally).
+
+If the configuration option `stash.index` is set `pop` will behave as  
if the
+`--index` option is always in use, unless explicitly overridden with
+`--no-index`.
++
When no `<stash>` is given, `stash@\{0}` is assumed, otherwise  
`<stash>` must
be a reference of the form `stash@\{<revision>}`.

-apply [--index] [-q|--quiet] [<stash>]::
+apply [--[no-]index] [-q|--quiet] [<stash>]::

	Like `pop`, but do not remove the state from the stash list. Unlike  
`pop`,
	`<stash>` may be any commit that looks like a commit created by
diff --git a/git-stash.sh b/git-stash.sh
index 0a94036..7711bf6 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -31,6 +31,8 @@ else
        reset_color=
fi

+CONFIG_INDEX="$(git config stash.index)"
+
no_changes () {
	git diff-index --quiet --cached HEAD --ignore-submodules -- &&
	git diff-files --quiet --ignore-submodules
@@ -256,7 +258,7 @@ parse_flags_and_rev()

	IS_STASH_LIKE=
	IS_STASH_REF=
-	INDEX_OPTION=
+	INDEX_OPTION=$CONFIG_INDEX
	s=
	w_commit=
	b_commit=
@@ -277,6 +279,9 @@ parse_flags_and_rev()
			--index)
				INDEX_OPTION=--index
			;;
+			--no-index)
+				unset INDEX_OPTION
+			;;
			-*)
				FLAGS="${FLAGS}${FLAGS:+ }$opt"
			;;
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 5c72540..4999682 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -84,6 +84,34 @@ test_expect_success 'apply stashed changes  
(including index)' '
	test 1 = $(git show HEAD:file)
'

+test_expect_success 'apply stashed changes (including index) with  
index config set' '
+    git config stash.index yes &&
+	git reset --hard HEAD^ &&
+	echo 7 > other-file &&
+	git add other-file &&
+	test_tick &&
+	git commit -m other-file &&
+	git stash apply &&
+	test 3 = $(cat file) &&
+	test 2 = $(git show :file) &&
+	test 1 = $(git show HEAD:file) &&
+	git config --unset stash.index
+'
+
+test_expect_success 'apply stashed changes (excluding index) with  
index config set' '
+    git config stash.index yes &&
+	git reset --hard &&
+	echo 8 >other-file &&
+	git add other-file &&
+	test_tick &&
+	git commit -m other-file &&
+	git stash apply --no-index &&
+	test 3 = $(cat file) &&
+	test 1 = $(git show :file) &&
+	test 1 = $(git show HEAD:file) &&
+	git config --unset stash.index
+'
+
test_expect_success 'unstashing in a subdirectory' '
	git reset --hard HEAD &&
	mkdir subdir &&
-- 
1.7.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-05-16 12:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-11 22:57 [PATCH] Adds 'stash.index' configuration option David Pisoni
2011-05-11 23:46 ` Junio C Hamano
2011-05-12  0:26   ` Junio C Hamano
2011-05-12  0:48     ` David Pisoni
2011-05-12  0:54       ` Junio C Hamano
2011-05-12  7:14 ` Michael J Gruber
2011-05-12  8:04   ` Jeff King
2011-05-12  8:14     ` Michael J Gruber
2011-05-12  8:22       ` Jeff King
2011-05-12 14:35         ` RFC proposal: set git defaults options from config Michael J Gruber
2011-05-12 22:36           ` David Pisoni
2011-05-16 11:05             ` Jeff King
2011-05-16 11:02           ` Jeff King
2011-05-16 12:54             ` Michael J Gruber

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).