Merge branch 'main' of github.com:git/git
[alt-git.git] / t / t1600-index.sh
blob010989f90e63f9ddf5a88d25198998c55782bbd2
1 #!/bin/sh
3 test_description='index file specific tests'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 sane_unset GIT_TEST_SPLIT_INDEX
10 test_expect_success 'setup' '
11 echo 1 >a
14 test_expect_success 'bogus GIT_INDEX_VERSION issues warning' '
16 rm -f .git/index &&
17 GIT_INDEX_VERSION=2bogus &&
18 export GIT_INDEX_VERSION &&
19 git add a 2>err &&
20 sed "s/[0-9]//" err >actual.err &&
21 sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
22 warning: GIT_INDEX_VERSION set, but the value is invalid.
23 Using version Z
24 EOF
25 test_cmp expect.err actual.err
29 test_expect_success 'out of bounds GIT_INDEX_VERSION issues warning' '
31 rm -f .git/index &&
32 GIT_INDEX_VERSION=1 &&
33 export GIT_INDEX_VERSION &&
34 git add a 2>err &&
35 sed "s/[0-9]//" err >actual.err &&
36 sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
37 warning: GIT_INDEX_VERSION set, but the value is invalid.
38 Using version Z
39 EOF
40 test_cmp expect.err actual.err
44 test_expect_success 'no warning with bogus GIT_INDEX_VERSION and existing index' '
46 GIT_INDEX_VERSION=1 &&
47 export GIT_INDEX_VERSION &&
48 git add a 2>actual.err &&
49 test_must_be_empty actual.err
53 test_expect_success 'out of bounds index.version issues warning' '
55 sane_unset GIT_INDEX_VERSION &&
56 rm -f .git/index &&
57 git config --add index.version 1 &&
58 git add a 2>err &&
59 sed "s/[0-9]//" err >actual.err &&
60 sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
61 warning: index.version set, but the value is invalid.
62 Using version Z
63 EOF
64 test_cmp expect.err actual.err
68 test_index_version () {
69 INDEX_VERSION_CONFIG=$1 &&
70 FEATURE_MANY_FILES=$2 &&
71 ENV_VAR_VERSION=$3
72 EXPECTED_OUTPUT_VERSION=$4 &&
74 rm -f .git/index &&
75 rm -f .git/config &&
76 if test "$INDEX_VERSION_CONFIG" -ne 0
77 then
78 git config --add index.version $INDEX_VERSION_CONFIG
79 fi &&
80 git config --add feature.manyFiles $FEATURE_MANY_FILES
81 if test "$ENV_VAR_VERSION" -ne 0
82 then
83 GIT_INDEX_VERSION=$ENV_VAR_VERSION &&
84 export GIT_INDEX_VERSION
85 else
86 unset GIT_INDEX_VERSION
87 fi &&
88 git add a &&
89 echo $EXPECTED_OUTPUT_VERSION >expect &&
90 test-tool index-version <.git/index >actual &&
91 test_cmp expect actual
95 test_expect_success 'index version config precedence' '
96 test_index_version 0 false 0 2 &&
97 test_index_version 2 false 0 2 &&
98 test_index_version 3 false 0 2 &&
99 test_index_version 4 false 0 4 &&
100 test_index_version 2 false 4 4 &&
101 test_index_version 2 true 0 2 &&
102 test_index_version 0 true 0 4 &&
103 test_index_version 0 true 2 2
106 test_done