Skip to content

Commit 5e389c4

Browse files
committed
Merge branch 'jc/stash-create'
* jc/stash-create: git-stash: Fix listing stashes git-merge: no reason to use cpio anymore Revert "rebase: allow starting from a dirty tree." rebase: allow starting from a dirty tree. stash: implement "stash create"
2 parents 55571f7 + a9ee9bf commit 5e389c4

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

git-merge.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,19 @@ allow_trivial_merge=t
2828

2929
dropsave() {
3030
rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" \
31-
"$GIT_DIR/MERGE_SAVE" || exit 1
31+
"$GIT_DIR/MERGE_STASH" || exit 1
3232
}
3333

3434
savestate() {
3535
# Stash away any local modifications.
36-
git diff-index -z --name-only $head |
37-
cpio -0 -o >"$GIT_DIR/MERGE_SAVE"
36+
git stash create >"$GIT_DIR/MERGE_STASH"
3837
}
3938

4039
restorestate() {
41-
if test -f "$GIT_DIR/MERGE_SAVE"
40+
if test -f "$GIT_DIR/MERGE_STASH"
4241
then
4342
git reset --hard $head >/dev/null
44-
cpio -iuv <"$GIT_DIR/MERGE_SAVE"
43+
git stash apply $(cat "$GIT_DIR/MERGE_STASH")
4544
git update-index --refresh >/dev/null
4645
fi
4746
}
@@ -437,7 +436,7 @@ case "$use_strategies" in
437436
single_strategy=no
438437
;;
439438
*)
440-
rm -f "$GIT_DIR/MERGE_SAVE"
439+
rm -f "$GIT_DIR/MERGE_STASH"
441440
single_strategy=yes
442441
;;
443442
esac

git-stash.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,17 @@ no_changes () {
2121
clear_stash () {
2222
if current=$(git rev-parse --verify $ref_stash 2>/dev/null)
2323
then
24-
git update-ref -d refs/stash $current
24+
git update-ref -d $ref_stash $current
2525
fi
2626
}
2727

28-
save_stash () {
28+
create_stash () {
2929
stash_msg="$1"
3030

3131
if no_changes
3232
then
33-
echo >&2 'No local changes to save'
3433
exit 0
3534
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"
4135

4236
# state of the base commit
4337
if b_commit=$(git rev-parse --verify HEAD)
@@ -84,6 +78,23 @@ save_stash () {
8478
w_commit=$(printf '%s\n' "$stash_msg" |
8579
git commit-tree $w_tree -p $b_commit -p $i_commit) ||
8680
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+
96+
# Make sure the reflog for stash is kept.
97+
: >>"$GIT_DIR/logs/$ref_stash"
8798

8899
git update-ref -m "$stash_msg" $ref_stash $w_commit ||
89100
die "Cannot save the current status"
@@ -202,6 +213,13 @@ apply)
202213
clear)
203214
clear_stash
204215
;;
216+
create)
217+
if test $# -gt 0 && test "$1" = create
218+
then
219+
shift
220+
fi
221+
create_stash "$*" && echo "$w_commit"
222+
;;
205223
help | usage)
206224
usage
207225
;;

0 commit comments

Comments
 (0)