interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t1900-repo-info.sh

219 lines · 7112 bytes Raw Blame History
1#!/bin/sh
2
3test_description='test git repo-info'
4
5. ./test-lib.sh
6
7# Test whether a key-value pair is correctly returned
8#
9# Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
10#
11# Arguments:
12# label: the label of the test
13# init_command: a command which creates a repository
14# repo_name: the name of the repository that will be created in init_command
15# key: the key of the field that is being tested
16# expected_value: the value that the field should contain
17test_repo_info () {
18 label=$1
19 init_command=$2
20 repo_name=$3
21 key=$4
22 expected_value=$5
23
24 test_expect_success "setup: $label" '
25 eval "$init_command $repo_name"
26 '
27
28 test_expect_success "lines: $label" '
29 echo "$key=$expected_value" > expect &&
30 git -C "$repo_name" repo info "$key" >actual &&
31 test_cmp expect actual
32 '
33
34 test_expect_success "nul: $label" '
35 printf "%s\n%s\0" "$key" "$expected_value" >expect &&
36 git -C "$repo_name" repo info --format=nul "$key" >actual &&
37 test_cmp_bin expect actual
38 '
39}
40
41test_repo_info 'ref format files is retrieved correctly' \
42 'git init --ref-storage-format=files' 'format-files' 'references.storageFormat' 'files'
43
44test_repo_info 'ref format reftable is retrieved correctly' \
45 'git init --ref-storage-format=reftable' 'format-reftable' 'references.storageFormat' 'reftable'
46
47test_repo_info 'bare repository = false is retrieved correctly' \
48 'git init' 'nonbare' 'layout.bare' 'false'
49
50test_repo_info 'bare repository = true is retrieved correctly' \
51 'git init --bare' 'bare' 'layout.bare' 'true'
52
53test_repo_info 'shallow repository = false is retrieved correctly' \
54 'git init' 'nonshallow' 'layout.shallow' 'false'
55
56test_expect_success 'setup remote' '
57 git init remote &&
58 echo x >remote/x &&
59 git -C remote add x &&
60 git -C remote commit -m x
61'
62
63test_repo_info 'shallow repository = true is retrieved correctly' \
64 'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
65
66test_repo_info 'object.format = sha1 is retrieved correctly' \
67 'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
68
69test_repo_info 'object.format = sha256 is retrieved correctly' \
70 'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
71
72test_repo_info 'objects.storageFormat = files is retrieved correctly' \
73 'git init' 'objects-files' 'objects.storageFormat' 'files'
74
75test_expect_success 'values returned in order requested' '
76 cat >expect <<-\EOF &&
77 layout.bare=false
78 references.storageFormat=files
79 layout.bare=false
80 EOF
81 git init --ref-storage-format=files ordered &&
82 git -C ordered repo info layout.bare references.storageFormat layout.bare >actual &&
83 test_cmp expect actual
84'
85
86test_expect_success 'git-repo-info fails if an invalid key is requested' '
87 echo "error: key ${SQ}foo${SQ} not found" >expect &&
88 test_must_fail git repo info foo 2>actual &&
89 test_cmp expect actual
90'
91
92test_expect_success 'git-repo-info outputs data even if there is an invalid field' '
93 echo "references.storageFormat=$(test_detect_ref_format)" >expect &&
94 test_must_fail git repo info foo references.storageFormat bar >actual &&
95 test_cmp expect actual
96'
97
98test_expect_success 'git-repo-info aborts when requesting an invalid format' '
99 echo "fatal: invalid format ${SQ}foo${SQ}" >expect &&
100 test_must_fail git repo info --format=foo 2>actual &&
101 test_cmp expect actual
102'
103
104test_expect_success '-z uses nul-terminated format' '
105 printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
106 git repo info -z layout.bare layout.shallow >actual &&
107 test_cmp expected actual
108'
109
110test_expect_success 'git repo info uses the last requested format' '
111 echo "layout.bare=false" >expected &&
112 git repo info --format=nul -z --format=lines layout.bare >actual &&
113 test_cmp expected actual
114'
115
116test_expect_success 'git repo info --all and git repo info $(git repo info --keys) output the same data' '
117 git repo info $(git repo info --keys) >expect &&
118 git repo info --all >actual &&
119 test_cmp expect actual
120'
121
122test_expect_success 'git repo info --all <key> aborts' '
123 echo "fatal: --all and <key> cannot be used together" >expect &&
124 test_must_fail git repo info --all object.format 2>actual &&
125 test_cmp expect actual
126'
127
128test_expect_success 'git repo info --keys --format=nul uses nul-terminated output' '
129 git repo info --keys --format=lines >lines &&
130 lf_to_nul <lines >expect &&
131 git repo info --keys --format=nul >actual &&
132 test_cmp expect actual
133'
134
135test_expect_success 'git repo info --keys aborts when using --format other than lines or nul' '
136 echo "fatal: --keys can only be used with --format=lines or --format=nul" >expect &&
137 test_must_fail git repo info --keys --format=table 2>actual &&
138 test_cmp expect actual
139'
140
141test_expect_success 'git repo info --keys aborts when requesting keys' '
142 echo "fatal: --keys cannot be used with a <key> or --all" >expect &&
143 test_must_fail git repo info --keys --all 2>actual_all &&
144 test_must_fail git repo info --keys some.key 2>actual_key &&
145 test_cmp expect actual_all &&
146 test_cmp expect actual_key
147'
148
149test_expect_success 'git repo info --keys uses lines as its default output format' '
150 git repo info --keys --format=lines >expect &&
151 git repo info --keys >actual &&
152 test_cmp expect actual
153'
154
155test_expect_success 'git repo info -h shows only repo info usage' '
156 git repo info -h >actual &&
157 test_grep "git repo info" actual &&
158 test_grep ! "git repo structure" actual
159'
160
161# Helper function to test path keys in both absolute and relative formats.
162# $1: label for the test
163# $2: field_name (e.g., commondir)
164# $3: expected_dir (the directory name, e.g., .git or custom-common)
165# $4: init_command (extra setup like exporting env vars)
166test_repo_info_path () {
167 label=$1
168 field_name=$2
169 expected_dir=$3
170 init_command=$4
171
172 test_expect_success "absolute: $label" '
173 test_when_finished "rm -rf repo" &&
174 git init repo &&
175 (
176 mkdir -p repo/sub &&
177 cd repo/sub &&
178 ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
179 eval "$init_command" &&
180 echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect &&
181 git repo info "path.$field_name.absolute" >actual &&
182 test_cmp expect actual
183 )
184 '
185
186 test_expect_success "relative: $label" '
187 test_when_finished "rm -rf repo" &&
188 git init repo &&
189 (
190 mkdir -p repo/sub &&
191 cd repo/sub &&
192 ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
193 eval "$init_command" &&
194 echo "path.$field_name.relative=../$expected_dir" >expect &&
195 git repo info "path.$field_name.relative" >actual &&
196 test_cmp expect actual
197 )
198 '
199}
200
201test_repo_info_path 'commondir standard' 'commondir' '.git'
202
203test_repo_info_path 'commondir with GIT_COMMON_DIR and GIT_DIR' 'commondir' \
204 'custom-common' \
205 'GIT_COMMON_DIR="$ROOT/custom-common" && export GIT_COMMON_DIR &&
206 GIT_DIR="../.git" && export GIT_DIR &&
207 git init --bare "$ROOT/custom-common"'
208
209test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
210 '.git' \
211 'GIT_DIR="../.git" && export GIT_DIR'
212
213test_repo_info_path 'gitdir standard' 'gitdir' '.git'
214
215test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
216 '.git' \
217 'GIT_DIR="../.git" && export GIT_DIR'
218
219test_done