mirror of
https://github.com/git/git.git
synced 2024-11-28 20:44:04 +08:00
stash push: avoid printing errors
'git stash push -u -- <pathspec>' prints the following errors if <pathspec> only matches untracked files: fatal: pathspec 'untracked' did not match any files error: unrecognized input This is because we first clean up the untracked files using 'git clean <pathspec>', and then use a command chain involving 'git add -u <pathspec>' and 'git apply' to clear the changes to files that are in the index and were stashed. As the <pathspec> only includes untracked files that were already removed by 'git clean', the 'git add' call will barf, and so will 'git apply', as there are no changes that need to be applied. Fix this by avoiding the 'git clean' if a pathspec is given, and use the pipeline that's used for pathspec mode to get rid of the untracked files as well. Reported-by: Marc Strapetz <marc.strapetz@syntevo.com> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
d97e4fa748
commit
833622a945
@ -308,14 +308,16 @@ push_stash () {
|
||||
if test -z "$patch_mode"
|
||||
then
|
||||
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
|
||||
if test -n "$untracked"
|
||||
if test -n "$untracked" && test $# = 0
|
||||
then
|
||||
git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
|
||||
fi
|
||||
|
||||
if test $# != 0
|
||||
then
|
||||
git add -u -- "$@"
|
||||
test -z "$untracked" && UPDATE_OPTION="-u" || UPDATE_OPTION=
|
||||
test "$untracked" = "all" && FORCE_OPTION="--force" || FORCE_OPTION=
|
||||
git add $UPDATE_OPTION $FORCE_OPTION -- "$@"
|
||||
git diff-index -p --cached --binary HEAD -- "$@" |
|
||||
git apply --index -R
|
||||
else
|
||||
|
@ -228,4 +228,50 @@ test_expect_success 'stash previously ignored file' '
|
||||
test_path_is_file ignored.d/foo
|
||||
'
|
||||
|
||||
test_expect_success 'stash -u -- <untracked> doesnt print error' '
|
||||
>untracked &&
|
||||
git stash push -u -- untracked 2>actual &&
|
||||
test_path_is_missing untracked &&
|
||||
test_line_count = 0 actual
|
||||
'
|
||||
|
||||
test_expect_success 'stash -u -- <untracked> leaves rest of working tree in place' '
|
||||
>tracked &&
|
||||
git add tracked &&
|
||||
>untracked &&
|
||||
git stash push -u -- untracked &&
|
||||
test_path_is_missing untracked &&
|
||||
test_path_is_file tracked
|
||||
'
|
||||
|
||||
test_expect_success 'stash -u -- <tracked> <untracked> clears changes in both' '
|
||||
>tracked &&
|
||||
git add tracked &&
|
||||
>untracked &&
|
||||
git stash push -u -- tracked untracked &&
|
||||
test_path_is_missing tracked &&
|
||||
test_path_is_missing untracked
|
||||
'
|
||||
|
||||
test_expect_success 'stash --all -- <ignored> stashes ignored file' '
|
||||
>ignored.d/bar &&
|
||||
git stash push --all -- ignored.d/bar &&
|
||||
test_path_is_missing ignored.d/bar
|
||||
'
|
||||
|
||||
test_expect_success 'stash --all -- <tracked> <ignored> clears changes in both' '
|
||||
>tracked &&
|
||||
git add tracked &&
|
||||
>ignored.d/bar &&
|
||||
git stash push --all -- tracked ignored.d/bar &&
|
||||
test_path_is_missing tracked &&
|
||||
test_path_is_missing ignored.d/bar
|
||||
'
|
||||
|
||||
test_expect_success 'stash -u -- <ignored> leaves ignored file alone' '
|
||||
>ignored.d/bar &&
|
||||
git stash push -u -- ignored.d/bar &&
|
||||
test_path_is_file ignored.d/bar
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user