Jacob Keller | 99b43a6 | 2016-08-31 16:27:22 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2016 Jacob Keller, based on t4041 by Jens Lehmann |
| 4 | # |
| 5 | |
| 6 | test_description='Test for submodule diff on non-checked out submodule |
| 7 | |
| 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. |
| 10 | ' |
| 11 | |
| 12 | . ./test-lib.sh |
| 13 | |
| 14 | # Tested non-UTF-8 encoding |
| 15 | test_encoding="ISO8859-1" |
| 16 | |
| 17 | # String "added" in German (translated with Google Translate), encoded in UTF-8, |
| 18 | # used in sample commit log messages in add_file() function below. |
| 19 | added=$(printf "hinzugef\303\274gt") |
| 20 | |
| 21 | add_file () { |
| 22 | ( |
| 23 | cd "$1" && |
| 24 | shift && |
| 25 | for name |
| 26 | do |
| 27 | echo "$name" >"$name" && |
| 28 | git add "$name" && |
| 29 | test_tick && |
| 30 | # "git commit -m" would break MinGW, as Windows refuse to pass |
| 31 | # $test_encoding encoded parameter to git. |
| 32 | echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding | |
| 33 | git -c "i18n.commitEncoding=$test_encoding" commit -F - |
| 34 | done >/dev/null && |
| 35 | git rev-parse --short --verify HEAD |
| 36 | ) |
| 37 | } |
| 38 | |
| 39 | commit_file () { |
| 40 | test_tick && |
| 41 | git commit "$@" -m "Commit $*" >/dev/null |
| 42 | } |
| 43 | |
| 44 | test_expect_success 'setup - submodules' ' |
| 45 | test_create_repo sm2 && |
| 46 | add_file . foo && |
| 47 | add_file sm2 foo1 foo2 && |
| 48 | smhead1=$(git -C sm2 rev-parse --short --verify HEAD) |
| 49 | ' |
| 50 | |
| 51 | test_expect_success 'setup - git submodule add' ' |
| 52 | git submodule add ./sm2 sm1 && |
| 53 | commit_file sm1 .gitmodules && |
| 54 | git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual && |
| 55 | cat >expected <<-EOF && |
| 56 | Submodule sm1 0000000...$smhead1 (new submodule) |
| 57 | EOF |
| 58 | test_cmp expected actual |
| 59 | ' |
| 60 | |
| 61 | test_expect_success 'submodule directory removed' ' |
| 62 | rm -rf sm1 && |
| 63 | git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual && |
| 64 | cat >expected <<-EOF && |
| 65 | Submodule sm1 0000000...$smhead1 (new submodule) |
| 66 | EOF |
| 67 | test_cmp expected actual |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'setup - submodule multiple commits' ' |
| 71 | git submodule update --checkout sm1 && |
| 72 | smhead2=$(add_file sm1 foo3 foo4) && |
| 73 | commit_file sm1 && |
| 74 | git diff-tree -p --no-commit-id --submodule=log HEAD >actual && |
| 75 | cat >expected <<-EOF && |
| 76 | Submodule sm1 $smhead1..$smhead2: |
| 77 | > Add foo4 ($added foo4) |
| 78 | > Add foo3 ($added foo3) |
| 79 | EOF |
| 80 | test_cmp expected actual |
| 81 | ' |
| 82 | |
| 83 | test_expect_success 'submodule removed multiple commits' ' |
| 84 | rm -rf sm1 && |
| 85 | git diff-tree -p --no-commit-id --submodule=log HEAD >actual && |
| 86 | cat >expected <<-EOF && |
| 87 | Submodule sm1 $smhead1..$smhead2: |
| 88 | > Add foo4 ($added foo4) |
| 89 | > Add foo3 ($added foo3) |
| 90 | EOF |
| 91 | test_cmp expected actual |
| 92 | ' |
| 93 | |
| 94 | test_expect_success 'submodule not initialized in new clone' ' |
| 95 | git clone . sm3 && |
| 96 | git -C sm3 diff-tree -p --no-commit-id --submodule=log HEAD >actual && |
| 97 | cat >expected <<-EOF && |
Stefan Beller | 2d94dd2 | 2017-09-26 11:27:56 -0700 | [diff] [blame] | 98 | Submodule sm1 $smhead1...$smhead2 (commits not present) |
Jacob Keller | 99b43a6 | 2016-08-31 16:27:22 -0700 | [diff] [blame] | 99 | EOF |
| 100 | test_cmp expected actual |
| 101 | ' |
| 102 | |
| 103 | test_expect_success 'setup submodule moved' ' |
| 104 | git submodule update --checkout sm1 && |
| 105 | git mv sm1 sm4 && |
| 106 | commit_file sm4 && |
| 107 | git diff-tree -p --no-commit-id --submodule=log HEAD >actual && |
| 108 | cat >expected <<-EOF && |
| 109 | Submodule sm4 0000000...$smhead2 (new submodule) |
| 110 | EOF |
| 111 | test_cmp expected actual |
| 112 | ' |
| 113 | |
| 114 | test_expect_success 'submodule moved then removed' ' |
| 115 | smhead3=$(add_file sm4 foo6 foo7) && |
| 116 | commit_file sm4 && |
| 117 | rm -rf sm4 && |
| 118 | git diff-tree -p --no-commit-id --submodule=log HEAD >actual && |
| 119 | cat >expected <<-EOF && |
| 120 | Submodule sm4 $smhead2..$smhead3: |
| 121 | > Add foo7 ($added foo7) |
| 122 | > Add foo6 ($added foo6) |
| 123 | EOF |
| 124 | test_cmp expected actual |
| 125 | ' |
| 126 | |
| 127 | test_done |