Merge branch 'ik/userdiff-html-h-element-fix' into maint
[git] / t / t2203-add-intent.sh
1 #!/bin/sh
2
3 test_description='Intent to add'
4
5 . ./test-lib.sh
6
7 test_expect_success 'intent to add' '
8         test_commit 1 &&
9         git rm 1.t &&
10         echo hello >1.t &&
11         echo hello >file &&
12         echo hello >elif &&
13         git add -N file &&
14         git add elif &&
15         git add -N 1.t
16 '
17
18 test_expect_success 'git status' '
19         git status --porcelain | grep -v actual >actual &&
20         cat >expect <<-\EOF &&
21         DA 1.t
22         A  elif
23          A file
24         EOF
25         test_cmp expect actual
26 '
27
28 test_expect_success 'check result of "add -N"' '
29         git ls-files -s file >actual &&
30         empty=$(git hash-object --stdin </dev/null) &&
31         echo "100644 $empty 0   file" >expect &&
32         test_cmp expect actual
33 '
34
35 test_expect_success 'intent to add is just an ordinary empty blob' '
36         git add -u &&
37         git ls-files -s file >actual &&
38         git ls-files -s elif | sed -e "s/elif/file/" >expect &&
39         test_cmp expect actual
40 '
41
42 test_expect_success 'intent to add does not clobber existing paths' '
43         git add -N file elif &&
44         empty=$(git hash-object --stdin </dev/null) &&
45         git ls-files -s >actual &&
46         ! grep "$empty" actual
47 '
48
49 test_expect_success 'i-t-a entry is simply ignored' '
50         test_tick &&
51         git commit -a -m initial &&
52         git reset --hard &&
53
54         echo xyzzy >rezrov &&
55         echo frotz >nitfol &&
56         git add rezrov &&
57         git add -N nitfol &&
58         git commit -m second &&
59         test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
60         test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&
61         test $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 0 &&
62         test $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1
63 '
64
65 test_expect_success 'can commit with an unrelated i-t-a entry in index' '
66         git reset --hard &&
67         echo bozbar >rezrov &&
68         echo frotz >nitfol &&
69         git add rezrov &&
70         git add -N nitfol &&
71         git commit -m partial rezrov
72 '
73
74 test_expect_success 'can "commit -a" with an i-t-a entry' '
75         git reset --hard &&
76         : >nitfol &&
77         git add -N nitfol &&
78         git commit -a -m all
79 '
80
81 test_expect_success 'cache-tree invalidates i-t-a paths' '
82         git reset --hard &&
83         mkdir dir &&
84         : >dir/foo &&
85         git add dir/foo &&
86         git commit -m foo &&
87
88         : >dir/bar &&
89         git add -N dir/bar &&
90         git diff --cached --name-only >actual &&
91         echo dir/bar >expect &&
92         test_cmp expect actual &&
93
94         git write-tree >/dev/null &&
95
96         git diff --cached --name-only >actual &&
97         echo dir/bar >expect &&
98         test_cmp expect actual
99 '
100
101 test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' '
102         git init ita-in-dir &&
103         (
104                 cd ita-in-dir &&
105                 mkdir 2 &&
106                 for f in 1 2/1 2/2 3
107                 do
108                         echo "$f" >"$f"
109                 done &&
110                 git add 1 2/2 3 &&
111                 git add -N 2/1 &&
112                 git commit -m committed &&
113                 git ls-tree -r HEAD >actual &&
114                 grep 2/2 actual
115         )
116 '
117
118 test_expect_success 'cache-tree does skip dir that becomes empty' '
119         rm -fr ita-in-dir &&
120         git init ita-in-dir &&
121         (
122                 cd ita-in-dir &&
123                 mkdir -p 1/2/3 &&
124                 echo 4 >1/2/3/4 &&
125                 git add -N 1/2/3/4 &&
126                 git write-tree >actual &&
127                 echo $EMPTY_TREE >expected &&
128                 test_cmp expected actual
129         )
130 '
131
132 test_expect_success 'commit: ita entries ignored in empty initial commit check' '
133         git init empty-initial-commit &&
134         (
135                 cd empty-initial-commit &&
136                 : >one &&
137                 git add -N one &&
138                 test_must_fail git commit -m nothing-new-here
139         )
140 '
141
142 test_expect_success 'commit: ita entries ignored in empty commit check' '
143         git init empty-subsequent-commit &&
144         (
145                 cd empty-subsequent-commit &&
146                 test_commit one &&
147                 : >two &&
148                 git add -N two &&
149                 test_must_fail git commit -m nothing-new-here
150         )
151 '
152
153 test_done
154