Skip to content

Commit cbf0339

Browse files
committed
Merge branch 'tg/stash-untracked-with-pathspec-fix'
"git stash push -u -- <pathspec>" gave an unnecessary and confusing error message when there was no tracked files that match the <pathspec>, which has been fixed. * tg/stash-untracked-with-pathspec-fix: stash: drop superfluos pathspec parameter stash push -u: don't create empty stash stash push: avoid printing errors stash: fix nonsense pipeline
2 parents ca923f7 + 3532786 commit cbf0339

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

git-stash.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fi
3939
no_changes () {
4040
git diff-index --quiet --cached HEAD --ignore-submodules -- "$@" &&
4141
git diff-files --quiet --ignore-submodules -- "$@" &&
42-
(test -z "$untracked" || test -z "$(untracked_files)")
42+
(test -z "$untracked" || test -z "$(untracked_files "$@")")
4343
}
4444

4545
untracked_files () {
@@ -315,16 +315,18 @@ push_stash () {
315315
if test -z "$patch_mode"
316316
then
317317
test "$untracked" = "all" && CLEAN_X_OPTION=-x || CLEAN_X_OPTION=
318-
if test -n "$untracked"
318+
if test -n "$untracked" && test $# = 0
319319
then
320-
git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
320+
git clean --force --quiet -d $CLEAN_X_OPTION
321321
fi
322322

323323
if test $# != 0
324324
then
325-
git add -u -- "$@" |
326-
git checkout-index -z --force --stdin
327-
git diff-index -p --cached --binary HEAD -- "$@" | git apply --index -R
325+
test -z "$untracked" && UPDATE_OPTION="-u" || UPDATE_OPTION=
326+
test "$untracked" = "all" && FORCE_OPTION="--force" || FORCE_OPTION=
327+
git add $UPDATE_OPTION $FORCE_OPTION -- "$@"
328+
git diff-index -p --cached --binary HEAD -- "$@" |
329+
git apply --index -R
328330
else
329331
git reset --hard -q
330332
fi

t/t3905-stash-include-untracked.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,56 @@ test_expect_success 'stash previously ignored file' '
228228
test_path_is_file ignored.d/foo
229229
'
230230

231+
test_expect_success 'stash -u -- <untracked> doesnt print error' '
232+
>untracked &&
233+
git stash push -u -- untracked 2>actual &&
234+
test_path_is_missing untracked &&
235+
test_line_count = 0 actual
236+
'
237+
238+
test_expect_success 'stash -u -- <untracked> leaves rest of working tree in place' '
239+
>tracked &&
240+
git add tracked &&
241+
>untracked &&
242+
git stash push -u -- untracked &&
243+
test_path_is_missing untracked &&
244+
test_path_is_file tracked
245+
'
246+
247+
test_expect_success 'stash -u -- <tracked> <untracked> clears changes in both' '
248+
>tracked &&
249+
git add tracked &&
250+
>untracked &&
251+
git stash push -u -- tracked untracked &&
252+
test_path_is_missing tracked &&
253+
test_path_is_missing untracked
254+
'
255+
256+
test_expect_success 'stash --all -- <ignored> stashes ignored file' '
257+
>ignored.d/bar &&
258+
git stash push --all -- ignored.d/bar &&
259+
test_path_is_missing ignored.d/bar
260+
'
261+
262+
test_expect_success 'stash --all -- <tracked> <ignored> clears changes in both' '
263+
>tracked &&
264+
git add tracked &&
265+
>ignored.d/bar &&
266+
git stash push --all -- tracked ignored.d/bar &&
267+
test_path_is_missing tracked &&
268+
test_path_is_missing ignored.d/bar
269+
'
270+
271+
test_expect_success 'stash -u -- <ignored> leaves ignored file alone' '
272+
>ignored.d/bar &&
273+
git stash push -u -- ignored.d/bar &&
274+
test_path_is_file ignored.d/bar
275+
'
276+
277+
test_expect_success 'stash -u -- <non-existant> shows no changes when there are none' '
278+
git stash push -u -- non-existant >actual &&
279+
echo "No local changes to save" >expect &&
280+
test_i18ncmp expect actual
281+
'
282+
231283
test_done

0 commit comments

Comments
 (0)