MinGW: 64-bit file offsets
[git/platforms.git] / t / t3701-add-interactive.sh
blobe95663d8e66d5b94e574a6b956625fccfd341a05
1 #!/bin/sh
3 test_description='add -i basic tests'
4 . ./test-lib.sh
6 test_expect_success 'setup (initial)' '
7 echo content >file &&
8 git add file &&
9 echo more >>file &&
10 echo lines >>file
12 test_expect_success 'status works (initial)' '
13 git add -i </dev/null >output &&
14 grep "+1/-0 *+2/-0 file" output
16 cat >expected <<EOF
17 new file mode 100644
18 index 0000000..d95f3ad
19 --- /dev/null
20 +++ b/file
21 @@ -0,0 +1 @@
22 +content
23 EOF
24 test_expect_success 'diff works (initial)' '
25 (echo d; echo 1) | git add -i >output &&
26 sed -ne "/new file/,/content/p" <output >diff &&
27 test_cmp expected diff
29 test_expect_success 'revert works (initial)' '
30 git add file &&
31 (echo r; echo 1) | git add -i &&
32 git ls-files >output &&
33 ! grep . output
36 test_expect_success 'setup (commit)' '
37 echo baseline >file &&
38 git add file &&
39 git commit -m commit &&
40 echo content >>file &&
41 git add file &&
42 echo more >>file &&
43 echo lines >>file
45 test_expect_success 'status works (commit)' '
46 git add -i </dev/null >output &&
47 grep "+1/-0 *+2/-0 file" output
49 cat >expected <<EOF
50 index 180b47c..b6f2c08 100644
51 --- a/file
52 +++ b/file
53 @@ -1 +1,2 @@
54 baseline
55 +content
56 EOF
57 test_expect_success 'diff works (commit)' '
58 (echo d; echo 1) | git add -i >output &&
59 sed -ne "/^index/,/content/p" <output >diff &&
60 test_cmp expected diff
62 test_expect_success 'revert works (commit)' '
63 git add file &&
64 (echo r; echo 1) | git add -i &&
65 git add -i </dev/null >output &&
66 grep "unchanged *+3/-0 file" output
69 cat >expected <<EOF
70 EOF
71 cat >fake_editor.sh <<EOF
72 EOF
73 chmod a+x fake_editor.sh
74 test_set_editor "$(pwd)/fake_editor.sh"
75 test_expect_success 'dummy edit works' '
76 (echo e; echo a) | git add -p &&
77 git diff > diff &&
78 test_cmp expected diff
81 cat >patch <<EOF
82 @@ -1,1 +1,4 @@
83 this
84 +patch
85 -doesn't
86 apply
87 EOF
88 echo "#!$SHELL_PATH" >fake_editor.sh
89 cat >>fake_editor.sh <<\EOF
90 mv -f "$1" oldpatch &&
91 mv -f patch "$1"
92 EOF
93 chmod a+x fake_editor.sh
94 test_set_editor "$(pwd)/fake_editor.sh"
95 test_expect_success 'bad edit rejected' '
96 git reset &&
97 (echo e; echo n; echo d) | git add -p >output &&
98 grep "hunk does not apply" output
101 cat >patch <<EOF
102 this patch
103 is garbage
105 test_expect_success 'garbage edit rejected' '
106 git reset &&
107 (echo e; echo n; echo d) | git add -p >output &&
108 grep "hunk does not apply" output
111 cat >patch <<EOF
112 @@ -1,0 +1,0 @@
113 baseline
114 +content
115 +newcontent
116 +lines
118 cat >expected <<EOF
119 diff --git a/file b/file
120 index b5dd6c9..f910ae9 100644
121 --- a/file
122 +++ b/file
123 @@ -1,4 +1,4 @@
124 baseline
125 content
126 -newcontent
127 +more
128 lines
130 test_expect_success 'real edit works' '
131 (echo e; echo n; echo d) | git add -p &&
132 git diff >output &&
133 test_cmp expected output
136 if test "$(git config --bool core.filemode)" = false
137 then
138 say 'skipping filemode tests (filesystem does not properly support modes)'
139 else
141 test_expect_success 'patch does not affect mode' '
142 git reset --hard &&
143 echo content >>file &&
144 chmod +x file &&
145 printf "n\\ny\\n" | git add -p &&
146 git show :file | grep content &&
147 git diff file | grep "new mode"
150 test_expect_success 'stage mode but not hunk' '
151 git reset --hard &&
152 echo content >>file &&
153 chmod +x file &&
154 printf "y\\nn\\n" | git add -p &&
155 git diff --cached file | grep "new mode" &&
156 git diff file | grep "+content"
160 # end of tests disabled when filemode is not usable
162 test_done