From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 4/6] stash: introduce 'git stash store'
Date: Mon, 13 May 2013 18:15:52 +0530 [thread overview]
Message-ID: <1368449154-21882-5-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1368449154-21882-1-git-send-email-artagnon@gmail.com>
save_stash() contains the logic for doing two potentially independent
operations; the first is preparing the stash merge commit, and the
second is updating the stash ref/ reflog accordingly. While the first
operation is abstracted out into a create_stash() for callers to access
via 'git stash create', the second one is not. Fix this by factoring
out the logic for storing the stash into a store_stash() that callers
can access via 'git stash store'.
Like create, store is not intended for end user interactive use, but for
callers in other scripts. We can simplify the logic in the
rebase.autostash feature using this new subcommand.
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
Documentation/git-stash.txt | 6 ++++++
git-stash.sh | 25 +++++++++++++++++++------
t/t3903-stash.sh | 20 ++++++++++++++++++++
3 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt
index 05e462b..e58ab74 100644
--- a/Documentation/git-stash.txt
+++ b/Documentation/git-stash.txt
@@ -17,6 +17,7 @@ SYNOPSIS
[-u|--include-untracked] [-a|--all] [<message>]]
'git stash' clear
'git stash' create [<message> [<include-untracked-p>]]
+'git stash' store <commit> <message>
DESCRIPTION
-----------
@@ -152,6 +153,11 @@ create::
Create a stash (which is a regular commit object) and return its
object name, without storing it anywhere in the ref namespace.
+store::
+
+ Store a given stash created via 'git stash create' (which is a
+ dangling merge commit) in the stash ref, updating the stash
+ reflog.
DISCUSSION
----------
diff --git a/git-stash.sh b/git-stash.sh
index 0ede313..1d483f5 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -156,6 +156,20 @@ create_stash () {
die "$(gettext "Cannot record working tree state")"
}
+store_stash () {
+ if test $# != 2
+ then
+ die "$(gettext "git stash store requires two arguments")"
+ fi
+ w_commit="$1"
+ stash_msg="$2"
+
+ # Make sure the reflog for stash is kept.
+ : >>"$GIT_DIR/logs/$ref_stash"
+ git update-ref -m "$stash_msg" $ref_stash $w_commit ||
+ die "$(gettext "Cannot save the current status")"
+}
+
save_stash () {
keep_index=
patch_mode=
@@ -227,12 +241,7 @@ save_stash () {
clear_stash || die "$(gettext "Cannot initialize stash")"
create_stash "$stash_msg" $untracked
-
- # Make sure the reflog for stash is kept.
- : >>"$GIT_DIR/logs/$ref_stash"
-
- git update-ref -m "$stash_msg" $ref_stash $w_commit ||
- die "$(gettext "Cannot save the current status")"
+ store_stash $w_commit "$stash_msg"
say Saved working directory and index state "$stash_msg"
if test -z "$patch_mode"
@@ -549,6 +558,10 @@ create)
shift
create_stash "$@" && echo "$w_commit"
;;
+store)
+ shift
+ store_stash "$@"
+ ;;
drop)
shift
drop_stash "$@"
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 5dfbda7..2ff3afd 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -637,4 +637,24 @@ test_expect_success 'stash where working directory contains "HEAD" file' '
test_cmp output expect
'
+test_expect_success 'store - argument 1 not a commit' '
+ test_must_fail git stash store foo bar
+'
+
+test_expect_success 'store - updates stash ref and reflog' '
+ git stash clear &&
+ git reset --hard &&
+ echo quux >file &&
+ git add file &&
+ STASH_ID=$(git stash create) &&
+ git reset --hard &&
+ ! grep quux file &&
+ git stash store ${STASH_ID} quuxery &&
+ test $(cat .git/refs/stash) = ${STASH_ID} &&
+ grep ${STASH_ID} .git/logs/refs/stash &&
+ git stash pop &&
+ grep quux file &&
+ false
+'
+
test_done
--
1.8.3.rc1.57.g4ac1522
next prev parent reply other threads:[~2013-05-13 12:44 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-13 12:45 [PATCH 0/6] Get stash to help rebase.autostash Ramkumar Ramachandra
2013-05-13 12:45 ` [PATCH 1/6] Documentation/stash: correct synopsis for create Ramkumar Ramachandra
2013-05-13 12:45 ` [PATCH 2/6] Documentation/stash: document short form -p in synopsis Ramkumar Ramachandra
2013-05-13 12:45 ` [PATCH 3/6] stash: simplify option parser for create Ramkumar Ramachandra
2013-05-13 14:34 ` Junio C Hamano
2013-05-13 14:59 ` Ramkumar Ramachandra
2013-05-13 12:45 ` Ramkumar Ramachandra [this message]
2013-05-13 14:40 ` [PATCH 4/6] stash: introduce 'git stash store' Junio C Hamano
2013-05-13 15:02 ` Ramkumar Ramachandra
2013-05-13 15:49 ` Junio C Hamano
2013-05-13 17:15 ` Ramkumar Ramachandra
2013-05-13 17:29 ` Junio C Hamano
2013-05-13 18:09 ` Ramkumar Ramachandra
2013-05-13 18:35 ` Junio C Hamano
2013-05-13 18:45 ` Ramkumar Ramachandra
2013-05-13 19:16 ` Junio C Hamano
2013-05-13 19:25 ` Ramkumar Ramachandra
2013-05-13 18:15 ` Ramkumar Ramachandra
2013-05-13 12:45 ` [PATCH 5/6] stash: tweak error message in store_stash () Ramkumar Ramachandra
2013-05-13 14:42 ` Junio C Hamano
2013-05-13 12:45 ` [PATCH 6/6] rebase: use 'git stash store' to simplify logic Ramkumar Ramachandra
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=1368449154-21882-5-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).