Sync with 'maint'
[alt-git.git] / t / t4059-diff-submodule-not-initialized.sh
blob28fd3cdb154e28d3183dcc13e8eec047c51bbecc
1 #!/bin/sh
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
13 . ./test-lib.sh
16 # Test non-UTF-8 encoding in case iconv is available.
17 if test_have_prereq ICONV
18 then
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")
23 else
24 test_encoding="UTF-8"
25 added="added"
28 add_file () {
30 cd "$1" &&
31 shift &&
32 for name
34 echo "$name" >"$name" &&
35 git add "$name" &&
36 test_tick &&
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 -
41 done >/dev/null &&
42 git rev-parse --short --verify HEAD
46 commit_file () {
47 test_tick &&
48 git commit "$@" -m "Commit $*" >/dev/null
51 test_expect_success 'setup - submodules' '
52 test_create_repo sm2 &&
53 add_file . foo &&
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)
64 EOF
65 test_cmp expected actual
68 test_expect_success 'submodule directory removed' '
69 rm -rf sm1 &&
70 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
71 cat >expected <<-EOF &&
72 Submodule sm1 0000000...$smhead1 (new submodule)
73 EOF
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) &&
80 commit_file sm1 &&
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)
86 EOF
87 test_cmp expected actual
90 test_expect_success 'submodule removed multiple commits' '
91 rm -rf sm1 &&
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)
97 EOF
98 test_cmp expected actual
101 test_expect_success 'submodule not initialized in new clone' '
102 git clone . sm3 &&
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 &&
112 git mv sm1 sm4 &&
113 commit_file sm4 &&
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) &&
123 commit_file sm4 &&
124 rm -rf sm4 &&
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
134 test_done