Merge branch 'mk/combine-diff-context-horizon-fix' into maint
[git/mjg.git] / t / t7506-status-submodule.sh
blobd31b34da83d5ad336f2355acc0d2536b9d30e3ce
1 #!/bin/sh
3 test_description='git status for submodule'
5 . ./test-lib.sh
7 test_create_repo_with_commit () {
8 test_create_repo "$1" &&
10 cd "$1" &&
11 : >bar &&
12 git add bar &&
13 git commit -m " Add bar" &&
14 : >foo &&
15 git add foo &&
16 git commit -m " Add foo"
20 test_expect_success 'setup' '
21 test_create_repo_with_commit sub &&
22 echo output > .gitignore &&
23 git add sub .gitignore &&
24 git commit -m "Add submodule sub"
27 test_expect_success 'status clean' '
28 git status >output &&
29 test_i18ngrep "nothing to commit" output
32 test_expect_success 'commit --dry-run -a clean' '
33 test_must_fail git commit --dry-run -a >output &&
34 test_i18ngrep "nothing to commit" output
37 test_expect_success 'status with modified file in submodule' '
38 (cd sub && git reset --hard) &&
39 echo "changed" >sub/foo &&
40 git status >output &&
41 test_i18ngrep "modified: sub (modified content)" output
44 test_expect_success 'status with modified file in submodule (porcelain)' '
45 (cd sub && git reset --hard) &&
46 echo "changed" >sub/foo &&
47 git status --porcelain >output &&
48 diff output - <<-\EOF
49 M sub
50 EOF
53 test_expect_success 'status with added file in submodule' '
54 (cd sub && git reset --hard && echo >foo && git add foo) &&
55 git status >output &&
56 test_i18ngrep "modified: sub (modified content)" output
59 test_expect_success 'status with added file in submodule (porcelain)' '
60 (cd sub && git reset --hard && echo >foo && git add foo) &&
61 git status --porcelain >output &&
62 diff output - <<-\EOF
63 M sub
64 EOF
67 test_expect_success 'status with untracked file in submodule' '
68 (cd sub && git reset --hard) &&
69 echo "content" >sub/new-file &&
70 git status >output &&
71 test_i18ngrep "modified: sub (untracked content)" output
74 test_expect_success 'status -uno with untracked file in submodule' '
75 git status -uno >output &&
76 test_i18ngrep "^nothing to commit" output
79 test_expect_success 'status with untracked file in submodule (porcelain)' '
80 git status --porcelain >output &&
81 diff output - <<-\EOF
82 M sub
83 EOF
86 test_expect_success 'status with added and untracked file in submodule' '
87 (cd sub && git reset --hard && echo >foo && git add foo) &&
88 echo "content" >sub/new-file &&
89 git status >output &&
90 test_i18ngrep "modified: sub (modified content, untracked content)" output
93 test_expect_success 'status with added and untracked file in submodule (porcelain)' '
94 (cd sub && git reset --hard && echo >foo && git add foo) &&
95 echo "content" >sub/new-file &&
96 git status --porcelain >output &&
97 diff output - <<-\EOF
98 M sub
99 EOF
102 test_expect_success 'status with modified file in modified submodule' '
103 (cd sub && git reset --hard) &&
104 rm sub/new-file &&
105 (cd sub && echo "next change" >foo && git commit -m "next change" foo) &&
106 echo "changed" >sub/foo &&
107 git status >output &&
108 test_i18ngrep "modified: sub (new commits, modified content)" output
111 test_expect_success 'status with modified file in modified submodule (porcelain)' '
112 (cd sub && git reset --hard) &&
113 echo "changed" >sub/foo &&
114 git status --porcelain >output &&
115 diff output - <<-\EOF
116 M sub
120 test_expect_success 'status with added file in modified submodule' '
121 (cd sub && git reset --hard && echo >foo && git add foo) &&
122 git status >output &&
123 test_i18ngrep "modified: sub (new commits, modified content)" output
126 test_expect_success 'status with added file in modified submodule (porcelain)' '
127 (cd sub && git reset --hard && echo >foo && git add foo) &&
128 git status --porcelain >output &&
129 diff output - <<-\EOF
130 M sub
134 test_expect_success 'status with untracked file in modified submodule' '
135 (cd sub && git reset --hard) &&
136 echo "content" >sub/new-file &&
137 git status >output &&
138 test_i18ngrep "modified: sub (new commits, untracked content)" output
141 test_expect_success 'status with untracked file in modified submodule (porcelain)' '
142 git status --porcelain >output &&
143 diff output - <<-\EOF
144 M sub
148 test_expect_success 'status with added and untracked file in modified submodule' '
149 (cd sub && git reset --hard && echo >foo && git add foo) &&
150 echo "content" >sub/new-file &&
151 git status >output &&
152 test_i18ngrep "modified: sub (new commits, modified content, untracked content)" output
155 test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
156 (cd sub && git reset --hard && echo >foo && git add foo) &&
157 echo "content" >sub/new-file &&
158 git status --porcelain >output &&
159 diff output - <<-\EOF
160 M sub
164 test_expect_success 'setup .git file for sub' '
165 (cd sub &&
166 rm -f new-file
167 REAL="$(pwd)/../.real" &&
168 mv .git "$REAL"
169 echo "gitdir: $REAL" >.git) &&
170 echo .real >>.gitignore &&
171 git commit -m "added .real to .gitignore" .gitignore
174 test_expect_success 'status with added file in modified submodule with .git file' '
175 (cd sub && git reset --hard && echo >foo && git add foo) &&
176 git status >output &&
177 test_i18ngrep "modified: sub (new commits, modified content)" output
180 test_expect_success 'rm submodule contents' '
181 rm -rf sub/* sub/.git
184 test_expect_success 'status clean (empty submodule dir)' '
185 git status >output &&
186 test_i18ngrep "nothing to commit" output
189 test_expect_success 'status -a clean (empty submodule dir)' '
190 test_must_fail git commit --dry-run -a >output &&
191 test_i18ngrep "nothing to commit" output
194 cat >status_expect <<\EOF
195 AA .gitmodules
196 A sub1
199 test_expect_success 'status with merge conflict in .gitmodules' '
200 git clone . super &&
201 test_create_repo_with_commit sub1 &&
202 test_tick &&
203 test_create_repo_with_commit sub2 &&
205 cd super &&
206 prev=$(git rev-parse HEAD) &&
207 git checkout -b add_sub1 &&
208 git submodule add ../sub1 &&
209 git commit -m "add sub1" &&
210 git checkout -b add_sub2 $prev &&
211 git submodule add ../sub2 &&
212 git commit -m "add sub2" &&
213 git checkout -b merge_conflict_gitmodules &&
214 test_must_fail git merge add_sub1 &&
215 git status -s >../status_actual 2>&1
216 ) &&
217 test_cmp status_actual status_expect
220 sha1_merge_sub1=$(cd sub1 && git rev-parse HEAD)
221 sha1_merge_sub2=$(cd sub2 && git rev-parse HEAD)
222 short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD)
223 short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD)
224 cat >diff_expect <<\EOF
225 diff --cc .gitmodules
226 index badaa4c,44f999a..0000000
227 --- a/.gitmodules
228 +++ b/.gitmodules
229 @@@ -1,3 -1,3 +1,9 @@@
230 ++<<<<<<< HEAD
231 +[submodule "sub2"]
232 + path = sub2
233 + url = ../sub2
234 ++=======
235 + [submodule "sub1"]
236 + path = sub1
237 + url = ../sub1
238 ++>>>>>>> add_sub1
241 cat >diff_submodule_expect <<\EOF
242 diff --cc .gitmodules
243 index badaa4c,44f999a..0000000
244 --- a/.gitmodules
245 +++ b/.gitmodules
246 @@@ -1,3 -1,3 +1,9 @@@
247 ++<<<<<<< HEAD
248 +[submodule "sub2"]
249 + path = sub2
250 + url = ../sub2
251 ++=======
252 + [submodule "sub1"]
253 + path = sub1
254 + url = ../sub1
255 ++>>>>>>> add_sub1
258 test_expect_success 'diff with merge conflict in .gitmodules' '
260 cd super &&
261 git diff >../diff_actual 2>&1
262 ) &&
263 test_cmp diff_actual diff_expect
266 test_expect_success 'diff --submodule with merge conflict in .gitmodules' '
268 cd super &&
269 git diff --submodule >../diff_submodule_actual 2>&1
270 ) &&
271 test_cmp diff_submodule_actual diff_submodule_expect
274 test_done