Fix "git add -u" data corruption.
[git/git.git] / t / t2200-add-update.sh
CommitLineData
93c44d49
JK
1#!/bin/sh
2
3test_description='git-add -u with path limiting
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
11and issues a git-add -u with path limiting on "dir" to add
12only the updates to dir/sub.'
13
14. ./test-lib.sh
15
a4882c27
JH
16test_expect_success setup '
17 echo initial >check &&
18 echo initial >top &&
19 mkdir dir1 dir2 &&
20 echo initial >dir1/sub1 &&
21 echo initial >dir1/sub2 &&
22 echo initial >dir2/sub3 &&
23 git add check dir1 dir2 top &&
24 test_tick
25 git-commit -m initial &&
26
27 echo changed >check &&
28 echo changed >top &&
29 echo changed >dir2/sub3 &&
30 rm -f dir1/sub1 &&
31 echo other >dir2/other
32'
33
34test_expect_success update '
35 git add -u dir1 dir2
93c44d49
JK
36'
37
a4882c27
JH
38test_expect_success 'update noticed a removal' '
39 test "$(git-ls-files dir1/sub1)" = ""
40'
93c44d49 41
a4882c27
JH
42test_expect_success 'update touched correct path' '
43 test "$(git-diff-files --name-status dir2/sub3)" = ""
44'
93c44d49 45
a4882c27
JH
46test_expect_success 'update did not touch other tracked files' '
47 test "$(git-diff-files --name-status check)" = "M check" &&
48 test "$(git-diff-files --name-status top)" = "M top"
49'
93c44d49 50
a4882c27
JH
51test_expect_success 'update did not touch untracked files' '
52 test "$(git-ls-files dir2/other)" = ""
53'
54
55test_expect_success 'cache tree has not been corrupted' '
56
57 git ls-files -s |
58 sed -e "s/ 0 / /" >expect &&
59 git ls-tree -r $(git write-tree) |
60 sed -e "s/ blob / /" >current &&
61 diff -u expect current
62
63'
93c44d49
JK
64
65test_done