X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-stash.sh;h=fa5a43e579f29a52e06295ca22fbc438b78e802c;hb=eed10649c2864168e6205057ce49101cc1123a13;hp=fbd4bc152d7fb0ba81f0dd5c999ffba3c2276108;hpb=0752000c2af829a1d220b9eb51b3fad331bc0038;p=git.git diff --git a/git-stash.sh b/git-stash.sh index fbd4bc152..fa5a43e57 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -14,6 +14,7 @@ SUBDIRECTORY_OK=Yes OPTIONS_SPEC= START_DIR=`pwd` . git-sh-setup +. git-sh-i18n require_work_tree cd_to_toplevel @@ -39,7 +40,7 @@ no_changes () { clear_stash () { if test $# != 0 then - die "git stash clear with parameters is unimplemented" + die "$(gettext "git stash clear with parameters is unimplemented")" fi if current=$(git rev-parse --verify $ref_stash 2>/dev/null) then @@ -61,7 +62,7 @@ create_stash () { then head=$(git rev-list --oneline -n 1 HEAD --) else - die "You do not have the initial commit yet" + die "$(gettext "You do not have the initial commit yet")" fi if branch=$(git symbolic-ref -q HEAD) @@ -76,7 +77,7 @@ create_stash () { i_tree=$(git write-tree) && i_commit=$(printf 'index on %s\n' "$msg" | git commit-tree $i_tree -p $b_commit) || - die "Cannot save the current index state" + die "$(gettext "Cannot save the current index state")" if test -z "$patch_mode" then @@ -90,7 +91,7 @@ create_stash () { git write-tree && rm -f "$TMPindex" ) ) || - die "Cannot save the current worktree state" + die "$(gettext "Cannot save the current worktree state")" else @@ -103,14 +104,14 @@ create_stash () { # state of the working tree w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) || - die "Cannot save the current worktree state" + die "$(gettext "Cannot save the current worktree state")" git diff-tree -p HEAD $w_tree > "$TMP-patch" && test -s "$TMP-patch" || - die "No changes selected" + die "$(gettext "No changes selected")" rm -f "$TMP-index" || - die "Cannot remove temporary index (can't happen)" + die "$(gettext "Cannot remove temporary index (can't happen)")" fi @@ -123,7 +124,7 @@ create_stash () { fi w_commit=$(printf '%s\n' "$stash_msg" | git commit-tree $w_tree -p $b_commit -p $i_commit) || - die "Cannot record working tree state" + die "$(gettext "Cannot record working tree state")" } save_stash () { @@ -136,11 +137,12 @@ save_stash () { keep_index=t ;; --no-keep-index) - keep_index= + keep_index=n ;; -p|--patch) patch_mode=t - keep_index=t + # only default to keep if we don't already have an override + test -z "$keep_index" && keep_index=t ;; -q|--quiet) GIT_QUIET=t @@ -150,8 +152,19 @@ save_stash () { break ;; -*) - echo "error: unknown option for 'stash save': $1" - echo " To provide a message, use git stash save -- '$1'" + option="$1" + # TRANSLATORS: $option is an invalid option, like + # `--blah-blah'. The 7 spaces at the beginning of the + # second line correspond to "error: ". So you should line + # up the second line with however many characters the + # translation of "error: " takes in your language. E.g. in + # English this is: + # + # $ git stash save --blah-blah 2>&1 | head -n 2 + # error: unknown option for 'stash save': --blah-blah + # To provide a message, use git stash save -- '--blah-blah' + eval_gettext "$("error: unknown option for 'stash save': \$option + To provide a message, use git stash save -- '\$option'")"; echo usage ;; *) @@ -166,11 +179,11 @@ save_stash () { git update-index -q --refresh if no_changes then - say 'No local changes to save' + say "$(gettext "No local changes to save")" exit 0 fi test -f "$GIT_DIR/logs/$ref_stash" || - clear_stash || die "Cannot initialize stash" + clear_stash || die "$(gettext "Cannot initialize stash")" create_stash "$stash_msg" @@ -178,22 +191,22 @@ save_stash () { : >>"$GIT_DIR/logs/$ref_stash" git update-ref -m "$stash_msg" $ref_stash $w_commit || - die "Cannot save the current status" + die "$(gettext "Cannot save the current status")" say Saved working directory and index state "$stash_msg" if test -z "$patch_mode" then git reset --hard ${GIT_QUIET:+-q} - if test -n "$keep_index" && test -n $i_tree + if test "$keep_index" = "t" && test -n $i_tree then git read-tree --reset -u $i_tree fi else git apply -R < "$TMP-patch" || - die "Cannot remove worktree changes" + die "$(gettext "Cannot remove worktree changes")" - if test -z "$keep_index" + if test "$keep_index" != "t" then git reset fi @@ -264,7 +277,7 @@ parse_flags_and_rev() b_tree= i_tree= - REV=$(git rev-parse --no-flags --symbolic "$@" 2>/dev/null) + REV=$(git rev-parse --no-flags --symbolic "$@") || exit 1 FLAGS= for opt @@ -286,18 +299,21 @@ parse_flags_and_rev() case $# in 0) - have_stash || die "No stash found." + have_stash || die "$(gettext "No stash found.")" set -- ${ref_stash}@{0} ;; 1) : ;; *) - die "Too many revisions specified: $REV" + die "$(eval_gettext "Too many revisions specified: \$REV")" ;; esac - REV=$(git rev-parse --quiet --symbolic --verify $1 2>/dev/null) || die "$1 is not valid reference" + REV=$(git rev-parse --quiet --symbolic --verify $1 2>/dev/null) || { + reference="$1" + die "$(eval_gettext "\$reference is not valid reference")" + } i_commit=$(git rev-parse --quiet --verify $REV^2 2>/dev/null) && set -- $(git rev-parse $REV $REV^1 $REV: $REV^1: $REV^2: 2>/dev/null) && @@ -310,16 +326,6 @@ parse_flags_and_rev() IS_STASH_LIKE=t && test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" && IS_STASH_REF=t - - if test "${REV}" != "${REV%{*\}}" - then - # maintainers: it would be better if git rev-parse indicated - # this condition with a non-zero status code but as of 1.7.2.1 it - # it did not. So, we use non-empty stderr output as a proxy for the - # condition of interest. - test -z "$(git rev-parse "$REV" 2>&1 >/dev/null)" || die "$REV does not exist in the stash log" - fi - } is_stash_like() @@ -329,7 +335,10 @@ is_stash_like() } assert_stash_like() { - is_stash_like "$@" || die "'$*' is not a stash-like commit" + is_stash_like "$@" || { + args="$*" + die "$(eval_gettext "'\$args' is not a stash-like commit")" + } } is_stash_ref() { @@ -337,18 +346,21 @@ is_stash_ref() { } assert_stash_ref() { - is_stash_ref "$@" || die "'$*' is not a stash reference" + is_stash_ref "$@" || { + args="$*" + die "$(eval_gettext "'\$args' is not a stash reference")" + } } apply_stash () { assert_stash_like "$@" - git update-index -q --refresh || die 'unable to refresh index' + git update-index -q --refresh || die "$(gettext "unable to refresh index")" # current index state c_tree=$(git write-tree) || - die 'Cannot apply a stash in the middle of a merge' + die "$(gettext "Cannot apply a stash in the middle of a merge")" unstashed_index_tree= if test -n "$INDEX_OPTION" && test "$b_tree" != "$i_tree" && @@ -356,9 +368,9 @@ apply_stash () { then git diff-tree --binary $s^2^..$s^2 | git apply --cached test $? -ne 0 && - die 'Conflicts in index. Try without --index.' + die "$(gettext "Conflicts in index. Try without --index.")" unstashed_index_tree=$(git write-tree) || - die 'Could not save index tree' + die "$(gettext "Could not save index tree")" git reset fi @@ -384,7 +396,7 @@ apply_stash () { git diff-index --cached --name-only --diff-filter=A $c_tree >"$a" && git read-tree --reset $c_tree && git update-index --add --stdin <"$a" || - die "Cannot unstage modified files" + die "$(gettext "Cannot unstage modified files")" rm -f "$a" fi squelch= @@ -398,7 +410,10 @@ apply_stash () { status=$? if test -n "$INDEX_OPTION" then - echo >&2 'Index was not unstashed.' + ( + gettext "Index was not unstashed." && + echo + ) >&2 fi exit $status fi @@ -422,7 +437,7 @@ drop_stash () { } apply_to_branch () { - test -n "$1" || die 'No branch name specified' + test -n "$1" || die "$(gettext "No branch name specified")" branch=$1 shift 1 @@ -493,7 +508,7 @@ branch) case $# in 0) save_stash && - say '(To restore them type "git stash apply")' + say "$(gettext "(To restore them type \"git stash apply\")")" ;; *) usage