3 test_description
='basic update-index tests
5 Tests for command-line parsing and basic operation.
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'update-index --nonsense fails' '
12 test_must_fail git update-index --nonsense 2>msg &&
16 test_expect_success
'update-index --nonsense dumps usage' '
17 test_expect_code 129 git update-index --nonsense 2>err &&
18 test_grep "[Uu]sage: git update-index" err
21 test_expect_success
'update-index -h with corrupt index' '
27 test_expect_code 129 git update-index -h >usage 2>&1
29 test_grep "[Uu]sage: git update-index" broken/usage
32 test_expect_success
'--cacheinfo complains of missing arguments' '
33 test_must_fail git update-index --cacheinfo
36 test_expect_success
'--cacheinfo does not accept blob null sha1' '
39 git rev-parse :file >expect &&
40 test_must_fail git update-index --verbose --cacheinfo 100644 $ZERO_OID file >out &&
41 git rev-parse :file >actual &&
42 test_cmp expect actual &&
44 cat >expect <<-\EOF &&
50 test_expect_success
'--cacheinfo does not accept gitlink null sha1' '
52 (cd submodule && test_commit foo) &&
54 git rev-parse :submodule >expect &&
55 test_must_fail git update-index --cacheinfo 160000 $ZERO_OID submodule &&
56 git rev-parse :submodule >actual &&
57 test_cmp expect actual
60 test_expect_success
'--cacheinfo mode,sha1,path (new syntax)' '
62 git hash-object -w --stdin <file >expect &&
64 git update-index --add --cacheinfo 100644 "$(cat expect)" file &&
65 git rev-parse :file >actual &&
66 test_cmp expect actual &&
68 git update-index --add --verbose --cacheinfo "100644,$(cat expect),elif" >out &&
69 git rev-parse :elif >actual &&
70 test_cmp expect actual &&
72 cat >expect <<-\EOF &&
78 test_expect_success
'.lock files cleaned up' '
85 git config core.worktree ../../worktree &&
86 # --refresh triggers late setup_work_tree,
87 # the_index.cache_changed is zero, rollback_lock_file fails
88 git update-index --refresh --verbose >out &&
89 test_must_be_empty out &&
90 ! test -f .git/index.lock
94 test_expect_success
'--chmod=+x and chmod=-x in the same argument list' '
98 git update-index --verbose --chmod=+x A --chmod=-x B >out &&
99 cat >expect <<-\EOF &&
105 test_cmp expect out &&
107 cat >expect <<-EOF &&
108 100755 $EMPTY_BLOB 0 A
109 100644 $EMPTY_BLOB 0 B
111 git ls-files --stage A B >actual &&
112 test_cmp expect actual
115 test_expect_success
'--index-version' '
116 git commit --allow-empty -m snap &&
118 git rm -f -r --cached . &&
120 # The default index version is 2 --- update this test
121 # when you change it in the code
122 git update-index --show-index-version >actual &&
124 test_cmp expect actual &&
126 # The next test wants us to be using version 2
127 git update-index --index-version 2 &&
129 git update-index --index-version 4 --verbose >actual &&
130 echo "index-version: was 2, set to 4" >expect &&
131 test_cmp expect actual &&
133 git update-index --index-version 4 --verbose >actual &&
134 echo "index-version: was 4, set to 4" >expect &&
135 test_cmp expect actual &&
137 git update-index --index-version 2 --verbose >actual &&
138 echo "index-version: was 4, set to 2" >expect &&
139 test_cmp expect actual &&
141 # non-verbose should be silent
142 git update-index --index-version 4 >actual &&
143 test_must_be_empty actual