]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2107-update-index-basic.sh
The third batch
[thirdparty/git.git] / t / t2107-update-index-basic.sh
CommitLineData
9c7c27ee
NTND
1#!/bin/sh
2
3test_description='basic update-index tests
4
5Tests for command-line parsing and basic operation.
6'
7
8. ./test-lib.sh
9
10test_expect_success 'update-index --nonsense fails' '
11 test_must_fail git update-index --nonsense 2>msg &&
9c7c27ee
NTND
12 test -s msg
13'
14
ac5ad864 15test_expect_success 'update-index --nonsense dumps usage' '
9c7c27ee 16 test_expect_code 129 git update-index --nonsense 2>err &&
6789275d 17 test_grep "[Uu]sage: git update-index" err
9c7c27ee
NTND
18'
19
20test_expect_success 'update-index -h with corrupt index' '
21 mkdir broken &&
22 (
23 cd broken &&
24 git init &&
25 >.git/index &&
26 test_expect_code 129 git update-index -h >usage 2>&1
27 ) &&
6789275d 28 test_grep "[Uu]sage: git update-index" broken/usage
9c7c27ee
NTND
29'
30
c8e1ee4f
JK
31test_expect_success '--cacheinfo complains of missing arguments' '
32 test_must_fail git update-index --cacheinfo
33'
34
4337b585
JK
35test_expect_success '--cacheinfo does not accept blob null sha1' '
36 echo content >file &&
37 git add file &&
38 git rev-parse :file >expect &&
624b8cfd 39 test_must_fail git update-index --verbose --cacheinfo 100644 $ZERO_OID file >out &&
4337b585 40 git rev-parse :file >actual &&
624b8cfd
DS
41 test_cmp expect actual &&
42
43 cat >expect <<-\EOF &&
44 add '\''file'\''
45 EOF
46 test_cmp expect out
4337b585
JK
47'
48
49test_expect_success '--cacheinfo does not accept gitlink null sha1' '
50 git init submodule &&
51 (cd submodule && test_commit foo) &&
52 git add submodule &&
53 git rev-parse :submodule >expect &&
8125a58b 54 test_must_fail git update-index --cacheinfo 160000 $ZERO_OID submodule &&
4337b585
JK
55 git rev-parse :submodule >actual &&
56 test_cmp expect actual
57'
58
ec160ae1
JH
59test_expect_success '--cacheinfo mode,sha1,path (new syntax)' '
60 echo content >file &&
61 git hash-object -w --stdin <file >expect &&
62
63 git update-index --add --cacheinfo 100644 "$(cat expect)" file &&
64 git rev-parse :file >actual &&
65 test_cmp expect actual &&
66
624b8cfd 67 git update-index --add --verbose --cacheinfo "100644,$(cat expect),elif" >out &&
ec160ae1 68 git rev-parse :elif >actual &&
624b8cfd
DS
69 test_cmp expect actual &&
70
71 cat >expect <<-\EOF &&
72 add '\''elif'\''
73 EOF
74 test_cmp expect out
ec160ae1
JH
75'
76
fa137f67
NTND
77test_expect_success '.lock files cleaned up' '
78 mkdir cleanup &&
79 (
80 cd cleanup &&
81 mkdir worktree &&
82 git init repo &&
83 cd repo &&
84 git config core.worktree ../../worktree &&
85 # --refresh triggers late setup_work_tree,
1ec40a83 86 # the_index.cache_changed is zero, rollback_lock_file fails
624b8cfd
DS
87 git update-index --refresh --verbose >out &&
88 test_must_be_empty out &&
fa137f67
NTND
89 ! test -f .git/index.lock
90 )
91'
92
22433ce4
TG
93test_expect_success '--chmod=+x and chmod=-x in the same argument list' '
94 >A &&
95 >B &&
96 git add A B &&
624b8cfd
DS
97 git update-index --verbose --chmod=+x A --chmod=-x B >out &&
98 cat >expect <<-\EOF &&
99 add '\''A'\''
100 chmod +x '\''A'\''
101 add '\''B'\''
102 chmod -x '\''B'\''
103 EOF
104 test_cmp expect out &&
105
31bdb1f2 106 cat >expect <<-EOF &&
107 100755 $EMPTY_BLOB 0 A
108 100644 $EMPTY_BLOB 0 B
22433ce4
TG
109 EOF
110 git ls-files --stage A B >actual &&
111 test_cmp expect actual
112'
113
606e088d
JH
114test_expect_success '--index-version' '
115 git commit --allow-empty -m snap &&
116 git reset --hard &&
117 git rm -f -r --cached . &&
118
119 # The default index version is 2 --- update this test
120 # when you change it in the code
121 git update-index --show-index-version >actual &&
122 echo 2 >expect &&
123 test_cmp expect actual &&
124
125 # The next test wants us to be using version 2
126 git update-index --index-version 2 &&
127
128 git update-index --index-version 4 --verbose >actual &&
129 echo "index-version: was 2, set to 4" >expect &&
130 test_cmp expect actual &&
131
132 git update-index --index-version 4 --verbose >actual &&
133 echo "index-version: was 4, set to 4" >expect &&
134 test_cmp expect actual &&
135
136 git update-index --index-version 2 --verbose >actual &&
137 echo "index-version: was 4, set to 2" >expect &&
138 test_cmp expect actual &&
139
140 # non-verbose should be silent
141 git update-index --index-version 4 >actual &&
142 test_must_be_empty actual
143'
144
9c7c27ee 145test_done