3 # Copyright (c) 2016 Jacob Keller, based on t4041 by Jens Lehmann
6 test_description
='Test for submodule diff on non-checked out submodule
8 This test tries to verify that add_submodule_odb works when the submodule was
9 initialized previously but the checkout has since been removed.
12 TEST_PASSES_SANITIZE_LEAK
=true
16 # Test non-UTF-8 encoding in case iconv is available.
17 if test_have_prereq ICONV
19 test_encoding
="ISO8859-1"
20 # String "added" in German (translated with Google Translate), encoded in UTF-8,
21 # used in sample commit log messages in add_file() function below.
22 added
=$
(printf "hinzugef\303\274gt")
34 echo "$name" >"$name" &&
37 # "git commit -m" would break MinGW, as Windows refuse to pass
38 # $test_encoding encoded parameter to git.
39 echo "Add $name ($added $name)" |
iconv -f utf-8
-t $test_encoding |
40 git
-c "i18n.commitEncoding=$test_encoding" commit
-F -
42 git rev-parse
--short --verify HEAD
48 git commit
"$@" -m "Commit $*" >/dev
/null
51 test_expect_success
'setup - submodules' '
52 test_create_repo sm2 &&
54 add_file sm2 foo1 foo2 &&
55 smhead1=$(git -C sm2 rev-parse --short --verify HEAD)
58 test_expect_success
'setup - git submodule add' '
59 git -c protocol.file.allow=always submodule add ./sm2 sm1 &&
60 commit_file sm1 .gitmodules &&
61 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
62 cat >expected <<-EOF &&
63 Submodule sm1 0000000...$smhead1 (new submodule)
65 test_cmp expected actual
68 test_expect_success
'submodule directory removed' '
70 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
71 cat >expected <<-EOF &&
72 Submodule sm1 0000000...$smhead1 (new submodule)
74 test_cmp expected actual
77 test_expect_success
'setup - submodule multiple commits' '
78 git submodule update --checkout sm1 &&
79 smhead2=$(add_file sm1 foo3 foo4) &&
81 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
82 cat >expected <<-EOF &&
83 Submodule sm1 $smhead1..$smhead2:
84 > Add foo4 ($added foo4)
85 > Add foo3 ($added foo3)
87 test_cmp expected actual
90 test_expect_success
'submodule removed multiple commits' '
92 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
93 cat >expected <<-EOF &&
94 Submodule sm1 $smhead1..$smhead2:
95 > Add foo4 ($added foo4)
96 > Add foo3 ($added foo3)
98 test_cmp expected actual
101 test_expect_success
'submodule not initialized in new clone' '
103 git -C sm3 diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
104 cat >expected <<-EOF &&
105 Submodule sm1 $smhead1...$smhead2 (commits not present)
107 test_cmp expected actual
110 test_expect_success
'setup submodule moved' '
111 git submodule update --checkout sm1 &&
114 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
115 cat >expected <<-EOF &&
116 Submodule sm4 0000000...$smhead2 (new submodule)
118 test_cmp expected actual
121 test_expect_success
'submodule moved then removed' '
122 smhead3=$(add_file sm4 foo6 foo7) &&
125 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
126 cat >expected <<-EOF &&
127 Submodule sm4 $smhead2..$smhead3:
128 > Add foo7 ($added foo7)
129 > Add foo6 ($added foo6)
131 test_cmp expected actual