Skip to content

Commit d319bb1

Browse files
tgummerergitster
authored andcommitted
stash push -u: don't create empty stash
When introducing the stash push feature, and thus allowing users to pass in a pathspec to limit the files that would get stashed in df6bba0 ("stash: teach 'push' (and 'create_stash') to honor pathspec", 2017-02-28), this developer missed one place where the pathspec should be passed in. Namely in the call to the 'untracked_files()' function in the 'no_changes()' function. This resulted in 'git stash push -u -- <non-existant>' creating an empty stash when there are untracked files in the repository other that don't match the pathspec. As 'git stash' never creates empty stashes, this behaviour is wrong and confusing for users. Instead it should just show a message "No local changes to save", and not create a stash. Luckily the 'untracked_files()' function already correctly respects pathspecs that are passed to it, so the fix is simply to pass the pathspec along to the function. Reported-by: Marc Strapetz <[email protected]> Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 833622a commit d319bb1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

git-stash.sh

Lines changed: 1 addition & 1 deletion
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 () {

t/t3905-stash-include-untracked.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,10 @@ test_expect_success 'stash -u -- <ignored> leaves ignored file alone' '
274274
test_path_is_file ignored.d/bar
275275
'
276276

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+
277283
test_done

0 commit comments

Comments
 (0)