Browse Source

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
maint
Junio C Hamano 12 years ago
parent
commit
fa4bf9edb9
  1. 13
      Documentation/git-stash.txt
  2. 7
      git-rebase.sh
  3. 52
      git-stash.sh
  4. 19
      t/t3903-stash.sh

13
Documentation/git-stash.txt

@ -13,10 +13,11 @@ SYNOPSIS @@ -13,10 +13,11 @@ SYNOPSIS
'git stash' drop [-q|--quiet] [<stash>]
'git stash' ( pop | apply ) [--index] [-q|--quiet] [<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>]]
'git stash' clear
'git stash' create
'git stash' create [<message>]
'git stash' store [-m|--message <message>] [-q|--quiet] <commit>

DESCRIPTION
-----------
@ -151,7 +152,15 @@ create:: @@ -151,7 +152,15 @@ create::

Create a stash (which is a regular commit object) and return its
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
----------

7
git-rebase.sh

@ -155,11 +155,8 @@ finish_rebase () { @@ -155,11 +155,8 @@ finish_rebase () {
then
echo "$(gettext 'Applied autostash.')"
else
ref_stash=refs/stash &&
>>"$GIT_DIR/logs/$ref_stash" &&
git update-ref -m "autostash" $ref_stash $stash_sha1 ||
die "$(eval_gettext 'Cannot store $stash_sha1')"

git stash store -m "autostash" -q $stash_sha1 ||
die "$(eval_gettext "Cannot store \$stash_sha1")"
gettext 'Applying autostash resulted in conflicts.
Your changes are safe in the stash.
You can run "git stash pop" or "git stash drop" it at any time.

52
git-stash.sh

@ -156,6 +156,41 @@ create_stash () { @@ -156,6 +156,41 @@ create_stash () {
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 () {
keep_index=
patch_mode=
@ -227,12 +262,8 @@ save_stash () { @@ -227,12 +262,8 @@ 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 -m "$stash_msg" -q $w_commit ||
die "$(gettext "Cannot save the current status")"
say Saved working directory and index state "$stash_msg"

if test -z "$patch_mode"
@ -546,12 +577,13 @@ clear) @@ -546,12 +577,13 @@ clear)
clear_stash "$@"
;;
create)
if test $# -gt 0 && test "$1" = create
then
shift
fi
shift
create_stash "$*" && echo "$w_commit"
;;
store)
shift
store_stash "$@"
;;
drop)
shift
drop_stash "$@"

19
t/t3903-stash.sh

@ -654,4 +654,23 @@ test_expect_success 'stash where working directory contains "HEAD" file' ' @@ -654,4 +654,23 @@ test_expect_success 'stash where working directory contains "HEAD" file' '
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

Loading…
Cancel
Save