3 test_description
='git status for submodule'
7 test_create_repo_with_commit
() {
8 test_create_repo
"$1" &&
13 git commit
-m " Add bar" &&
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 C_LOCALE_OUTPUT
'status clean' '
29 grep "nothing to commit" output
32 test_expect_success C_LOCALE_OUTPUT
'commit --dry-run -a clean' '
33 test_must_fail git commit --dry-run -a >output &&
34 grep "nothing to commit" output
37 test_expect_success C_LOCALE_OUTPUT
'status with modified file in submodule' '
38 (cd sub && git reset --hard) &&
39 echo "changed" >sub/foo &&
41 grep "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 &&
53 test_expect_success C_LOCALE_OUTPUT
'status with added file in submodule' '
54 (cd sub && git reset --hard && echo >foo && git add foo) &&
56 grep "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 &&
67 test_expect_success C_LOCALE_OUTPUT
'status with untracked file in submodule' '
68 (cd sub && git reset --hard) &&
69 echo "content" >sub/new-file &&
71 grep "modified: sub (untracked content)" output
74 test_expect_success C_LOCALE_OUTPUT
'status -uno with untracked file in submodule' '
75 git status -uno >output &&
76 grep "^nothing to commit" output
79 test_expect_success
'status with untracked file in submodule (porcelain)' '
80 git status --porcelain >output &&
86 test_expect_success C_LOCALE_OUTPUT
'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 &&
90 grep "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 &&
102 test_expect_success C_LOCALE_OUTPUT
'status with modified file in modified submodule' '
103 (cd sub && git reset --hard) &&
105 (cd sub && echo "next change" >foo && git commit -m "next change" foo) &&
106 echo "changed" >sub/foo &&
107 git status >output &&
108 grep "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
120 test_expect_success C_LOCALE_OUTPUT
'status with added file in modified submodule' '
121 (cd sub && git reset --hard && echo >foo && git add foo) &&
122 git status >output &&
123 grep "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
134 test_expect_success C_LOCALE_OUTPUT
'status with untracked file in modified submodule' '
135 (cd sub && git reset --hard) &&
136 echo "content" >sub/new-file &&
137 git status >output &&
138 grep "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
148 test_expect_success C_LOCALE_OUTPUT
'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 grep "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
164 test_expect_success
'setup .git file for sub' '
167 REAL="$(pwd)/../.real" &&
169 echo "gitdir: $REAL" >.git) &&
170 echo .real >>.gitignore &&
171 git commit -m "added .real to .gitignore" .gitignore
174 test_expect_success C_LOCALE_OUTPUT
'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 grep "modified: sub (new commits, modified content)" output
180 test_expect_success
'rm submodule contents' '
181 rm -rf sub/* sub/.git
184 test_expect_success C_LOCALE_OUTPUT
'status clean (empty submodule dir)' '
185 git status >output &&
186 grep "nothing to commit" output
189 test_expect_success C_LOCALE_OUTPUT
'status -a clean (empty submodule dir)' '
190 test_must_fail git commit --dry-run -a >output &&
191 grep "nothing to commit" output
194 cat >status_expect
<<\EOF
199 test_expect_failure
'status with merge conflict in .gitmodules' '
201 test_create_repo_with_commit sub1 &&
203 test_create_repo_with_commit sub2 &&
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
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
229 @@@
-1,3 -1,3 +1,9 @@@
241 cat >diff_submodule_expect <<\EOF
242 diff --cc .gitmodules
243 index badaa4c,44f999a..0000000
246 @@@ -1,3 -1,3 +1,9 @@@
258 test_expect_failure 'diff with merge conflict in .gitmodules' '
261 git diff >../diff_actual 2>&1
263 test_cmp diff_actual diff_expect
266 test_expect_failure 'diff --submodule with merge conflict in .gitmodules' '
269 git diff --submodule >../diff_submodule_actual 2>&1
271 test_cmp diff_submodule_actual diff_submodule_expect