Skip to content

Commit f5114a4

Browse files
mhaggergitster
authored andcommitted
git-check-attr: Normalize paths
Normalize the path arguments (relative to the working tree root, if applicable) before looking up their attributes. This requires passing the prefix down the call chain. This fixes two test cases for different reasons: * "unnormalized paths" is fixed because the .gitattribute-file-seeking code is not confused into reading the top-level file twice. * "relative paths" is fixed because the canonical pathnames are passed to get_check_attr() or get_all_attrs(), allowing them to match the pathname patterns as expected. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0216af8 commit f5114a4

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

builtin/check-attr.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,26 @@ static void output_attr(int cnt, struct git_attr_check *check,
4141
}
4242
}
4343

44-
static void check_attr(int cnt, struct git_attr_check *check,
45-
const char *file)
44+
static void check_attr(const char *prefix, int cnt,
45+
struct git_attr_check *check, const char *file)
4646
{
47+
char *full_path =
48+
prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
4749
if (check != NULL) {
48-
if (git_check_attr(file, cnt, check))
50+
if (git_check_attr(full_path, cnt, check))
4951
die("git_check_attr died");
5052
output_attr(cnt, check, file);
5153
} else {
52-
if (git_all_attrs(file, &cnt, &check))
54+
if (git_all_attrs(full_path, &cnt, &check))
5355
die("git_all_attrs died");
5456
output_attr(cnt, check, file);
5557
free(check);
5658
}
59+
free(full_path);
5760
}
5861

59-
static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
62+
static void check_attr_stdin_paths(const char *prefix, int cnt,
63+
struct git_attr_check *check)
6064
{
6165
struct strbuf buf, nbuf;
6266
int line_termination = null_term_line ? 0 : '\n';
@@ -70,7 +74,7 @@ static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
7074
die("line is badly quoted");
7175
strbuf_swap(&buf, &nbuf);
7276
}
73-
check_attr(cnt, check, buf.buf);
77+
check_attr(prefix, cnt, check, buf.buf);
7478
maybe_flush_or_die(stdout, "attribute to stdout");
7579
}
7680
strbuf_release(&buf);
@@ -154,10 +158,10 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
154158
}
155159

156160
if (stdin_paths)
157-
check_attr_stdin_paths(cnt, check);
161+
check_attr_stdin_paths(prefix, cnt, check);
158162
else {
159163
for (i = filei; i < argc; i++)
160-
check_attr(cnt, check, argv[i]);
164+
check_attr(prefix, cnt, check, argv[i]);
161165
maybe_flush_or_die(stdout, "attribute to stdout");
162166
}
163167
return 0;

t/t0003-attributes.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test_expect_success 'attribute test' '
9393
9494
'
9595

96-
test_expect_failure 'unnormalized paths' '
96+
test_expect_success 'unnormalized paths' '
9797
9898
attr_check ./f f &&
9999
attr_check ./a/g a/g &&
@@ -102,7 +102,7 @@ test_expect_failure 'unnormalized paths' '
102102
103103
'
104104

105-
test_expect_failure 'relative paths' '
105+
test_expect_success 'relative paths' '
106106
107107
(cd a && attr_check ../f f) &&
108108
(cd a && attr_check f f) &&

0 commit comments

Comments
 (0)