Git fork
at reftables-rust 129 lines 3.5 kB view raw
1#!/bin/sh 2 3test_description='stash -p' 4 5. ./lib-patch-mode.sh 6 7test_expect_success 'setup' ' 8 mkdir dir && 9 echo parent > dir/foo && 10 echo dummy > bar && 11 echo committed > HEAD && 12 git add bar dir/foo HEAD && 13 git commit -m initial && 14 test_tick && 15 test_commit second dir/foo head && 16 echo index > dir/foo && 17 git add dir/foo && 18 set_and_save_state bar bar_work bar_index && 19 save_head 20' 21 22# note: order of files with unstaged changes: HEAD bar dir/foo 23 24test_expect_success 'saying "n" does nothing' ' 25 set_state HEAD HEADfile_work HEADfile_index && 26 set_state dir/foo work index && 27 test_write_lines n n n | test_must_fail git stash save -p && 28 verify_state HEAD HEADfile_work HEADfile_index && 29 verify_saved_state bar && 30 verify_state dir/foo work index 31' 32 33test_expect_success 'git stash -p' ' 34 test_write_lines y n y | git stash save -p && 35 verify_state HEAD committed HEADfile_index && 36 verify_saved_state bar && 37 verify_state dir/foo head index && 38 git reset --hard && 39 git stash apply && 40 verify_state HEAD HEADfile_work committed && 41 verify_state bar dummy dummy && 42 verify_state dir/foo work head 43' 44 45test_expect_success 'git stash -p --no-keep-index' ' 46 set_state HEAD HEADfile_work HEADfile_index && 47 set_state bar bar_work bar_index && 48 set_state dir/foo work index && 49 test_write_lines y n y | git stash save -p --no-keep-index && 50 verify_state HEAD committed committed && 51 verify_state bar bar_work dummy && 52 verify_state dir/foo head head && 53 git reset --hard && 54 git stash apply --index && 55 verify_state HEAD HEADfile_work HEADfile_index && 56 verify_state bar dummy bar_index && 57 verify_state dir/foo work index 58' 59 60test_expect_success 'git stash --no-keep-index -p' ' 61 set_state HEAD HEADfile_work HEADfile_index && 62 set_state bar bar_work bar_index && 63 set_state dir/foo work index && 64 test_write_lines y n y | git stash save --no-keep-index -p && 65 verify_state HEAD committed committed && 66 verify_state dir/foo head head && 67 verify_state bar bar_work dummy && 68 git reset --hard && 69 git stash apply --index && 70 verify_state HEAD HEADfile_work HEADfile_index && 71 verify_state bar dummy bar_index && 72 verify_state dir/foo work index 73' 74 75test_expect_success 'stash -p --no-keep-index -- <pathspec> does not unstage other files' ' 76 set_state HEAD HEADfile_work HEADfile_index && 77 set_state dir/foo work index && 78 echo y | git stash push -p --no-keep-index -- HEAD && 79 verify_state HEAD committed committed && 80 verify_state dir/foo work index 81' 82 83test_expect_success 'none of this moved HEAD' ' 84 verify_saved_head 85' 86 87test_expect_success 'stash -p with split hunk' ' 88 git reset --hard && 89 cat >test <<-\EOF && 90 aaa 91 bbb 92 ccc 93 EOF 94 git add test && 95 git commit -m "initial" && 96 cat >test <<-\EOF && 97 aaa 98 added line 1 99 bbb 100 added line 2 101 ccc 102 EOF 103 printf "%s\n" s n y q | 104 git stash -p 2>error && 105 test_must_be_empty error && 106 grep "added line 1" test && 107 ! grep "added line 2" test 108' 109 110test_expect_success 'stash -p not confused by GIT_PAGER_IN_USE' ' 111 echo to-stash >test && 112 # Set both GIT_PAGER_IN_USE and TERM. Our goal is to entice any 113 # diff subprocesses into thinking that they could output 114 # color, even though their stdout is not going into a tty. 115 echo y | 116 GIT_PAGER_IN_USE=1 TERM=vt100 git stash -p && 117 git diff --exit-code 118' 119 120test_expect_success 'index push not confused by GIT_PAGER_IN_USE' ' 121 echo index >test && 122 git add test && 123 echo working-tree >test && 124 # As above, we try to entice the child diff into using color. 125 GIT_PAGER_IN_USE=1 TERM=vt100 git stash push test && 126 git diff --exit-code 127' 128 129test_done