]> git.ipfire.org Git - thirdparty/git.git/blame - git-stash.sh
stash: replace all `write-tree` child processes with API calls
[thirdparty/git.git] / git-stash.sh
CommitLineData
f2c66ed1
NS
1#!/bin/sh
2# Copyright (c) 2007, Nanako Shiraishi
3
a5ab00c5
SB
4dashless=$(basename "$0" | sed -e 's/-/ /')
5USAGE="list [<options>]
fcdd0e92
SB
6 or: $dashless show [<stash>]
7 or: $dashless drop [-q|--quiet] [<stash>]
8 or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>]
a5ab00c5 9 or: $dashless branch <branchname> [<stash>]
1ada5020
TG
10 or: $dashless save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
11 [-u|--include-untracked] [-a|--all] [<message>]
12 or: $dashless [push [--patch] [-k|--[no-]keep-index] [-q|--quiet]
13 [-u|--include-untracked] [-a|--all] [-m <message>]
14 [-- <pathspec>...]]
a5ab00c5 15 or: $dashless clear"
f2c66ed1 16
3cd2491a 17SUBDIRECTORY_OK=Yes
8f321a39 18OPTIONS_SPEC=
d0ea45bf 19START_DIR=$(pwd)
f2c66ed1
NS
20. git-sh-setup
21require_work_tree
22fc703e 22prefix=$(git rev-parse --show-prefix) || exit 1
ceff079b 23cd_to_toplevel
f2c66ed1
NS
24
25TMP="$GIT_DIR/.git-stash.$$"
c697b577 26TMPindex=${GIT_INDEX_FILE-"$(git rev-parse --git-path index)"}.stash.$$
3ba2e865 27trap 'rm -f "$TMP-"* "$TMPindex"' 0
f2c66ed1
NS
28
29ref_stash=refs/stash
30
dda1f2a5
TR
31if git config --get-colorbool color.interactive; then
32 help_color="$(git config --get-color color.interactive.help 'red bold')"
33 reset_color="$(git config --get-color '' reset)"
34else
35 help_color=
36 reset_color=
37fi
38
ef763129
JS
39#
40# Parses the remaining options looking for flags and
41# at most one revision defaulting to ${ref_stash}@{0}
42# if none found.
43#
44# Derives related tree and commit objects from the
45# revision, if one is found.
46#
47# stash records the work tree, and is a merge between the
48# base commit (first parent) and the index tree (second parent).
49#
50# REV is set to the symbolic version of the specified stash-like commit
51# IS_STASH_LIKE is non-blank if ${REV} looks like a stash
52# IS_STASH_REF is non-blank if the ${REV} looks like a stash ref
53# s is set to the SHA1 of the stash commit
54# w_commit is set to the commit containing the working tree
55# b_commit is set to the base commit
56# i_commit is set to the commit containing the index tree
78751302 57# u_commit is set to the commit containing the untracked files tree
ef763129
JS
58# w_tree is set to the working tree
59# b_tree is set to the base tree
60# i_tree is set to the index tree
78751302 61# u_tree is set to the untracked files tree
ef763129
JS
62#
63# GIT_QUIET is set to t if -q is specified
64# INDEX_OPTION is set to --index if --index is specified.
d6cc2df5 65# FLAGS is set to the remaining flags (if allowed)
ef763129
JS
66#
67# dies if:
68# * too many revisions specified
69# * no revision is specified and there is no stash stack
70# * a revision is specified which cannot be resolve to a SHA1
71# * a non-existent stash reference is specified
d6cc2df5 72# * unknown flags were set and ALLOW_UNKNOWN_FLAGS is not "t"
ef763129
JS
73#
74
9e140909
TG
75test "$1" = "-p" && set "push" "$@"
76
ef763129 77PARSE_CACHE='--not-parsed'
1ada5020 78# The default command is "push" if nothing but options are given
3c2eb80f
MM
79seen_non_option=
80for opt
81do
82 case "$opt" in
9e140909 83 --) break ;;
3c2eb80f
MM
84 -*) ;;
85 *) seen_non_option=t; break ;;
86 esac
87done
88
1ada5020 89test -n "$seen_non_option" || set "push" "$@"
3c2eb80f 90
f2c66ed1
NS
91# Main command set
92case "$1" in
fcb10a96
JH
93list)
94 shift
130f2697 95 git stash--helper list "$@"
f2c66ed1
NS
96 ;;
97show)
98 shift
dc7bd382 99 git stash--helper show "$@"
f2c66ed1 100 ;;
683befa1
KL
101save)
102 shift
64fe9c26
PSU
103 cd "$START_DIR"
104 git stash--helper save "$@"
683befa1 105 ;;
f5727e26
TG
106push)
107 shift
d553f538
PSU
108 cd "$START_DIR"
109 git stash--helper push "$@"
f5727e26 110 ;;
f2c66ed1
NS
111apply)
112 shift
8a0fc8d1
JT
113 cd "$START_DIR"
114 git stash--helper apply "$@"
f2c66ed1
NS
115 ;;
116clear)
3023dc69 117 shift
4e2dd393 118 git stash--helper clear "$@"
f2c66ed1 119 ;;
bc9e7399 120create)
0719f300 121 shift
d4788af8 122 git stash--helper create --message "$*"
bc9e7399 123 ;;
bd514cad
RR
124store)
125 shift
41e0dd55 126 git stash--helper store "$@"
bd514cad 127 ;;
e25d5f9c
BC
128drop)
129 shift
4e2dd393 130 git stash--helper drop "$@"
e25d5f9c 131 ;;
bd56ff54
BC
132pop)
133 shift
c4de61d7
JT
134 cd "$START_DIR"
135 git stash--helper pop "$@"
bd56ff54 136 ;;
656b5034
AMS
137branch)
138 shift
577c1995
JT
139 cd "$START_DIR"
140 git stash--helper branch "$@"
656b5034 141 ;;
f2c66ed1 142*)
3c2eb80f
MM
143 case $# in
144 0)
d553f538
PSU
145 cd "$START_DIR"
146 git stash--helper push &&
5a175871 147 say "$(gettext "(To restore them type \"git stash apply\")")"
ea41cfc4
JS
148 ;;
149 *)
683befa1 150 usage
ea41cfc4 151 esac
9f62e18a 152 ;;
f2c66ed1 153esac