diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-07-11 13:05:52 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-07-11 13:05:52 -0700 |
commit | d26792ad69c0d2ea0b197656ae9a562e2c1f900e (patch) | |
tree | 06b8527f68bc9705bc6fe979f9c3f75ab2bb5e05 /git-stash.sh | |
parent | Merge branch 'jc/maint-diff-core-safecrlf' (diff) | |
parent | git stash: avoid data loss when "git stash save" kills a directory (diff) | |
download | tgif-d26792ad69c0d2ea0b197656ae9a562e2c1f900e.tar.xz |
Merge branch 'pb/stash-refuse-to-kill'
"git stash save" is not just about "saving" the local changes, but
also is to restore the working tree state to that of HEAD. If you
changed a non-directory into a directory in the local change, you
may have untracked files in that directory, which have to be killed
while doing so, unless you run it with --include-untracked. Teach
the command to detect and error out before spreading the damage.
This needed a small fix to "ls-files --killed".
* pb/stash-refuse-to-kill:
git stash: avoid data loss when "git stash save" kills a directory
treat_directory(): do not declare submodules to be untracked
Diffstat (limited to 'git-stash.sh')
-rwxr-xr-x | git-stash.sh | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/git-stash.sh b/git-stash.sh index 1e541a2125..85c9e2c081 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -195,6 +195,7 @@ save_stash () { keep_index= patch_mode= untracked= + force= while test $# != 0 do case "$1" in @@ -215,6 +216,9 @@ save_stash () { -u|--include-untracked) untracked=untracked ;; + -f|--force) + force=t + ;; -a|--all) untracked=all ;; @@ -258,6 +262,14 @@ save_stash () { say "$(gettext "No local changes to save")" exit 0 fi + if test -z "$untracked$force" && + test -n "$(git ls-files --killed | head -n 1)" + then + say "$(gettext "The following untracked files would NOT be saved but need to be removed by stash save:")" + test -n "$GIT_QUIET" || git ls-files --killed | sed 's/^/\t/' + say "$(gettext "Aborting. Consider using either the --force or --include-untracked option.")" >&2 + exit 1 + fi test -f "$GIT_DIR/logs/$ref_stash" || clear_stash || die "$(gettext "Cannot initialize stash")" |