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
db3572b7
Unverified
Commit
db3572b7
authored
Jan 06, 2022
by
Edward Thomson
Committed by
GitHub
Jan 06, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6165 from libgit2/ethomson/includeif
config: handle empty conditional in includeIf
parents
0bf67234
715bfe10
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
src/config_file.c
+14
-3
tests/config/conditionals.c
+25
-0
No files found.
src/config_file.c
View file @
db3572b7
...
@@ -724,14 +724,25 @@ static const struct {
...
@@ -724,14 +724,25 @@ static const struct {
static
int
parse_conditional_include
(
config_file_parse_data
*
parse_data
,
const
char
*
section
,
const
char
*
file
)
static
int
parse_conditional_include
(
config_file_parse_data
*
parse_data
,
const
char
*
section
,
const
char
*
file
)
{
{
char
*
condition
;
char
*
condition
;
size_t
i
;
size_t
section_len
,
i
;
int
error
=
0
,
matches
;
int
error
=
0
,
matches
;
if
(
!
parse_data
->
repo
||
!
file
)
if
(
!
parse_data
->
repo
||
!
file
)
return
0
;
return
0
;
condition
=
git__substrdup
(
section
+
strlen
(
"includeIf."
),
section_len
=
strlen
(
section
);
strlen
(
section
)
-
strlen
(
"includeIf."
)
-
strlen
(
".path"
));
/*
* We checked that the string starts with `includeIf.` and ends
* in `.path` to get here. Make sure it consists of more.
*/
if
(
section_len
<
CONST_STRLEN
(
"includeIf."
)
+
CONST_STRLEN
(
".path"
))
return
0
;
condition
=
git__substrdup
(
section
+
CONST_STRLEN
(
"includeIf."
),
section_len
-
CONST_STRLEN
(
"includeIf."
)
-
CONST_STRLEN
(
".path"
));
GIT_ERROR_CHECK_ALLOC
(
condition
);
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
conditions
);
i
++
)
{
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
conditions
);
i
++
)
{
if
(
git__prefixcmp
(
condition
,
conditions
[
i
].
prefix
))
if
(
git__prefixcmp
(
condition
,
conditions
[
i
].
prefix
))
...
...
tests/config/conditionals.c
View file @
db3572b7
...
@@ -148,3 +148,28 @@ void test_config_conditionals__onbranch(void)
...
@@ -148,3 +148,28 @@ void test_config_conditionals__onbranch(void)
assert_condition_includes
(
"onbranch"
,
"dir*"
,
false
);
assert_condition_includes
(
"onbranch"
,
"dir*"
,
false
);
assert_condition_includes
(
"onbranch"
,
"dir/*"
,
false
);
assert_condition_includes
(
"onbranch"
,
"dir/*"
,
false
);
}
}
void
test_config_conditionals__empty
(
void
)
{
git_buf
value
=
GIT_BUF_INIT
;
git_str
buf
=
GIT_STR_INIT
;
git_config
*
cfg
;
cl_git_pass
(
git_str_puts
(
&
buf
,
"[includeIf]
\n
"
));
cl_git_pass
(
git_str_puts
(
&
buf
,
"path = other
\n
"
));
cl_git_mkfile
(
"empty_standard_repo/.git/config"
,
buf
.
ptr
);
cl_git_mkfile
(
"empty_standard_repo/.git/other"
,
"[foo]
\n
bar=baz
\n
"
);
_repo
=
cl_git_sandbox_reopen
();
git_str_dispose
(
&
buf
);
cl_git_pass
(
git_repository_config
(
&
cfg
,
_repo
));
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_config_get_string_buf
(
&
value
,
cfg
,
"foo.bar"
));
git_str_dispose
(
&
buf
);
git_buf_dispose
(
&
value
);
git_config_free
(
cfg
);
}
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