blob: 058ee0829ded8163f99325494f326ef6609fee06 [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 &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000260 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530261 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000262 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530263'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100264
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530265test_expect_success 'submodule contains untracked content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100266 echo new > sm1/new-file &&
267 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000268 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530269 Submodule sm1 contains untracked content
270 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000271 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530272'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100273
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530274test_expect_success 'submodule contains untracked content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200275 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
Brian Gernhardt6ed7dda2010-06-25 13:20:48 -0400276 ! test -s actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530277'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200278
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530279test_expect_success 'submodule contains untracked content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200280 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
Brian Gernhardt6ed7dda2010-06-25 13:20:48 -0400281 ! test -s actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530282'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200283
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530284test_expect_success 'submodule contains untracked content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200285 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
Brian Gernhardt6ed7dda2010-06-25 13:20:48 -0400286 ! test -s actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530287'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200288
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530289test_expect_success 'submodule contains untracked and modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100290 echo new > sm1/foo6 &&
291 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000292 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530293 Submodule sm1 contains untracked content
294 Submodule sm1 contains modified content
295 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000296 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530297'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100298
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530299test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200300 echo new > sm1/foo6 &&
301 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000302 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530303 Submodule sm1 contains modified content
304 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000305 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530306'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200307
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530308test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200309 echo new > sm1/foo6 &&
310 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
Brian Gernhardt6ed7dda2010-06-25 13:20:48 -0400311 ! test -s actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530312'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200313
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530314test_expect_success 'submodule contains untracked and modifed content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200315 echo new > sm1/foo6 &&
316 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
Brian Gernhardt6ed7dda2010-06-25 13:20:48 -0400317 ! test -s actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530318'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200319
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530320test_expect_success 'submodule contains modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100321 rm -f sm1/new-file &&
322 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000323 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530324 Submodule sm1 contains modified content
325 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000326 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530327'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100328
329(cd sm1; git commit -mchange foo6 >/dev/null) &&
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +0530330head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530331test_expect_success 'submodule is modified' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100332 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000333 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530334 Submodule sm1 $head6..$head8:
335 > change
336 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000337 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530338'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100339
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530340test_expect_success 'modified submodule contains untracked content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100341 echo new > sm1/new-file &&
342 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000343 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530344 Submodule sm1 contains untracked content
345 Submodule sm1 $head6..$head8:
346 > change
347 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000348 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530349'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100350
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530351test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200352 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000353 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530354 Submodule sm1 $head6..$head8:
355 > change
356 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000357 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530358'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200359
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530360test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200361 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000362 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530363 Submodule sm1 $head6..$head8:
364 > change
365 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000366 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530367'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200368
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530369test_expect_success 'modified submodule contains untracked content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200370 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
Brian Gernhardt6ed7dda2010-06-25 13:20:48 -0400371 ! test -s actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530372'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200373
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530374test_expect_success 'modified submodule contains untracked and modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100375 echo modification >> sm1/foo6 &&
376 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000377 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530378 Submodule sm1 contains untracked content
379 Submodule sm1 contains modified content
380 Submodule sm1 $head6..$head8:
381 > change
382 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000383 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530384'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100385
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530386test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200387 echo modification >> sm1/foo6 &&
388 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000389 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530390 Submodule sm1 contains modified content
391 Submodule sm1 $head6..$head8:
392 > change
393 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000394 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530395'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200396
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530397test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200398 echo modification >> sm1/foo6 &&
399 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000400 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530401 Submodule sm1 $head6..$head8:
402 > change
403 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000404 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530405'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200406
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530407test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' '
Jens Lehmanndd44d412010-06-08 18:31:51 +0200408 echo modification >> sm1/foo6 &&
409 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
Brian Gernhardt6ed7dda2010-06-25 13:20:48 -0400410 ! test -s actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530411'
Jens Lehmanndd44d412010-06-08 18:31:51 +0200412
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530413test_expect_success 'modified submodule contains modifed content' '
Jens Lehmann721ceec2010-01-24 15:09:00 +0100414 rm -f sm1/new-file &&
415 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000416 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530417 Submodule sm1 contains modified content
418 Submodule sm1 $head6..$head8:
419 > change
420 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000421 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530422'
Jens Lehmann721ceec2010-01-24 15:09:00 +0100423
Jens Lehmann86140d52009-10-23 13:25:33 +0200424rm -rf sm1
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530425test_expect_success 'deleted submodule' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200426 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000427 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530428 Submodule sm1 $head6...0000000 (submodule deleted)
429 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000430 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530431'
Jens Lehmann86140d52009-10-23 13:25:33 +0200432
Jeff King17f2f882017-06-14 06:58:25 -0400433test_expect_success 'create second submodule' '
434 test_create_repo sm2 &&
435 head7=$(add_file sm2 foo8 foo9) &&
436 git add sm2
437'
Jens Lehmann86140d52009-10-23 13:25:33 +0200438
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530439test_expect_success 'multiple submodules' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200440 git diff-index -p --submodule=log HEAD >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000441 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530442 Submodule sm1 $head6...0000000 (submodule deleted)
443 Submodule sm2 0000000...$head7 (new submodule)
444 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000445 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530446'
Jens Lehmann86140d52009-10-23 13:25:33 +0200447
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530448test_expect_success 'path filter' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200449 git diff-index -p --submodule=log HEAD sm2 >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000450 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530451 Submodule sm2 0000000...$head7 (new submodule)
452 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000453 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530454'
Jens Lehmann86140d52009-10-23 13:25:33 +0200455
456commit_file sm2
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530457test_expect_success 'given commit' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200458 git diff-index -p --submodule=log HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000459 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530460 Submodule sm1 $head6...0000000 (submodule deleted)
461 Submodule sm2 0000000...$head7 (new submodule)
462 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000463 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530464'
Jens Lehmann86140d52009-10-23 13:25:33 +0200465
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530466test_expect_success 'given commit --submodule' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200467 git diff-index -p --submodule HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000468 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530469 Submodule sm1 $head6...0000000 (submodule deleted)
470 Submodule sm2 0000000...$head7 (new submodule)
471 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000472 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530473'
Jens Lehmann86140d52009-10-23 13:25:33 +0200474
Ramkumar Ramachandra20fa5382012-11-30 17:07:34 +0530475fullhead7=$(cd sm2; git rev-parse --verify HEAD)
Jens Lehmann86140d52009-10-23 13:25:33 +0200476
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530477test_expect_success 'given commit --submodule=short' '
Jens Lehmann86140d52009-10-23 13:25:33 +0200478 git diff-index -p --submodule=short HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000479 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530480 diff --git a/sm1 b/sm1
481 deleted file mode 160000
482 index $head6..0000000
483 --- a/sm1
484 +++ /dev/null
485 @@ -1 +0,0 @@
486 -Subproject commit $fullhead6
487 diff --git a/sm2 b/sm2
488 new file mode 160000
489 index 0000000..$head7
490 --- /dev/null
491 +++ b/sm2
492 @@ -0,0 +1 @@
493 +Subproject commit $fullhead7
494 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000495 test_cmp expected actual
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530496'
Jens Lehmann86140d52009-10-23 13:25:33 +0200497
Jens Lehmanneee49b62010-04-10 19:01:12 +0200498test_expect_success 'setup .git file for sm2' '
499 (cd sm2 &&
500 REAL="$(pwd)/../.real" &&
501 mv .git "$REAL"
502 echo "gitdir: $REAL" >.git)
503'
504
505test_expect_success 'diff --submodule with .git file' '
506 git diff --submodule HEAD^ >actual &&
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000507 cat >expected <<-EOF &&
Ramkumar Ramachandraa1549f92012-11-30 17:07:36 +0530508 Submodule sm1 $head6...0000000 (submodule deleted)
509 Submodule sm2 0000000...$head7 (new submodule)
510 EOF
Ævar Arnfjörð Bjarmasonf8d186b2010-11-14 14:44:16 +0000511 test_cmp expected actual
Jens Lehmanneee49b62010-04-10 19:01:12 +0200512'
513
Heiko Voigt5e736332012-05-14 18:24:45 +0200514test_expect_success 'diff --submodule with objects referenced by alternates' '
515 mkdir sub_alt &&
516 (cd sub_alt &&
517 git init &&
518 echo a >a &&
519 git add a &&
520 git commit -m a
521 ) &&
522 mkdir super &&
523 (cd super &&
524 git clone -s ../sub_alt sub &&
525 git init &&
526 git add sub &&
527 git commit -m "sub a"
528 ) &&
529 (cd sub_alt &&
530 sha1_before=$(git rev-parse --short HEAD)
531 echo b >b &&
532 git add b &&
Jeff King99094a72015-03-20 06:07:15 -0400533 git commit -m b &&
534 sha1_after=$(git rev-parse --short HEAD) &&
535 {
536 echo "Submodule sub $sha1_before..$sha1_after:" &&
537 echo " > b"
538 } >../expected
Heiko Voigt5e736332012-05-14 18:24:45 +0200539 ) &&
540 (cd super &&
541 (cd sub &&
542 git fetch &&
543 git checkout origin/master
544 ) &&
545 git diff --submodule > ../actual
Jeff King60687de2015-03-20 06:06:44 -0400546 ) &&
Heiko Voigt5e736332012-05-14 18:24:45 +0200547 test_cmp expected actual
548'
549
Jens Lehmann86140d52009-10-23 13:25:33 +0200550test_done