mirror of
https://github.com/git/git
synced 2024-10-30 04:01:21 +00:00
dir: ignore trailing spaces in exclude patterns
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
16402b992e
commit
7e2e4b37d3
3 changed files with 19 additions and 13 deletions
|
@ -77,6 +77,9 @@ PATTERN FORMAT
|
||||||
Put a backslash ("`\`") in front of the first hash for patterns
|
Put a backslash ("`\`") in front of the first hash for patterns
|
||||||
that begin with a hash.
|
that begin with a hash.
|
||||||
|
|
||||||
|
- Trailing spaces are ignored unless they are quoted with backlash
|
||||||
|
("`\`").
|
||||||
|
|
||||||
- An optional prefix "`!`" which negates the pattern; any
|
- An optional prefix "`!`" which negates the pattern; any
|
||||||
matching file excluded by a previous pattern will become
|
matching file excluded by a previous pattern will become
|
||||||
included again. If a negated pattern matches, this will
|
included again. If a negated pattern matches, this will
|
||||||
|
|
21
dir.c
21
dir.c
|
@ -463,20 +463,23 @@ void clear_exclude_list(struct exclude_list *el)
|
||||||
el->filebuf = NULL;
|
el->filebuf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_trailing_spaces(const char *fname, char *buf)
|
static void trim_trailing_spaces(char *buf)
|
||||||
{
|
{
|
||||||
int i, last_space = -1, len = strlen(buf);
|
int i, last_space = -1, nr_spaces, len = strlen(buf);
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
if (buf[i] == '\\')
|
if (buf[i] == '\\')
|
||||||
i++;
|
i++;
|
||||||
else if (buf[i] == ' ')
|
else if (buf[i] == ' ') {
|
||||||
last_space = i;
|
if (last_space == -1) {
|
||||||
else
|
last_space = i;
|
||||||
|
nr_spaces = 1;
|
||||||
|
} else
|
||||||
|
nr_spaces++;
|
||||||
|
} else
|
||||||
last_space = -1;
|
last_space = -1;
|
||||||
|
|
||||||
if (last_space == len - 1)
|
if (last_space != -1 && last_space + nr_spaces == len)
|
||||||
warning(_("%s: trailing spaces in '%s'. Please quote or remove them."),
|
buf[last_space] = '\0';
|
||||||
fname, buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int add_excludes_from_file_to_list(const char *fname,
|
int add_excludes_from_file_to_list(const char *fname,
|
||||||
|
@ -530,7 +533,7 @@ int add_excludes_from_file_to_list(const char *fname,
|
||||||
if (buf[i] == '\n') {
|
if (buf[i] == '\n') {
|
||||||
if (entry != buf + i && entry[0] != '#') {
|
if (entry != buf + i && entry[0] != '#') {
|
||||||
buf[i - (i && buf[i-1] == '\r')] = 0;
|
buf[i - (i && buf[i-1] == '\r')] = 0;
|
||||||
check_trailing_spaces(fname, entry);
|
trim_trailing_spaces(entry);
|
||||||
add_exclude(entry, base, baselen, el, lineno);
|
add_exclude(entry, base, baselen, el, lineno);
|
||||||
}
|
}
|
||||||
lineno++;
|
lineno++;
|
||||||
|
|
|
@ -779,18 +779,18 @@ test_expect_success PIPE 'streaming support for --stdin' '
|
||||||
#
|
#
|
||||||
# test whitespace handling
|
# test whitespace handling
|
||||||
|
|
||||||
test_expect_success 'trailing whitespace is warned' '
|
test_expect_success 'trailing whitespace is ignored' '
|
||||||
mkdir whitespace &&
|
mkdir whitespace &&
|
||||||
>whitespace/trailing &&
|
>whitespace/trailing &&
|
||||||
>whitespace/untracked &&
|
>whitespace/untracked &&
|
||||||
echo "whitespace/trailing " >ignore &&
|
echo "whitespace/trailing " >ignore &&
|
||||||
cat >expect <<EOF &&
|
cat >expect <<EOF &&
|
||||||
whitespace/trailing
|
|
||||||
whitespace/untracked
|
whitespace/untracked
|
||||||
EOF
|
EOF
|
||||||
|
: >err.expect &&
|
||||||
git ls-files -o -X ignore whitespace >actual 2>err &&
|
git ls-files -o -X ignore whitespace >actual 2>err &&
|
||||||
grep "ignore:.*'\''whitespace/trailing '\''" err &&
|
test_cmp expect actual &&
|
||||||
test_cmp expect actual
|
test_cmp err.expect err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'quoting allows trailing whitespace' '
|
test_expect_success 'quoting allows trailing whitespace' '
|
||||||
|
|
Loading…
Reference in a new issue