Sync with 'master'
[alt-git.git] / t / t2107-update-index-basic.sh
blobf0eab13f96a6b946f982db2543112cc7467d857d
1 #!/bin/sh
3 test_description='basic update-index tests
5 Tests for command-line parsing and basic operation.
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'update-index --nonsense fails' '
12 test_must_fail git update-index --nonsense 2>msg &&
13 test -s 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' '
22 mkdir broken &&
24 cd broken &&
25 git init &&
26 >.git/index &&
27 test_expect_code 129 git update-index -h >usage 2>&1
28 ) &&
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' '
37 echo content >file &&
38 git add file &&
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 &&
45 add '\''file'\''
46 EOF
47 test_cmp expect out
50 test_expect_success '--cacheinfo does not accept gitlink null sha1' '
51 git init submodule &&
52 (cd submodule && test_commit foo) &&
53 git add submodule &&
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)' '
61 echo content >file &&
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 &&
73 add '\''elif'\''
74 EOF
75 test_cmp expect out
78 test_expect_success '.lock files cleaned up' '
79 mkdir cleanup &&
81 cd cleanup &&
82 mkdir worktree &&
83 git init repo &&
84 cd repo &&
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' '
95 >A &&
96 >B &&
97 git add A B &&
98 git update-index --verbose --chmod=+x A --chmod=-x B >out &&
99 cat >expect <<-\EOF &&
100 add '\''A'\''
101 chmod +x '\''A'\''
102 add '\''B'\''
103 chmod -x '\''B'\''
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 &&
117 git reset --hard &&
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 &&
123 echo 2 >expect &&
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
146 test_done