rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t2200-add-update.sh
blob0c38f8e35695745c8eb02fe090c0d15b6d1666c8
1 #!/bin/sh
3 test_description='git add -u
5 This test creates a working tree state with three files:
7 top (previously committed, modified)
8 dir/sub (previously committed, modified)
9 dir/other (untracked)
11 and issues a git add -u with path limiting on "dir" to add
12 only the updates to dir/sub.
14 Also tested are "git add -u" without limiting, and "git add -u"
15 without contents changes, and other conditions'
17 . ./test-lib.sh
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 &&
31 echo changed >check &&
32 echo changed >top &&
33 echo changed >dir2/sub3 &&
34 rm -f dir1/sub1 &&
35 echo other >dir2/other
38 test_expect_success update '
39 git add -u dir1 dir2
42 test_expect_success 'update noticed a removal' '
43 git ls-files dir1/sub1 >out &&
44 test_must_be_empty out
47 test_expect_success 'update touched correct path' '
48 git diff-files --name-status dir2/sub3 >out &&
49 test_must_be_empty out
52 test_expect_success 'update did not touch other tracked files' '
53 echo "M check" >expect &&
54 git diff-files --name-status check >actual &&
55 test_cmp expect actual &&
57 echo "M top" >expect &&
58 git diff-files --name-status top >actual &&
59 test_cmp expect actual
62 test_expect_success 'update did not touch untracked files' '
63 git ls-files dir2/other >out &&
64 test_must_be_empty out
67 test_expect_success 'cache tree has not been corrupted' '
69 git ls-files -s |
70 sed -e "s/ 0 / /" >expect &&
71 git ls-tree -r $(git write-tree) |
72 sed -e "s/ blob / /" >current &&
73 test_cmp expect current
77 test_expect_success 'update from a subdirectory' '
79 cd dir1 &&
80 echo more >sub2 &&
81 git add -u sub2
85 test_expect_success 'change gets noticed' '
86 git diff-files --name-status dir1 >out &&
87 test_must_be_empty out
90 test_expect_success 'non-qualified update in subdir updates from the root' '
92 cd dir1 &&
93 echo even more >>sub2 &&
94 git --literal-pathspecs add -u &&
95 echo even more >>sub2 &&
96 git add -u
97 ) &&
98 git diff-files --name-only >actual &&
99 test_must_be_empty actual
102 test_expect_success 'replace a file with a symlink' '
104 rm foo &&
105 test_ln_s_add top foo
109 test_expect_success 'add everything changed' '
111 git add -u &&
112 git diff-files >out &&
113 test_must_be_empty out
117 test_expect_success 'touch and then add -u' '
119 touch check &&
120 git add -u &&
121 git diff-files >out &&
122 test_must_be_empty out
126 test_expect_success 'touch and then add explicitly' '
128 touch check &&
129 git add check &&
130 git diff-files >out &&
131 test_must_be_empty out
135 test_expect_success 'add -n -u should not add but just report' '
138 echo "add '\''check'\''" &&
139 echo "remove '\''top'\''"
140 ) >expect &&
141 before=$(git ls-files -s check top) &&
142 git count-objects -v >objects_before &&
143 echo changed >>check &&
144 rm -f top &&
145 git add -n -u >actual &&
146 after=$(git ls-files -s check top) &&
147 git count-objects -v >objects_after &&
149 test "$before" = "$after" &&
150 test_cmp objects_before objects_after &&
151 test_cmp expect actual
155 test_expect_success 'add -u resolves unmerged paths' '
156 git reset --hard &&
157 one=$(echo 1 | git hash-object -w --stdin) &&
158 two=$(echo 2 | git hash-object -w --stdin) &&
159 three=$(echo 3 | git hash-object -w --stdin) &&
161 for path in path1 path2
163 echo "100644 $one 1 $path" &&
164 echo "100644 $two 2 $path" &&
165 echo "100644 $three 3 $path" || return 1
166 done &&
167 echo "100644 $one 1 path3" &&
168 echo "100644 $one 1 path4" &&
169 echo "100644 $one 3 path5" &&
170 echo "100644 $one 3 path6"
172 git update-index --index-info &&
173 echo 3 >path1 &&
174 echo 2 >path3 &&
175 echo 2 >path5 &&
177 # Fail to explicitly resolve removed paths with "git add"
178 test_must_fail git add --no-all path4 &&
179 test_must_fail git add --no-all path6 &&
181 # "add -u" should notice removals no matter what stages
182 # the index entries are in.
183 git add -u &&
184 git ls-files -s path1 path2 path3 path4 path5 path6 >actual &&
186 echo "100644 $three 0 path1" &&
187 echo "100644 $two 0 path3" &&
188 echo "100644 $two 0 path5"
189 } >expect &&
190 test_cmp expect actual
193 test_expect_success '"add -u non-existent" should fail' '
194 test_must_fail git add -u non-existent &&
195 git ls-files >actual &&
196 ! grep "non-existent" actual
199 test_done