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
e0568621
Commit
e0568621
authored
Jul 19, 2017
by
Edward Thomson
Committed by
GitHub
Jul 19, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4250 from pks-t/pks/config-file-iteration
Configuration file fixes with includes
parents
a94a5402
1b329089
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
42 deletions
+55
-42
src/config_file.c
+0
-0
tests/config/include.c
+55
-42
No files found.
src/config_file.c
View file @
e0568621
This diff is collapsed.
Click to expand it.
tests/config/include.c
View file @
e0568621
...
...
@@ -2,25 +2,31 @@
#include "buffer.h"
#include "fileops.h"
void
test_config_include__relative
(
void
)
static
git_config
*
cfg
;
static
git_buf
buf
;
void
test_config_include__initialize
(
void
)
{
cfg
=
NULL
;
git_buf_init
(
&
buf
,
0
);
}
void
test_config_include__cleanup
(
void
)
{
git_config
*
cfg
;
git_buf
buf
=
GIT_BUF_INIT
;
git_config_free
(
cfg
);
git_buf_free
(
&
buf
);
}
void
test_config_include__relative
(
void
)
{
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
cl_fixture
(
"config/config-include"
)));
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar.baz"
));
cl_assert_equal_s
(
"huzzah"
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
git_config_free
(
cfg
);
}
void
test_config_include__absolute
(
void
)
{
git_config
*
cfg
;
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_pass
(
git_buf_printf
(
&
buf
,
"[include]
\n
path = %s/config-included"
,
cl_fixture
(
"config"
)));
cl_git_mkfile
(
"config-include-absolute"
,
git_buf_cstr
(
&
buf
));
...
...
@@ -29,16 +35,10 @@ void test_config_include__absolute(void)
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar.baz"
));
cl_assert_equal_s
(
"huzzah"
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
git_config_free
(
cfg
);
}
void
test_config_include__homedir
(
void
)
{
git_config
*
cfg
;
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_SET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
cl_fixture
(
"config"
)));
cl_git_mkfile
(
"config-include-homedir"
,
"[include]
\n
path = ~/config-included"
);
...
...
@@ -47,18 +47,12 @@ void test_config_include__homedir(void)
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar.baz"
));
cl_assert_equal_s
(
"huzzah"
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
git_config_free
(
cfg
);
cl_sandbox_set_search_path_defaults
();
}
/* We need to pretend that the variables were defined where the file was included */
void
test_config_include__ordering
(
void
)
{
git_config
*
cfg
;
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_mkfile
(
"included"
,
"[foo
\"
bar
\"
]
\n
baz = hurrah
\n
frotz = hiya"
);
cl_git_mkfile
(
"including"
,
"[foo
\"
bar
\"
]
\n
frotz = hello
\n
"
...
...
@@ -72,16 +66,11 @@ void test_config_include__ordering(void)
git_buf_clear
(
&
buf
);
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar.baz"
));
cl_assert_equal_s
(
"huzzah"
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
git_config_free
(
cfg
);
}
/* We need to pretend that the variables were defined where the file was included */
void
test_config_include__depth
(
void
)
{
git_config
*
cfg
;
cl_git_mkfile
(
"a"
,
"[include]
\n
path = b"
);
cl_git_mkfile
(
"b"
,
"[include]
\n
path = a"
);
...
...
@@ -93,9 +82,6 @@ void test_config_include__depth(void)
void
test_config_include__missing
(
void
)
{
git_config
*
cfg
;
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_mkfile
(
"including"
,
"[include]
\n
path = nonexistentfile
\n
[foo]
\n
bar = baz"
);
giterr_clear
();
...
...
@@ -103,16 +89,10 @@ void test_config_include__missing(void)
cl_assert
(
giterr_last
()
==
NULL
);
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar"
));
cl_assert_equal_s
(
"baz"
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
git_config_free
(
cfg
);
}
void
test_config_include__missing_homedir
(
void
)
{
git_config
*
cfg
;
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_SET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
cl_fixture
(
"config"
)));
cl_git_mkfile
(
"including"
,
"[include]
\n
path = ~/.nonexistentfile
\n
[foo]
\n
bar = baz"
);
...
...
@@ -122,17 +102,12 @@ void test_config_include__missing_homedir(void)
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar"
));
cl_assert_equal_s
(
"baz"
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
git_config_free
(
cfg
);
cl_sandbox_set_search_path_defaults
();
}
#define replicate10(s) s s s s s s s s s s
void
test_config_include__depth2
(
void
)
{
git_config
*
cfg
;
git_buf
buf
=
GIT_BUF_INIT
;
const
char
*
content
=
"[include]
\n
"
replicate10
(
replicate10
(
"path=bottom
\n
"
));
cl_git_mkfile
(
"top-level"
,
"[include]
\n
path = middle
\n
[foo]
\n
bar = baz"
);
...
...
@@ -147,7 +122,45 @@ void test_config_include__depth2(void)
git_buf_clear
(
&
buf
);
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar2"
));
cl_assert_equal_s
(
"baz2"
,
git_buf_cstr
(
&
buf
));
}
git_buf_free
(
&
buf
);
git_config_free
(
cfg
);
void
test_config_include__removing_include_removes_values
(
void
)
{
cl_git_mkfile
(
"top-level"
,
"[include]
\n
path = included"
);
cl_git_mkfile
(
"included"
,
"[foo]
\n
bar = value"
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"top-level"
));
cl_git_mkfile
(
"top-level"
,
""
);
cl_git_fail
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar"
));
}
void
test_config_include__rewriting_include_refreshes_values
(
void
)
{
cl_git_mkfile
(
"top-level"
,
"[include]
\n
path = first
\n
[include]
\n
path = second"
);
cl_git_mkfile
(
"first"
,
"[first]
\n
foo = bar"
);
cl_git_mkfile
(
"second"
,
"[second]
\n
foo = bar"
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"top-level"
));
cl_git_mkfile
(
"first"
,
"[first]
\n
other = value"
);
cl_git_fail
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"foo.bar"
));
cl_git_pass
(
git_config_get_string_buf
(
&
buf
,
cfg
,
"first.other"
));
cl_assert_equal_s
(
buf
.
ptr
,
"value"
);
}
void
test_config_include__included_variables_cannot_be_deleted
(
void
)
{
cl_git_mkfile
(
"top-level"
,
"[include]
\n
path = included
\n
"
);
cl_git_mkfile
(
"included"
,
"[foo]
\n
bar = value"
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"top-level"
));
cl_git_fail
(
git_config_delete_entry
(
cfg
,
"foo.bar"
));
}
void
test_config_include__included_variables_cannot_be_modified
(
void
)
{
cl_git_mkfile
(
"top-level"
,
"[include]
\n
path = included
\n
"
);
cl_git_mkfile
(
"included"
,
"[foo]
\n
bar = value"
);
cl_git_pass
(
git_config_open_ondisk
(
&
cfg
,
"top-level"
));
cl_git_fail
(
git_config_set_string
(
cfg
,
"foo.bar"
,
"other-value"
));
}
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