Merge branch 'rr/rebase-stash-store'

Finishing touches for the "git rebase --autostash" feature
introduced earlier.

* rr/rebase-stash-store:
  rebase: use 'git stash store' to simplify logic
  stash: introduce 'git stash store'
  stash: simplify option parser for create
  stash doc: document short form -p in synopsis
  stash doc: add a warning about using create
This commit is contained in:
Junio C Hamano 2013-06-27 14:29:41 -07:00
commit fa4bf9edb9
4 changed files with 74 additions and 17 deletions

View File

@ -13,10 +13,11 @@ SYNOPSIS
'git stash' drop [-q|--quiet] [<stash>] 'git stash' drop [-q|--quiet] [<stash>]
'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>] 'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
'git stash' branch <branchname> [<stash>] 'git stash' branch <branchname> [<stash>]
'git stash' [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] 'git stash' [save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]] [-u|--include-untracked] [-a|--all] [<message>]]
'git stash' clear 'git stash' clear
'git stash' create 'git stash' create [<message>]
'git stash' store [-m|--message <message>] [-q|--quiet] <commit>
DESCRIPTION DESCRIPTION
----------- -----------
@ -151,7 +152,15 @@ create::
Create a stash (which is a regular commit object) and return its Create a stash (which is a regular commit object) and return its
object name, without storing it anywhere in the ref namespace. object name, without storing it anywhere in the ref namespace.
This is intended to be useful for scripts. It is probably not
the command you want to use; see "save" above.
store::
Store a given stash created via 'git stash create' (which is a
dangling merge commit) in the stash ref, updating the stash
reflog. This is intended to be useful for scripts. It is
probably not the command you want to use; see "save" above.
DISCUSSION DISCUSSION
---------- ----------

View File

@ -155,11 +155,8 @@ finish_rebase () {
then then
echo "$(gettext 'Applied autostash.')" echo "$(gettext 'Applied autostash.')"
else else
ref_stash=refs/stash && git stash store -m "autostash" -q $stash_sha1 ||
>>"$GIT_DIR/logs/$ref_stash" && die "$(eval_gettext "Cannot store \$stash_sha1")"
git update-ref -m "autostash" $ref_stash $stash_sha1 ||
die "$(eval_gettext 'Cannot store $stash_sha1')"
gettext 'Applying autostash resulted in conflicts. gettext 'Applying autostash resulted in conflicts.
Your changes are safe in the stash. Your changes are safe in the stash.
You can run "git stash pop" or "git stash drop" it at any time. You can run "git stash pop" or "git stash drop" it at any time.

View File

@ -156,6 +156,41 @@ create_stash () {
die "$(gettext "Cannot record working tree state")" die "$(gettext "Cannot record working tree state")"
} }
store_stash () {
while test $# != 0
do
case "$1" in
-m|--message)
shift
stash_msg="$1"
;;
-q|--quiet)
quiet=t
;;
*)
break
;;
esac
shift
done
test $# = 1 ||
die "$(eval_gettext "\"$dashless store\" requires one <commit> argument")"
w_commit="$1"
if test -z "$stash_msg"
then
stash_msg="Created via \"git stash store\"."
fi
# Make sure the reflog for stash is kept.
: >>"$GIT_DIR/logs/$ref_stash"
git update-ref -m "$stash_msg" $ref_stash $w_commit
ret=$?
test $ret != 0 && test -z $quiet &&
die "$(eval_gettext "Cannot update \$ref_stash with \$w_commit")"
return $ret
}
save_stash () { save_stash () {
keep_index= keep_index=
patch_mode= patch_mode=
@ -227,12 +262,8 @@ save_stash () {
clear_stash || die "$(gettext "Cannot initialize stash")" clear_stash || die "$(gettext "Cannot initialize stash")"
create_stash "$stash_msg" $untracked create_stash "$stash_msg" $untracked
store_stash -m "$stash_msg" -q $w_commit ||
# Make sure the reflog for stash is kept. die "$(gettext "Cannot save the current status")"
: >>"$GIT_DIR/logs/$ref_stash"
git update-ref -m "$stash_msg" $ref_stash $w_commit ||
die "$(gettext "Cannot save the current status")"
say Saved working directory and index state "$stash_msg" say Saved working directory and index state "$stash_msg"
if test -z "$patch_mode" if test -z "$patch_mode"
@ -546,12 +577,13 @@ clear)
clear_stash "$@" clear_stash "$@"
;; ;;
create) create)
if test $# -gt 0 && test "$1" = create shift
then
shift
fi
create_stash "$*" && echo "$w_commit" create_stash "$*" && echo "$w_commit"
;; ;;
store)
shift
store_stash "$@"
;;
drop) drop)
shift shift
drop_stash "$@" drop_stash "$@"

View File

@ -654,4 +654,23 @@ test_expect_success 'stash where working directory contains "HEAD" file' '
test_cmp output expect test_cmp output expect
' '
test_expect_success 'store called with invalid commit' '
test_must_fail git stash store foo
'
test_expect_success 'store updates stash ref and reflog' '
git stash clear &&
git reset --hard &&
echo quux >bazzy &&
git add bazzy &&
STASH_ID=$(git stash create) &&
git reset --hard &&
! grep quux bazzy &&
git stash store -m quuxery $STASH_ID &&
test $(cat .git/refs/stash) = $STASH_ID &&
grep $STASH_ID .git/logs/refs/stash &&
git stash pop &&
grep quux bazzy
'
test_done test_done