Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t2071-restore-patch.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t2071-restore-patch.sh` 122 lines ยท 3479 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git restore --patch' 4 5 . ./lib-patch-mode.sh 6 7 test_expect_success 'setup' ' 8 mkdir dir && 9 echo parent >dir/foo && 10 echo dummy >bar && 11 git add bar dir/foo && 12 git commit -m initial && 13 test_tick && 14 test_commit second dir/foo head && 15 set_and_save_state bar bar_work bar_index && 16 save_head 17 ' 18 19 test_expect_success 'restore -p without pathspec is fine' ' 20 echo q >cmd && 21 git restore -p output && 53 verify_saved_state bar && 54 verify_state dir/foo head index && 55 test_grep "Discard" output 56 ' 57 done 58 59 test_expect_success 'git restore -p --source=HEAD^' ' 60 set_state dir/foo work index && 61 # the third n is to get out in case it mistakenly does not apply 62 test_write_lines n y n | git restore -p --source=HEAD^ && 63 verify_saved_state bar && 64 verify_state dir/foo parent index 65 ' 66 67 test_expect_success 'git restore -p --source=HEAD^...' ' 68 set_state dir/foo work index && 69 # the third n is to get out in case it mistakenly does not apply 70 test_write_lines n y n | git restore -p --source=HEAD^... && 71 verify_saved_state bar && 72 verify_state dir/foo parent index 73 ' 74 75 test_expect_success 'git restore -p handles deletion' ' 76 set_state dir/foo work index && 77 rm dir/foo && 78 test_write_lines n y | git restore -p && 79 verify_saved_state bar && 80 verify_state dir/foo index index 81 ' 82 83 # The idea in the rest is that bar sorts first, so we always say 'y' 84 # first and if the path limiter fails it'll apply to bar instead of 85 # dir/foo. There's always an extra 'n' to reject edits to dir/foo in 86 # the failure case (and thus get out of the loop). 87 88 test_expect_success 'path limiting works: dir' ' 89 set_state dir/foo work head && 90 test_write_lines y n | git restore -p dir && 91 verify_saved_state bar && 92 verify_state dir/foo head head 93 ' 94 95 test_expect_success 'path limiting works: -- dir' ' 96 set_state dir/foo work head && 97 test_write_lines y n | git restore -p -- dir && 98 verify_saved_state bar && 99 verify_state dir/foo head head 100 ' 101 102 test_expect_success 'path limiting works: HEAD^ -- dir' ' 103 set_state dir/foo work head && 104 # the third n is to get out in case it mistakenly does not apply 105 test_write_lines y n n | git restore -p --source=HEAD^ -- dir && 106 verify_saved_state bar && 107 verify_state dir/foo parent head 108 ' 109 110 test_expect_success 'path limiting works: foo inside dir' ' 111 set_state dir/foo work head && 112 # the third n is to get out in case it mistakenly does not apply 113 test_write_lines y n n | (cd dir && git restore -p foo) && 114 verify_saved_state bar && 115 verify_state dir/foo head head 116 ' 117 118 test_expect_success 'none of this moved HEAD' ' 119 verify_saved_head 120 ' 121 122 test_done