]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2200-add-update.sh
Merge branch 'wb/fsmonitor-bitmap-fix'
[thirdparty/git.git] / t / t2200-add-update.sh
1 #!/bin/sh
2
3 test_description='git add -u
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
11 and issues a git add -u with path limiting on "dir" to add
12 only the updates to dir/sub.
13
14 Also tested are "git add -u" without limiting, and "git add -u"
15 without contents changes, and other conditions'
16
17 . ./test-lib.sh
18
19 test_expect_success setup '
20 echo initial >check &&
21 echo initial >top &&
22 echo initial >foo &&
23 mkdir dir1 dir2 &&
24 echo initial >dir1/sub1 &&
25 echo initial >dir1/sub2 &&
26 echo initial >dir2/sub3 &&
27 git add check dir1 dir2 top foo &&
28 test_tick &&
29 git commit -m initial &&
30
31 echo changed >check &&
32 echo changed >top &&
33 echo changed >dir2/sub3 &&
34 rm -f dir1/sub1 &&
35 echo other >dir2/other
36 '
37
38 test_expect_success update '
39 git add -u dir1 dir2
40 '
41
42 test_expect_success 'update noticed a removal' '
43 test "$(git ls-files dir1/sub1)" = ""
44 '
45
46 test_expect_success 'update touched correct path' '
47 test "$(git diff-files --name-status dir2/sub3)" = ""
48 '
49
50 test_expect_success 'update did not touch other tracked files' '
51 test "$(git diff-files --name-status check)" = "M check" &&
52 test "$(git diff-files --name-status top)" = "M top"
53 '
54
55 test_expect_success 'update did not touch untracked files' '
56 test "$(git ls-files dir2/other)" = ""
57 '
58
59 test_expect_success 'cache tree has not been corrupted' '
60
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 &&
65 test_cmp expect current
66
67 '
68
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 '
82
83 test_expect_success 'non-qualified update in subdir updates from the root' '
84 (
85 cd dir1 &&
86 echo even more >>sub2 &&
87 git --literal-pathspecs add -u &&
88 echo even more >>sub2 &&
89 git add -u
90 ) &&
91 git diff-files --name-only >actual &&
92 test_must_be_empty actual
93 '
94
95 test_expect_success 'replace a file with a symlink' '
96
97 rm foo &&
98 test_ln_s_add top foo
99
100 '
101
102 test_expect_success 'add everything changed' '
103
104 git add -u &&
105 test -z "$(git diff-files)"
106
107 '
108
109 test_expect_success 'touch and then add -u' '
110
111 touch check &&
112 git add -u &&
113 test -z "$(git diff-files)"
114
115 '
116
117 test_expect_success 'touch and then add explicitly' '
118
119 touch check &&
120 git add check &&
121 test -z "$(git diff-files)"
122
123 '
124
125 test_expect_success 'add -n -u should not add but just report' '
126
127 (
128 echo "add '\''check'\''" &&
129 echo "remove '\''top'\''"
130 ) >expect &&
131 before=$(git ls-files -s check top) &&
132 echo changed >>check &&
133 rm -f top &&
134 git add -n -u >actual &&
135 after=$(git ls-files -s check top) &&
136
137 test "$before" = "$after" &&
138 test_i18ncmp expect actual
139
140 '
141
142 test_expect_success 'add -u resolves unmerged paths' '
143 git reset --hard &&
144 one=$(echo 1 | git hash-object -w --stdin) &&
145 two=$(echo 2 | git hash-object -w --stdin) &&
146 three=$(echo 3 | git hash-object -w --stdin) &&
147 {
148 for path in path1 path2
149 do
150 echo "100644 $one 1 $path"
151 echo "100644 $two 2 $path"
152 echo "100644 $three 3 $path"
153 done
154 echo "100644 $one 1 path3"
155 echo "100644 $one 1 path4"
156 echo "100644 $one 3 path5"
157 echo "100644 $one 3 path6"
158 } |
159 git update-index --index-info &&
160 echo 3 >path1 &&
161 echo 2 >path3 &&
162 echo 2 >path5 &&
163
164 # Fail to explicitly resolve removed paths with "git add"
165 test_must_fail git add --no-all path4 &&
166 test_must_fail git add --no-all path6 &&
167
168 # "add -u" should notice removals no matter what stages
169 # the index entries are in.
170 git add -u &&
171 git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
172 {
173 echo "100644 $three 0 path1"
174 echo "100644 $two 0 path3"
175 echo "100644 $two 0 path5"
176 } >expect &&
177 test_cmp expect actual
178 '
179
180 test_expect_success '"add -u non-existent" should fail' '
181 test_must_fail git add -u non-existent &&
182 ! (git ls-files | grep "non-existent")
183 '
184
185 test_done