Imported Upstream version 2.20.4
[platform/upstream/git.git] / t / t3904-stash-patch.sh
index 70655c1..9546b6f 100755 (executable)
@@ -1,9 +1,15 @@
 #!/bin/sh
 
-test_description='git checkout --patch'
+test_description='stash -p'
 . ./lib-patch-mode.sh
 
-test_expect_success PERL 'setup' '
+if ! test_have_prereq PERL
+then
+       skip_all='skipping stash -p tests, perl not available'
+       test_done
+fi
+
+test_expect_success 'setup' '
        mkdir dir &&
        echo parent > dir/foo &&
        echo dummy > bar &&
@@ -20,17 +26,17 @@ test_expect_success PERL 'setup' '
 
 # note: order of files with unstaged changes: HEAD bar dir/foo
 
-test_expect_success PERL 'saying "n" does nothing' '
+test_expect_success 'saying "n" does nothing' '
        set_state HEAD HEADfile_work HEADfile_index &&
        set_state dir/foo work index &&
-       (echo n; echo n; echo n) | test_must_fail git stash save -p &&
+       test_write_lines n n n | test_must_fail git stash save -p &&
        verify_state HEAD HEADfile_work HEADfile_index &&
        verify_saved_state bar &&
        verify_state dir/foo work index
 '
 
-test_expect_success PERL 'git stash -p' '
-       (echo y; echo n; echo y) | git stash save -p &&
+test_expect_success 'git stash -p' '
+       test_write_lines y n y | git stash save -p &&
        verify_state HEAD committed HEADfile_index &&
        verify_saved_state bar &&
        verify_state dir/foo head index &&
@@ -41,11 +47,11 @@ test_expect_success PERL 'git stash -p' '
        verify_state dir/foo work head
 '
 
-test_expect_success PERL 'git stash -p --no-keep-index' '
+test_expect_success 'git stash -p --no-keep-index' '
        set_state HEAD HEADfile_work HEADfile_index &&
        set_state bar bar_work bar_index &&
        set_state dir/foo work index &&
-       (echo y; echo n; echo y) | git stash save -p --no-keep-index &&
+       test_write_lines y n y | git stash save -p --no-keep-index &&
        verify_state HEAD committed committed &&
        verify_state bar bar_work dummy &&
        verify_state dir/foo head head &&
@@ -56,11 +62,11 @@ test_expect_success PERL 'git stash -p --no-keep-index' '
        verify_state dir/foo work index
 '
 
-test_expect_success PERL 'git stash --no-keep-index -p' '
+test_expect_success 'git stash --no-keep-index -p' '
        set_state HEAD HEADfile_work HEADfile_index &&
        set_state bar bar_work bar_index &&
        set_state dir/foo work index &&
-       (echo y; echo n; echo y) | git stash save --no-keep-index -p &&
+       test_write_lines y n y | git stash save --no-keep-index -p &&
        verify_state HEAD committed committed &&
        verify_state dir/foo head head &&
        verify_state bar bar_work dummy &&
@@ -71,8 +77,39 @@ test_expect_success PERL 'git stash --no-keep-index -p' '
        verify_state dir/foo work index
 '
 
-test_expect_success PERL 'none of this moved HEAD' '
+test_expect_success 'stash -p --no-keep-index -- <pathspec> does not unstage other files' '
+       set_state HEAD HEADfile_work HEADfile_index &&
+       set_state dir/foo work index &&
+       echo y | git stash push -p --no-keep-index -- HEAD &&
+       verify_state HEAD committed committed &&
+       verify_state dir/foo work index
+'
+
+test_expect_success 'none of this moved HEAD' '
        verify_saved_head
 '
 
+test_expect_failure 'stash -p with split hunk' '
+       git reset --hard &&
+       cat >test <<-\EOF &&
+       aaa
+       bbb
+       ccc
+       EOF
+       git add test &&
+       git commit -m "initial" &&
+       cat >test <<-\EOF &&
+       aaa
+       added line 1
+       bbb
+       added line 2
+       ccc
+       EOF
+       printf "%s\n" s n y q |
+       test_might_fail git stash -p 2>error &&
+       ! test_must_be_empty error &&
+       grep "added line 1" test &&
+       ! grep "added line 2" test
+'
+
 test_done