From: Junio C Hamano Date: Mon, 1 Jun 2015 19:45:14 +0000 (-0700) Subject: Merge branch 'jk/stash-options' X-Git-Tag: v2.5.0-rc0~64 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f693bb0bb0d18d6150d6059dfad5018501a9713a?ds=inline;hp=-c Merge branch 'jk/stash-options' Make "git stash something --help" error out, so that users can safely say "git stash drop --help". * jk/stash-options: stash: recognize "--help" for subcommands stash: complain about unknown flags --- f693bb0bb0d18d6150d6059dfad5018501a9713a diff --combined git-stash.sh index 7911f30c63,23bd1d3db2..1f5ea877d7 --- a/git-stash.sh +++ b/git-stash.sh @@@ -20,7 -20,7 +20,7 @@@ require_work_tre cd_to_toplevel TMP="$GIT_DIR/.git-stash.$$" -TMPindex=${GIT_INDEX_FILE-"$GIT_DIR/index"}.stash.$$ +TMPindex=${GIT_INDEX_FILE-"$(git rev-parse --git-path index)"}.stash.$$ trap 'rm -f "$TMP-"* "$TMPindex"' 0 ref_stash=refs/stash @@@ -184,7 -184,7 +184,7 @@@ store_stash () fi # Make sure the reflog for stash is kept. - : >>"$GIT_DIR/logs/$ref_stash" + : >>"$(git rev-parse --git-path logs/$ref_stash)" git update-ref -m "$stash_msg" $ref_stash $w_commit ret=$? test $ret != 0 && test -z $quiet && @@@ -219,6 -219,9 +219,9 @@@ save_stash () -a|--all) untracked=all ;; + --help) + show_help + ;; --) shift break @@@ -259,7 -262,7 +262,7 @@@ say "$(gettext "No local changes to save")" exit 0 fi - test -f "$GIT_DIR/logs/$ref_stash" || + test -f "$(git rev-parse --git-path logs/$ref_stash)" || clear_stash || die "$(gettext "Cannot initialize stash")" create_stash "$stash_msg" $untracked @@@ -301,11 -304,17 +304,17 @@@ list_stash () } show_stash () { + ALLOW_UNKNOWN_FLAGS=t assert_stash_like "$@" git diff ${FLAGS:---stat} $b_commit $w_commit } + show_help () { + exec git help stash + exit 1 + } + # # Parses the remaining options looking for flags and # at most one revision defaulting to ${ref_stash}@{0} @@@ -332,13 -341,14 +341,14 @@@ # # GIT_QUIET is set to t if -q is specified # INDEX_OPTION is set to --index if --index is specified. - # FLAGS is set to the remaining flags + # FLAGS is set to the remaining flags (if allowed) # # dies if: # * too many revisions specified # * no revision is specified and there is no stash stack # * a revision is specified which cannot be resolve to a SHA1 # * a non-existent stash reference is specified + # * unknown flags were set and ALLOW_UNKNOWN_FLAGS is not "t" # parse_flags_and_rev() @@@ -371,7 -381,12 +381,12 @@@ --index) INDEX_OPTION=--index ;; + --help) + show_help + ;; -*) + test "$ALLOW_UNKNOWN_FLAGS" = t || + die "$(eval_gettext "unknown option: \$opt")" FLAGS="${FLAGS}${FLAGS:+ }$opt" ;; esac @@@ -442,8 -457,6 +457,8 @@@ apply_stash () assert_stash_like "$@" git update-index -q --refresh || die "$(gettext "unable to refresh index")" + git diff-index --cached --quiet --ignore-submodules HEAD -- || + die "$(gettext "Cannot apply stash: Your index contains uncommitted changes.")" # current index state c_tree=$(git write-tree) || diff --combined t/t3903-stash.sh index 0746eeeff7,384678953e..7396ca9911 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@@ -10,8 -10,6 +10,8 @@@ test_description='Test git stash test_expect_success 'stash some dirty working directory' ' echo 1 > file && git add file && + echo unrelated >other-file && + git add other-file && test_tick && git commit -m initial && echo 2 > file && @@@ -45,15 -43,10 +45,15 @@@ test_expect_success 'applying bogus sta test_cmp expect file ' +test_expect_success 'apply requires a clean index' ' + test_when_finished "git reset --hard" && + echo changed >other-file && + git add other-file && + test_must_fail git stash apply +' + test_expect_success 'apply does not need clean working directory' ' echo 4 >other-file && - git add other-file && - echo 5 >other-file && git stash apply && echo 3 >expect && test_cmp expect file @@@ -100,6 -93,10 +100,10 @@@ test_expect_success 'unstashing in a su ) ' + test_expect_success 'stash drop complains of extra options' ' + test_must_fail git stash drop --foo + ' + test_expect_success 'drop top stash' ' git reset --hard && git stash list > stashlist1 && @@@ -702,8 -699,8 +706,8 @@@ test_expect_success 'setup stash with i ' test_expect_success 'stash list implies --first-parent -m' ' - cat >expect <<-\EOF && - stash@{0}: WIP on master: b27a2bc subdir + cat >expect <<-EOF && + stash@{0} diff --git a/file b/file index 257cc56..d26b33d 100644 @@@ -713,13 -710,13 +717,13 @@@ -foo +working EOF - git stash list -p >actual && + git stash list --format=%gd -p >actual && test_cmp expect actual ' test_expect_success 'stash list --cc shows combined diff' ' cat >expect <<-\EOF && - stash@{0}: WIP on master: b27a2bc subdir + stash@{0} diff --cc file index 257cc56,9015a7a..d26b33d @@@ -730,7 -727,7 +734,7 @@@ -index ++working EOF - git stash list -p --cc >actual && + git stash list --format=%gd -p --cc >actual && test_cmp expect actual '