]>
Commit | Line | Data |
---|---|---|
93c44d49 JK |
1 | #!/bin/sh |
2 | ||
25487bde | 3 | test_description='git add -u |
93c44d49 JK |
4 | |
5 | This test creates a working tree state with three files: | |
6 | ||
7 | top (previously committed, modified) | |
8 | dir/sub (previously committed, modified) | |
9 | dir/other (untracked) | |
10 | ||
5be60078 | 11 | and issues a git add -u with path limiting on "dir" to add |
25487bde JH |
12 | only the updates to dir/sub. |
13 | ||
14 | Also tested are "git add -u" without limiting, and "git add -u" | |
4cc8d6c6 | 15 | without contents changes, and other conditions' |
93c44d49 JK |
16 | |
17 | . ./test-lib.sh | |
18 | ||
a4882c27 JH |
19 | test_expect_success setup ' |
20 | echo initial >check && | |
21 | echo initial >top && | |
43b98acc | 22 | echo initial >foo && |
a4882c27 JH |
23 | mkdir dir1 dir2 && |
24 | echo initial >dir1/sub1 && | |
25 | echo initial >dir1/sub2 && | |
26 | echo initial >dir2/sub3 && | |
43b98acc | 27 | git add check dir1 dir2 top foo && |
a48fcd83 | 28 | test_tick && |
0cb0e143 | 29 | git commit -m initial && |
a4882c27 JH |
30 | |
31 | echo changed >check && | |
32 | echo changed >top && | |
33 | echo changed >dir2/sub3 && | |
34 | rm -f dir1/sub1 && | |
35 | echo other >dir2/other | |
93c44d49 JK |
36 | ' |
37 | ||
a4882c27 JH |
38 | test_expect_success update ' |
39 | git add -u dir1 dir2 | |
93c44d49 | 40 | ' |
93c44d49 | 41 | |
a4882c27 | 42 | test_expect_success 'update noticed a removal' ' |
0cb0e143 | 43 | test "$(git ls-files dir1/sub1)" = "" |
a4882c27 | 44 | ' |
93c44d49 | 45 | |
a4882c27 | 46 | test_expect_success 'update touched correct path' ' |
0cb0e143 | 47 | test "$(git diff-files --name-status dir2/sub3)" = "" |
a4882c27 | 48 | ' |
93c44d49 | 49 | |
a4882c27 | 50 | test_expect_success 'update did not touch other tracked files' ' |
0cb0e143 NS |
51 | test "$(git diff-files --name-status check)" = "M check" && |
52 | test "$(git diff-files --name-status top)" = "M top" | |
a4882c27 | 53 | ' |
93c44d49 | 54 | |
a4882c27 | 55 | test_expect_success 'update did not touch untracked files' ' |
0cb0e143 | 56 | test "$(git ls-files dir2/other)" = "" |
a4882c27 | 57 | ' |
93c44d49 | 58 | |
a4882c27 | 59 | test_expect_success 'cache tree has not been corrupted' ' |
93c44d49 | 60 | |
a4882c27 JH |
61 | git ls-files -s | |
62 | sed -e "s/ 0 / /" >expect && | |
63 | git ls-tree -r $(git write-tree) | | |
64 | sed -e "s/ blob / /" >current && | |
82ebb0b6 | 65 | test_cmp expect current |
a4882c27 JH |
66 | |
67 | ' | |
93c44d49 | 68 | |
2ed2c222 SZ |
69 | test_expect_success 'update from a subdirectory' ' |
70 | ( | |
71 | cd dir1 && | |
72 | echo more >sub2 && | |
73 | git add -u sub2 | |
74 | ) | |
75 | ' | |
76 | ||
77 | test_expect_success 'change gets noticed' ' | |
78 | ||
79 | test "$(git diff-files --name-status dir1)" = "" | |
80 | ||
81 | ' | |
93c44d49 | 82 | |
808d3d71 | 83 | test_expect_success 'non-qualified update in subdir updates from the root' ' |
7bf7a92f JK |
84 | ( |
85 | cd dir1 && | |
86 | echo even more >>sub2 && | |
87 | git add -u | |
88 | ) && | |
808d3d71 | 89 | : >expect && |
7bf7a92f JK |
90 | git diff-files --name-only >actual && |
91 | test_cmp expect actual | |
92 | ' | |
93 | ||
889c6f0e | 94 | test_expect_success 'replace a file with a symlink' ' |
43b98acc BS |
95 | |
96 | rm foo && | |
889c6f0e | 97 | test_ln_s_add top foo |
43b98acc BS |
98 | |
99 | ' | |
100 | ||
25487bde JH |
101 | test_expect_success 'add everything changed' ' |
102 | ||
103 | git add -u && | |
104 | test -z "$(git diff-files)" | |
105 | ||
106 | ' | |
107 | ||
108 | test_expect_success 'touch and then add -u' ' | |
109 | ||
110 | touch check && | |
111 | git add -u && | |
112 | test -z "$(git diff-files)" | |
113 | ||
114 | ' | |
115 | ||
116 | test_expect_success 'touch and then add explicitly' ' | |
117 | ||
118 | touch check && | |
119 | git add check && | |
120 | test -z "$(git diff-files)" | |
121 | ||
122 | ' | |
123 | ||
c36f9412 | 124 | test_expect_success 'add -n -u should not add but just report' ' |
38ed1d89 JH |
125 | |
126 | ( | |
127 | echo "add '\''check'\''" && | |
128 | echo "remove '\''top'\''" | |
129 | ) >expect && | |
130 | before=$(git ls-files -s check top) && | |
131 | echo changed >>check && | |
132 | rm -f top && | |
133 | git add -n -u >actual && | |
134 | after=$(git ls-files -s check top) && | |
135 | ||
136 | test "$before" = "$after" && | |
c36f9412 | 137 | test_i18ncmp expect actual |
38ed1d89 JH |
138 | |
139 | ' | |
140 | ||
4cc8d6c6 JH |
141 | test_expect_success 'add -u resolves unmerged paths' ' |
142 | git reset --hard && | |
143 | one=$(echo 1 | git hash-object -w --stdin) && | |
144 | two=$(echo 2 | git hash-object -w --stdin) && | |
145 | three=$(echo 3 | git hash-object -w --stdin) && | |
146 | { | |
147 | for path in path1 path2 | |
148 | do | |
149 | echo "100644 $one 1 $path" | |
150 | echo "100644 $two 2 $path" | |
151 | echo "100644 $three 3 $path" | |
152 | done | |
153 | echo "100644 $one 1 path3" | |
154 | echo "100644 $one 1 path4" | |
155 | echo "100644 $one 3 path5" | |
156 | echo "100644 $one 3 path6" | |
157 | } | | |
158 | git update-index --index-info && | |
159 | echo 3 >path1 && | |
160 | echo 2 >path3 && | |
161 | echo 2 >path5 && | |
4cc8d6c6 | 162 | |
45c45e30 JH |
163 | # Fail to explicitly resolve removed paths with "git add" |
164 | test_must_fail git add --no-all path4 && | |
165 | test_must_fail git add --no-all path6 && | |
4cc8d6c6 | 166 | |
75973b2c JH |
167 | # "add -u" should notice removals no matter what stages |
168 | # the index entries are in. | |
169 | git add -u && | |
170 | git ls-files -s path1 path2 path3 path4 path5 path6 >actual && | |
4cc8d6c6 JH |
171 | { |
172 | echo "100644 $three 0 path1" | |
173 | echo "100644 $two 0 path3" | |
174 | echo "100644 $two 0 path5" | |
75973b2c JH |
175 | } >expect && |
176 | test_cmp expect actual | |
4cc8d6c6 JH |
177 | ' |
178 | ||
1e7ef746 CP |
179 | test_expect_success '"add -u non-existent" should fail' ' |
180 | test_must_fail git add -u non-existent && | |
181 | ! (git ls-files | grep "non-existent") | |
182 | ' | |
183 | ||
93c44d49 | 184 | test_done |