stash: teach 'push' (and 'create_stash') to honor pathspec
While working on a repository, it's often helpful to stash the changes
of a single or multiple files, and leave others alone. Unfortunately
git currently offers no such option. git stash -p can be used to work
around this, but it's often impractical when there are a lot of changes
over multiple files.
Allow 'git stash push' to take pathspec to specify which paths to stash.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Thomas Gummerer8 years agocommitted byJunio C Hamano
@ -802,4 +802,96 @@ test_expect_success 'create with multiple arguments for the message' '
@@ -802,4 +802,96 @@ test_expect_success 'create with multiple arguments for the message' '
test_cmp expect actual
'
test_expect_success 'stash -- <pathspec> stashes and restores the file' '
>foo &&
>bar &&
git add foo bar &&
git stash push -- foo &&
test_path_is_file bar &&
test_path_is_missing foo &&
git stash pop &&
test_path_is_file foo &&
test_path_is_file bar
'
test_expect_success 'stash with multiple pathspec arguments' '
>foo &&
>bar &&
>extra &&
git add foo bar extra &&
git stash push -- foo bar &&
test_path_is_missing bar &&
test_path_is_missing foo &&
test_path_is_file extra &&
git stash pop &&
test_path_is_file foo &&
test_path_is_file bar &&
test_path_is_file extra
'
test_expect_success 'stash with file including $IFS character' '
>"foo bar" &&
>foo &&
>bar &&
git add foo* &&
git stash push -- "foo b*" &&
test_path_is_missing "foo bar" &&
test_path_is_file foo &&
test_path_is_file bar &&
git stash pop &&
test_path_is_file "foo bar" &&
test_path_is_file foo &&
test_path_is_file bar
'
test_expect_success 'stash with pathspec matching multiple paths' '
echo original >file &&
echo original >other-file &&
git commit -m "two" file other-file &&
echo modified >file &&
echo modified >other-file &&
git stash push -- "*file" &&
echo original >expect &&
test_cmp expect file &&
test_cmp expect other-file &&
git stash pop &&
echo modified >expect &&
test_cmp expect file &&
test_cmp expect other-file
'
test_expect_success 'stash push -p with pathspec shows no changes only once' '
>foo &&
git add foo &&
git commit -m "tmp" &&
git stash push -p foo >actual &&
echo "No local changes to save" >expect &&
git reset --hard HEAD~ &&
test_cmp expect actual
'
test_expect_success 'stash push with pathspec shows no changes when there are none' '
>foo &&
git add foo &&
git commit -m "tmp" &&
git stash push foo >actual &&
echo "No local changes to save" >expect &&
git reset --hard HEAD~ &&
test_cmp expect actual
'
test_expect_success 'stash push with pathspec not in the repository errors out' '
>untracked &&
test_must_fail git stash push untracked &&
test_path_is_file untracked
'
test_expect_success 'untracked files are left in place when -u is not given' '