Merge branch 'jc/ci-upload-artifact-and-linux32'
[git/gitster.git] / t / t4059-diff-submodule-not-initialized.sh
blob668f5263038374ec0a2584230041cbdfef674652
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
15 # Tested non-UTF-8 encoding
16 test_encoding="ISO8859-1"
18 # String "added" in German (translated with Google Translate), encoded in UTF-8,
19 # used in sample commit log messages in add_file() function below.
20 added=$(printf "hinzugef\303\274gt")
22 add_file () {
24 cd "$1" &&
25 shift &&
26 for name
28 echo "$name" >"$name" &&
29 git add "$name" &&
30 test_tick &&
31 # "git commit -m" would break MinGW, as Windows refuse to pass
32 # $test_encoding encoded parameter to git.
33 echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
34 git -c "i18n.commitEncoding=$test_encoding" commit -F -
35 done >/dev/null &&
36 git rev-parse --short --verify HEAD
40 commit_file () {
41 test_tick &&
42 git commit "$@" -m "Commit $*" >/dev/null
45 test_expect_success 'setup - submodules' '
46 test_create_repo sm2 &&
47 add_file . foo &&
48 add_file sm2 foo1 foo2 &&
49 smhead1=$(git -C sm2 rev-parse --short --verify HEAD)
52 test_expect_success 'setup - git submodule add' '
53 git -c protocol.file.allow=always submodule add ./sm2 sm1 &&
54 commit_file sm1 .gitmodules &&
55 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
56 cat >expected <<-EOF &&
57 Submodule sm1 0000000...$smhead1 (new submodule)
58 EOF
59 test_cmp expected actual
62 test_expect_success 'submodule directory removed' '
63 rm -rf sm1 &&
64 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
65 cat >expected <<-EOF &&
66 Submodule sm1 0000000...$smhead1 (new submodule)
67 EOF
68 test_cmp expected actual
71 test_expect_success 'setup - submodule multiple commits' '
72 git submodule update --checkout sm1 &&
73 smhead2=$(add_file sm1 foo3 foo4) &&
74 commit_file sm1 &&
75 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
76 cat >expected <<-EOF &&
77 Submodule sm1 $smhead1..$smhead2:
78 > Add foo4 ($added foo4)
79 > Add foo3 ($added foo3)
80 EOF
81 test_cmp expected actual
84 test_expect_success 'submodule removed multiple commits' '
85 rm -rf sm1 &&
86 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
87 cat >expected <<-EOF &&
88 Submodule sm1 $smhead1..$smhead2:
89 > Add foo4 ($added foo4)
90 > Add foo3 ($added foo3)
91 EOF
92 test_cmp expected actual
95 test_expect_success 'submodule not initialized in new clone' '
96 git clone . sm3 &&
97 git -C sm3 diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
98 cat >expected <<-EOF &&
99 Submodule sm1 $smhead1...$smhead2 (commits not present)
101 test_cmp expected actual
104 test_expect_success 'setup submodule moved' '
105 git submodule update --checkout sm1 &&
106 git mv sm1 sm4 &&
107 commit_file sm4 &&
108 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
109 cat >expected <<-EOF &&
110 Submodule sm4 0000000...$smhead2 (new submodule)
112 test_cmp expected actual
115 test_expect_success 'submodule moved then removed' '
116 smhead3=$(add_file sm4 foo6 foo7) &&
117 commit_file sm4 &&
118 rm -rf sm4 &&
119 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
120 cat >expected <<-EOF &&
121 Submodule sm4 $smhead2..$smhead3:
122 > Add foo7 ($added foo7)
123 > Add foo6 ($added foo6)
125 test_cmp expected actual
128 test_done