blob: 619bf970983e481af1537eb539d66bdd6b12971f [file] [log] [blame]
Jens Lehmann86140d52009-10-23 13:25:33 +02001#!/bin/sh
2#
3# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
Alexey Shumkinde6029a2013-06-26 14:19:49 +04004# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
Jens Lehmann86140d52009-10-23 13:25:33 +02005#
6
7test_description='Support for verbose submodule differences in git diff
8
9This test tries to verify the sanity of the --submodule option of git diff.
10'
11
12. ./test-lib.sh
13
Alexey Shumkinee3efaf2014-05-21 17:20:04 +040014# Tested non-UTF-8 encoding
15test_encoding="ISO8859-1"
16
Alexey Shumkinde6029a2013-06-26 14:19:49 +040017# String "added" in German (translated with Google Translate), encoded in UTF-8,
18# used in sample commit log messages in add_file() function below.
19added=$(printf "hinzugef\303\274gt")
Jens Lehmann86140d52009-10-23 13:25:33 +020020add_file () {
Ramkumar Ramachandra29349752012-11-30 17:07:35 +053021 (
22 cd "$1" &&
23 shift &&
24 for name
25 do
26 echo "$name" >"$name" &&
27 git add "$name" &&
28 test_tick &&
Pat Thoytse6ce2be2013-09-02 15:44:54 +010029 # "git commit -m" would break MinGW, as Windows refuse to pass
30 # $test_encoding encoded parameter to git.
31 echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
32 git -c "i18n.commitEncoding=$test_encoding" commit -F -
Ramkumar Ramachandra29349752012-11-30 17:07:35 +053033 done >/dev/null &&
34 git rev-parse --short --verify HEAD
35 )
Jens Lehmann86140d52009-10-23 13:25:33 +020036}
37commit_file () {
38 test_tick &&
39 git commit "$@" -m "Commit $*" >/dev/null
40}
41
42test_create_repo sm1 &&
43add_file . foo >/dev/null
44
45head1=$(add_file sm1 foo1 foo2)
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +053046fullhead1=$(cd sm1; git rev-parse --verify HEAD)
Jens Lehmann86140d52009-10-23 13:25:33 +020047
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053048test_expect_success 'added submodule' '
Jens Lehmann86140d52009-10-23 13:25:33 +020049 git add sm1 &&
50 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000051 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053052 Submodule sm1 0000000...$head1 (new submodule)
53 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +000054 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053055'
Jens Lehmann86140d52009-10-23 13:25:33 +020056
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053057test_expect_success 'added submodule, set diff.submodule' '
Ramkumar Ramachandrac47ef572012-11-13 21:12:45 +053058 git config diff.submodule log &&
59 git add sm1 &&
60 git diff --cached >actual &&
61 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053062 Submodule sm1 0000000...$head1 (new submodule)
63 EOF
Ramkumar Ramachandrac47ef572012-11-13 21:12:45 +053064 git config --unset diff.submodule &&
65 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053066'
Ramkumar Ramachandrac47ef572012-11-13 21:12:45 +053067
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053068test_expect_success '--submodule=short overrides diff.submodule' '
Ramkumar Ramachandrac47ef572012-11-13 21:12:45 +053069 test_config diff.submodule log &&
70 git add sm1 &&
71 git diff --submodule=short --cached >actual &&
72 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053073 diff --git a/sm1 b/sm1
74 new file mode 160000
75 index 0000000..$head1
76 --- /dev/null
77 +++ b/sm1
78 @@ -0,0 +1 @@
79 +Subproject commit $fullhead1
80 EOF
Ramkumar Ramachandrac47ef572012-11-13 21:12:45 +053081 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +053082'
Ramkumar Ramachandrac47ef572012-11-13 21:12:45 +053083
Jeff Kingd9c552f2012-11-13 21:12:46 +053084test_expect_success 'diff.submodule does not affect plumbing' '
85 test_config diff.submodule log &&
86 git diff-index -p HEAD >actual &&
87 cat >expected <<-EOF &&
88 diff --git a/sm1 b/sm1
89 new file mode 160000
Ramkumar Ramachandra3b13af92012-11-26 19:24:28 +053090 index 0000000..$head1
Jeff Kingd9c552f2012-11-13 21:12:46 +053091 --- /dev/null
92 +++ b/sm1
93 @@ -0,0 +1 @@
94 +Subproject commit $fullhead1
95 EOF
96 test_cmp expected actual
97'
98
Jens Lehmann86140d52009-10-23 13:25:33 +020099commit_file sm1 &&
100head2=$(add_file sm1 foo3)
101
Alexey Shumkinecaee802013-06-26 14:19:50 +0400102test_expect_success 'modified submodule(forward)' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200103 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000104 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530105 Submodule sm1 $head1..$head2:
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400106 > Add foo3 ($added foo3)
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530107 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000108 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530109'
Jens Lehmann86140d52009-10-23 13:25:33 +0200110
Alexey Shumkinecaee802013-06-26 14:19:50 +0400111test_expect_success 'modified submodule(forward)' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200112 git diff --submodule=log >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000113 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530114 Submodule sm1 $head1..$head2:
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400115 > Add foo3 ($added foo3)
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530116 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000117 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530118'
Jens Lehmann86140d52009-10-23 13:25:33 +0200119
Alexey Shumkinecaee802013-06-26 14:19:50 +0400120test_expect_success 'modified submodule(forward) --submodule' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200121 git diff --submodule >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000122 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530123 Submodule sm1 $head1..$head2:
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400124 > Add foo3 ($added foo3)
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530125 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000126 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530127'
Jens Lehmann86140d52009-10-23 13:25:33 +0200128
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +0530129fullhead2=$(cd sm1; git rev-parse --verify HEAD)
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530130test_expect_success 'modified submodule(forward) --submodule=short' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200131 git diff --submodule=short >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000132 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530133 diff --git a/sm1 b/sm1
134 index $head1..$head2 160000
135 --- a/sm1
136 +++ b/sm1
137 @@ -1 +1 @@
138 -Subproject commit $fullhead1
139 +Subproject commit $fullhead2
140 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000141 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530142'
Jens Lehmann86140d52009-10-23 13:25:33 +0200143
144commit_file sm1 &&
Jonathan Nieder18a82692010-09-06 20:42:54 -0500145head3=$(
146 cd sm1 &&
147 git reset --hard HEAD~2 >/dev/null &&
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +0530148 git rev-parse --short --verify HEAD
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +0200149)
Jens Lehmann86140d52009-10-23 13:25:33 +0200150
Alexey Shumkinecaee802013-06-26 14:19:50 +0400151test_expect_success 'modified submodule(backward)' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200152 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000153 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530154 Submodule sm1 $head2..$head3 (rewind):
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400155 < Add foo3 ($added foo3)
156 < Add foo2 ($added foo2)
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530157 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000158 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530159'
Jens Lehmann86140d52009-10-23 13:25:33 +0200160
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530161head4=$(add_file sm1 foo4 foo5)
Alexey Shumkinecaee802013-06-26 14:19:50 +0400162test_expect_success 'modified submodule(backward and forward)' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200163 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000164 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530165 Submodule sm1 $head2...$head4:
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400166 > Add foo5 ($added foo5)
167 > Add foo4 ($added foo4)
168 < Add foo3 ($added foo3)
169 < Add foo2 ($added foo2)
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530170 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000171 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530172'
Jens Lehmann86140d52009-10-23 13:25:33 +0200173
174commit_file sm1 &&
175mv sm1 sm1-bak &&
176echo sm1 >sm1 &&
177head5=$(git hash-object sm1 | cut -c1-7) &&
178git add sm1 &&
179rm -f sm1 &&
180mv sm1-bak sm1
181
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530182test_expect_success 'typechanged submodule(submodule->blob), --cached' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200183 git diff --submodule=log --cached >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000184 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530185 Submodule sm1 $head4...0000000 (submodule deleted)
186 diff --git a/sm1 b/sm1
187 new file mode 100644
188 index 0000000..$head5
189 --- /dev/null
190 +++ b/sm1
191 @@ -0,0 +1 @@
192 +sm1
193 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000194 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530195'
Jens Lehmann86140d52009-10-23 13:25:33 +0200196
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530197test_expect_success 'typechanged submodule(submodule->blob)' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200198 git diff --submodule=log >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000199 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530200 diff --git a/sm1 b/sm1
201 deleted file mode 100644
202 index $head5..0000000
203 --- a/sm1
204 +++ /dev/null
205 @@ -1 +0,0 @@
206 -sm1
207 Submodule sm1 0000000...$head4 (new submodule)
208 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000209 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530210'
Jens Lehmann86140d52009-10-23 13:25:33 +0200211
212rm -rf sm1 &&
213git checkout-index sm1
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530214test_expect_success 'typechanged submodule(submodule->blob)' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200215 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000216 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530217 Submodule sm1 $head4...0000000 (submodule deleted)
218 diff --git a/sm1 b/sm1
219 new file mode 100644
220 index 0000000..$head5
221 --- /dev/null
222 +++ b/sm1
223 @@ -0,0 +1 @@
224 +sm1
225 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000226 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530227'
Jens Lehmann86140d52009-10-23 13:25:33 +0200228
229rm -f sm1 &&
230test_create_repo sm1 &&
231head6=$(add_file sm1 foo6 foo7)
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +0530232fullhead6=$(cd sm1; git rev-parse --verify HEAD)
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530233test_expect_success 'nonexistent commit' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200234 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000235 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530236 Submodule sm1 $head4...$head6 (commits not present)
237 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000238 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530239'
Jens Lehmann86140d52009-10-23 13:25:33 +0200240
241commit_file
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530242test_expect_success 'typechanged submodule(blob->submodule)' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200243 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000244 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530245 diff --git a/sm1 b/sm1
246 deleted file mode 100644
247 index $head5..0000000
248 --- a/sm1
249 +++ /dev/null
250 @@ -1 +0,0 @@
251 -sm1
252 Submodule sm1 0000000...$head6 (new submodule)
253 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000254 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530255'
Jens Lehmann86140d52009-10-23 13:25:33 +0200256
257commit_file sm1 &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530258test_expect_success 'submodule is up to date' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100259 git diff-index -p --submodule=log HEAD >actual &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200260 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530261'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100262
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530263test_expect_success 'submodule contains untracked content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100264 echo new > sm1/new-file &&
265 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000266 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530267 Submodule sm1 contains untracked content
268 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000269 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530270'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100271
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530272test_expect_success 'submodule contains untracked content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200273 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200274 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530275'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200276
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530277test_expect_success 'submodule contains untracked content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200278 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200279 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530280'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200281
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530282test_expect_success 'submodule contains untracked content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200283 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200284 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530285'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200286
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530287test_expect_success 'submodule contains untracked and modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100288 echo new > sm1/foo6 &&
289 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000290 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530291 Submodule sm1 contains untracked content
292 Submodule sm1 contains modified content
293 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000294 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530295'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100296
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530297test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200298 echo new > sm1/foo6 &&
299 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000300 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530301 Submodule sm1 contains modified content
302 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000303 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530304'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200305
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530306test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200307 echo new > sm1/foo6 &&
308 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200309 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530310'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200311
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530312test_expect_success 'submodule contains untracked and modifed content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200313 echo new > sm1/foo6 &&
314 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200315 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530316'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200317
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530318test_expect_success 'submodule contains modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100319 rm -f sm1/new-file &&
320 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000321 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530322 Submodule sm1 contains modified content
323 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000324 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530325'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100326
327(cd sm1; git commit -mchange foo6 >/dev/null) &&
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +0530328head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530329test_expect_success 'submodule is modified' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100330 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000331 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530332 Submodule sm1 $head6..$head8:
333 > change
334 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000335 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530336'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100337
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530338test_expect_success 'modified submodule contains untracked content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100339 echo new > sm1/new-file &&
340 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000341 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530342 Submodule sm1 contains untracked content
343 Submodule sm1 $head6..$head8:
344 > change
345 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000346 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530347'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100348
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530349test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200350 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000351 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530352 Submodule sm1 $head6..$head8:
353 > change
354 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000355 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530356'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200357
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530358test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200359 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000360 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530361 Submodule sm1 $head6..$head8:
362 > change
363 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000364 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530365'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200366
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530367test_expect_success 'modified submodule contains untracked content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200368 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200369 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530370'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200371
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530372test_expect_success 'modified submodule contains untracked and modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100373 echo modification >> sm1/foo6 &&
374 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000375 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530376 Submodule sm1 contains untracked content
377 Submodule sm1 contains modified content
378 Submodule sm1 $head6..$head8:
379 > change
380 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000381 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530382'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100383
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530384test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200385 echo modification >> sm1/foo6 &&
386 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000387 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530388 Submodule sm1 contains modified content
389 Submodule sm1 $head6..$head8:
390 > change
391 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000392 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530393'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200394
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530395test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200396 echo modification >> sm1/foo6 &&
397 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000398 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530399 Submodule sm1 $head6..$head8:
400 > change
401 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000402 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530403'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200404
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530405test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200406 echo modification >> sm1/foo6 &&
407 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
SZEDER Gáborec10b012018-08-19 23:57:22 +0200408 test_must_be_empty actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530409'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200410
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530411test_expect_success 'modified submodule contains modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100412 rm -f sm1/new-file &&
413 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000414 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530415 Submodule sm1 contains modified content
416 Submodule sm1 $head6..$head8:
417 > change
418 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000419 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530420'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100421
Jens Lehmann86140d52009-10-23 13:25:33 +0200422rm -rf sm1
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530423test_expect_success 'deleted submodule' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200424 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000425 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530426 Submodule sm1 $head6...0000000 (submodule deleted)
427 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000428 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530429'
Jens Lehmann86140d52009-10-23 13:25:33 +0200430
Jeff King17f2f882017-06-14 06:58:25 -0400431test_expect_success 'create second submodule' '
432 test_create_repo sm2 &&
433 head7=$(add_file sm2 foo8 foo9) &&
434 git add sm2
435'
Jens Lehmann86140d52009-10-23 13:25:33 +0200436
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530437test_expect_success 'multiple submodules' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200438 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000439 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530440 Submodule sm1 $head6...0000000 (submodule deleted)
441 Submodule sm2 0000000...$head7 (new submodule)
442 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000443 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530444'
Jens Lehmann86140d52009-10-23 13:25:33 +0200445
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530446test_expect_success 'path filter' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200447 git diff-index -p --submodule=log HEAD sm2 >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000448 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530449 Submodule sm2 0000000...$head7 (new submodule)
450 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000451 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530452'
Jens Lehmann86140d52009-10-23 13:25:33 +0200453
454commit_file sm2
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530455test_expect_success 'given commit' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200456 git diff-index -p --submodule=log HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000457 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530458 Submodule sm1 $head6...0000000 (submodule deleted)
459 Submodule sm2 0000000...$head7 (new submodule)
460 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000461 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530462'
Jens Lehmann86140d52009-10-23 13:25:33 +0200463
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530464test_expect_success 'given commit --submodule' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200465 git diff-index -p --submodule HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000466 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530467 Submodule sm1 $head6...0000000 (submodule deleted)
468 Submodule sm2 0000000...$head7 (new submodule)
469 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000470 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530471'
Jens Lehmann86140d52009-10-23 13:25:33 +0200472
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +0530473fullhead7=$(cd sm2; git rev-parse --verify HEAD)
Jens Lehmann86140d52009-10-23 13:25:33 +0200474
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530475test_expect_success 'given commit --submodule=short' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200476 git diff-index -p --submodule=short HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000477 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530478 diff --git a/sm1 b/sm1
479 deleted file mode 160000
480 index $head6..0000000
481 --- a/sm1
482 +++ /dev/null
483 @@ -1 +0,0 @@
484 -Subproject commit $fullhead6
485 diff --git a/sm2 b/sm2
486 new file mode 160000
487 index 0000000..$head7
488 --- /dev/null
489 +++ b/sm2
490 @@ -0,0 +1 @@
491 +Subproject commit $fullhead7
492 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000493 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530494'
Jens Lehmann86140d52009-10-23 13:25:33 +0200495
Jens Lehmanneee49b62010-04-10 19:01:12 +0200496test_expect_success 'setup .git file for sm2' '
497 (cd sm2 &&
498 REAL="$(pwd)/../.real" &&
Eric Sunshinef957f032018-07-01 20:24:00 -0400499 mv .git "$REAL" &&
Jens Lehmanneee49b62010-04-10 19:01:12 +0200500 echo "gitdir: $REAL" >.git)
501'
502
503test_expect_success 'diff --submodule with .git file' '
504 git diff --submodule HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000505 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530506 Submodule sm1 $head6...0000000 (submodule deleted)
507 Submodule sm2 0000000...$head7 (new submodule)
508 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000509 test_cmp expected actual
Jens Lehmanneee49b62010-04-10 19:01:12 +0200510'
511
Heiko Voigt5e736332012-05-14 18:24:45 +0200512test_expect_success 'diff --submodule with objects referenced by alternates' '
513 mkdir sub_alt &&
514 (cd sub_alt &&
515 git init &&
516 echo a >a &&
517 git add a &&
518 git commit -m a
519 ) &&
520 mkdir super &&
521 (cd super &&
522 git clone -s ../sub_alt sub &&
523 git init &&
524 git add sub &&
525 git commit -m "sub a"
526 ) &&
527 (cd sub_alt &&
Eric Sunshinef957f032018-07-01 20:24:00 -0400528 sha1_before=$(git rev-parse --short HEAD) &&
Heiko Voigt5e736332012-05-14 18:24:45 +0200529 echo b >b &&
530 git add b &&
Jeff King99094a72015-03-20 06:07:15 -0400531 git commit -m b &&
532 sha1_after=$(git rev-parse --short HEAD) &&
533 {
534 echo "Submodule sub $sha1_before..$sha1_after:" &&
535 echo " > b"
536 } >../expected
Heiko Voigt5e736332012-05-14 18:24:45 +0200537 ) &&
538 (cd super &&
539 (cd sub &&
540 git fetch &&
541 git checkout origin/master
542 ) &&
543 git diff --submodule > ../actual
Jeff King60687de2015-03-20 06:06:44 -0400544 ) &&
Heiko Voigt5e736332012-05-14 18:24:45 +0200545 test_cmp expected actual
546'
547
Jens Lehmann86140d52009-10-23 13:25:33 +0200548test_done