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