Skip to content

Commit 28b6821

Browse files
committed
Merge branch 'jc/check-attr-honor-working-tree'
"git check-attr" when (trying to) work on a repository with a working tree did not work well when the working tree was specified via --work-tree (and obviously with --git-dir). The command also works in a bare repository but it reads from the (possibly stale, irrelevant and/or nonexistent) index, which may need to be fixed to read from HEAD, but that is a completely separate issue. As a related tangent to this separate issue, we may want to also fix "check-ignore", which refuses to work in a bare repository, to also operate in a bare one. * jc/check-attr-honor-working-tree: check-attr: move to the top of working tree when in non-bare repository t0003: do not chdir the whole test process
2 parents 384364b + cdbf623 commit 28b6821

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

builtin/check-attr.c

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
102102
struct git_attr_check *check;
103103
int cnt, i, doubledash, filei;
104104

105+
if (!is_bare_repository())
106+
setup_work_tree();
107+
105108
git_config(git_default_config, NULL);
106109

107110
argc = parse_options(argc, argv, prefix, check_attr_options,

t/t0003-attributes.sh

+40-22
Original file line numberDiff line numberDiff line change
@@ -243,40 +243,58 @@ EOF
243243
test_line_count = 0 err
244244
'
245245

246+
test_expect_success 'using --git-dir and --work-tree' '
247+
mkdir unreal real &&
248+
git init real &&
249+
echo "file test=in-real" >real/.gitattributes &&
250+
(
251+
cd unreal &&
252+
attr_check file in-real "--git-dir ../real/.git --work-tree ../real"
253+
)
254+
'
255+
246256
test_expect_success 'setup bare' '
247-
git clone --bare . bare.git &&
248-
cd bare.git
257+
git clone --bare . bare.git
249258
'
250259

251260
test_expect_success 'bare repository: check that .gitattribute is ignored' '
252261
(
253-
echo "f test=f"
254-
echo "a/i test=a/i"
255-
) >.gitattributes &&
256-
attr_check f unspecified &&
257-
attr_check a/f unspecified &&
258-
attr_check a/c/f unspecified &&
259-
attr_check a/i unspecified &&
260-
attr_check subdir/a/i unspecified
262+
cd bare.git &&
263+
(
264+
echo "f test=f"
265+
echo "a/i test=a/i"
266+
) >.gitattributes &&
267+
attr_check f unspecified &&
268+
attr_check a/f unspecified &&
269+
attr_check a/c/f unspecified &&
270+
attr_check a/i unspecified &&
271+
attr_check subdir/a/i unspecified
272+
)
261273
'
262274

263275
test_expect_success 'bare repository: check that --cached honors index' '
264-
GIT_INDEX_FILE=../.git/index \
265-
git check-attr --cached --stdin --all <../stdin-all |
266-
sort >actual &&
267-
test_cmp ../specified-all actual
276+
(
277+
cd bare.git &&
278+
GIT_INDEX_FILE=../.git/index \
279+
git check-attr --cached --stdin --all <../stdin-all |
280+
sort >actual &&
281+
test_cmp ../specified-all actual
282+
)
268283
'
269284

270285
test_expect_success 'bare repository: test info/attributes' '
271286
(
272-
echo "f test=f"
273-
echo "a/i test=a/i"
274-
) >info/attributes &&
275-
attr_check f f &&
276-
attr_check a/f f &&
277-
attr_check a/c/f f &&
278-
attr_check a/i a/i &&
279-
attr_check subdir/a/i unspecified
287+
cd bare.git &&
288+
(
289+
echo "f test=f"
290+
echo "a/i test=a/i"
291+
) >info/attributes &&
292+
attr_check f f &&
293+
attr_check a/f f &&
294+
attr_check a/c/f f &&
295+
attr_check a/i a/i &&
296+
attr_check subdir/a/i unspecified
297+
)
280298
'
281299

282300
test_done

0 commit comments

Comments
 (0)