Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e50d138e
Unverified
Commit
e50d138e
authored
Jun 06, 2019
by
Edward Thomson
Committed by
GitHub
Jun 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5095 from pks-t/pks/ignore-escaped-trailing-space
ignore: handle escaped trailing whitespace
parents
4de6eb5b
d81e7866
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
3 deletions
+65
-3
src/attr_file.c
+19
-3
tests/attr/ignore.c
+46
-0
No files found.
src/attr_file.c
View file @
e50d138e
...
@@ -560,6 +560,21 @@ void git_attr_path__free(git_attr_path *info)
...
@@ -560,6 +560,21 @@ void git_attr_path__free(git_attr_path *info)
*/
*/
/*
/*
* Determine the length of trailing spaces. Escaped spaces do not count as
* trailing whitespace.
*/
static
size_t
trailing_space_length
(
const
char
*
p
,
size_t
len
)
{
size_t
n
;
for
(
n
=
len
;
n
;
n
--
)
{
if
((
p
[
n
-
1
]
!=
' '
&&
p
[
n
-
1
]
!=
'\t'
)
||
(
n
>
1
&&
p
[
n
-
2
]
==
'\\'
))
break
;
}
return
len
-
n
;
}
/*
* This will return 0 if the spec was filled out,
* This will return 0 if the spec was filled out,
* GIT_ENOTFOUND if the fnmatch does not require matching, or
* GIT_ENOTFOUND if the fnmatch does not require matching, or
* another error code there was an actual problem.
* another error code there was an actual problem.
...
@@ -647,9 +662,10 @@ int git_attr_fnmatch__parse(
...
@@ -647,9 +662,10 @@ int git_attr_fnmatch__parse(
return
GIT_ENOTFOUND
;
return
GIT_ENOTFOUND
;
/* Remove trailing spaces. */
/* Remove trailing spaces. */
while
(
pattern
[
spec
->
length
-
1
]
==
' '
||
pattern
[
spec
->
length
-
1
]
==
'\t'
)
spec
->
length
-=
trailing_space_length
(
pattern
,
spec
->
length
);
if
(
--
spec
->
length
==
0
)
return
GIT_ENOTFOUND
;
if
(
spec
->
length
==
0
)
return
GIT_ENOTFOUND
;
if
(
pattern
[
spec
->
length
-
1
]
==
'/'
)
{
if
(
pattern
[
spec
->
length
-
1
]
==
'/'
)
{
spec
->
length
--
;
spec
->
length
--
;
...
...
tests/attr/ignore.c
View file @
e50d138e
...
@@ -61,6 +61,52 @@ void test_attr_ignore__ignore_space(void)
...
@@ -61,6 +61,52 @@ void test_attr_ignore__ignore_space(void)
assert_is_ignored
(
true
,
"NewFolder/NewFolder/File.txt"
);
assert_is_ignored
(
true
,
"NewFolder/NewFolder/File.txt"
);
}
}
void
test_attr_ignore__intermittent_space
(
void
)
{
cl_git_rewritefile
(
"attr/.gitignore"
,
"foo bar
\n
"
);
assert_is_ignored
(
false
,
"foo"
);
assert_is_ignored
(
false
,
"bar"
);
assert_is_ignored
(
true
,
"foo bar"
);
}
void
test_attr_ignore__trailing_space
(
void
)
{
cl_git_rewritefile
(
"attr/.gitignore"
,
"foo
\n
"
"bar
\n
"
);
assert_is_ignored
(
true
,
"foo"
);
assert_is_ignored
(
false
,
"foo "
);
assert_is_ignored
(
true
,
"bar"
);
assert_is_ignored
(
false
,
"bar "
);
assert_is_ignored
(
false
,
"bar "
);
}
void
test_attr_ignore__escaped_trailing_spaces
(
void
)
{
cl_git_rewritefile
(
"attr/.gitignore"
,
"foo
\\
\n
"
"bar
\\
\\
\n
"
"baz
\\
\n
"
"qux
\\
\n
"
);
assert_is_ignored
(
false
,
"foo"
);
assert_is_ignored
(
true
,
"foo "
);
assert_is_ignored
(
false
,
"bar"
);
assert_is_ignored
(
false
,
"bar "
);
assert_is_ignored
(
true
,
"bar "
);
assert_is_ignored
(
true
,
"baz "
);
assert_is_ignored
(
false
,
"baz "
);
assert_is_ignored
(
true
,
"qux "
);
assert_is_ignored
(
false
,
"qux"
);
assert_is_ignored
(
false
,
"qux "
);
}
void
test_attr_ignore__ignore_dir
(
void
)
void
test_attr_ignore__ignore_dir
(
void
)
{
{
cl_git_rewritefile
(
"attr/.gitignore"
,
"dir/
\n
"
);
cl_git_rewritefile
(
"attr/.gitignore"
,
"dir/
\n
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment