stash: implement "stash create"
This subcommand creates a stash from the current state and writes out the resulting commit object ID to the standard output, without updating the stash ref nor resetting the tree. It is intended to be used by scripts to temporarily rewind the working tree to a clean state. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 8, 2007 at 01:38 UTC
bc9e7399af3790918140c30a5b2c85bf9a8f1ad3
1 file changed
+21
-7
git-stash.sh
+21
-7
@@ -25,19 +25,13 @@ clear_stash () {
25
fi
26
}
27
28
-save_stash () {
28
+create_stash () {
29
stash_msg="$1"
30
31
if no_changes
32
then
33
- echo >&2 'No local changes to save'
33
exit 0
34
fi
36
- test -f "$GIT_DIR/logs/$ref_stash" ||
37
- clear_stash || die "Cannot initialize stash"
38
-
39
- # Make sure the reflog for stash is kept.
40
- : >>"$GIT_DIR/logs/$ref_stash"
35
36
# state of the base commit
37
if b_commit=$(git rev-parse --verify HEAD)
@@ -84,7 +78,20 @@ save_stash () {
78
w_commit=$(printf '%s\n' "$stash_msg" |
79
git commit-tree $w_tree -p $b_commit -p $i_commit) ||
80
die "Cannot record working tree state"
81
+}
82
83
+save_stash () {
84
+ stash_msg="$1"
85
+
86
+ if no_changes
87
+ then
88
+ echo >&2 'No local changes to save'
89
+ exit 0
90
+ fi
91
+ test -f "$GIT_DIR/logs/$ref_stash" ||
92
+ clear_stash || die "Cannot initialize stash"
93
+
94
+ create_stash "$stash_msg"
95
git update-ref -m "$stash_msg" $ref_stash $w_commit ||
96
die "Cannot save the current status"
97
printf >&2 'Saved "%s"\n' "$stash_msg"
@@ -202,6 +209,13 @@ apply)
209
clear)
210
clear_stash
211
;;
212
+create)
213
+ if test $# -gt 0 && test "$1" = create
214
+ then
215
+ shift
216
+ fi
217
+ create_stash "$*" && echo "$w_commit"
218
+ ;;
219
help | usage)
220
usage
221
;;