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
08ed0881
Commit
08ed0881
authored
2 years ago
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: isolate home directory separately from global config
parent
b7352a70
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
23 deletions
+66
-23
tests/clar_libgit2.c
+41
-11
tests/clar_libgit2.h
+13
-3
tests/ignore/path.c
+3
-3
tests/ignore/status.c
+2
-2
tests/online/clone.c
+6
-3
tests/remote/httpproxy.c
+1
-1
No files found.
tests/clar_libgit2.c
View file @
08ed0881
...
...
@@ -548,31 +548,61 @@ void clar__assert_equal_file(
(
size_t
)
expected_bytes
,
(
size_t
)
total_bytes
);
}
static
git_buf
_cl_restore_home
=
GIT_BUF_INIT
;
static
git_buf
_cl_restore_home
dir
=
GIT_BUF_INIT
;
void
cl_fake_home_cleanup
(
void
*
payload
)
void
cl_fake_home
dir
_cleanup
(
void
*
payload
)
{
GIT_UNUSED
(
payload
);
if
(
_cl_restore_home
.
ptr
)
{
if
(
_cl_restore_home
dir
.
ptr
)
{
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_SET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
_cl_restore_home
.
ptr
));
git_buf_dispose
(
&
_cl_restore_home
);
GIT_OPT_SET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
_cl_restore_home
dir
.
ptr
));
git_buf_dispose
(
&
_cl_restore_home
dir
);
}
}
void
cl_fake_home
(
void
)
void
cl_fake_home
dir
(
void
)
{
git_str
path
=
GIT_STR_INIT
;
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_GET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
&
_cl_restore_home
));
GIT_OPT_GET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
&
_cl_restore_home
dir
));
cl_set_cleanup
(
cl_fake_home_cleanup
,
NULL
);
cl_set_cleanup
(
cl_fake_home
dir
_cleanup
,
NULL
);
if
(
!
git_fs_path_exists
(
"home"
))
cl_must_pass
(
p_mkdir
(
"home"
,
0777
));
cl_git_pass
(
git_fs_path_prettify
(
&
path
,
"home"
,
NULL
));
if
(
!
git_fs_path_exists
(
"homedir"
))
cl_must_pass
(
p_mkdir
(
"homedir"
,
0777
));
cl_git_pass
(
git_fs_path_prettify
(
&
path
,
"homedir"
,
NULL
));
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_SET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
path
.
ptr
));
git_str_dispose
(
&
path
);
}
static
git_buf
_cl_restore_globalconfig
=
GIT_BUF_INIT
;
void
cl_fake_globalconfig_cleanup
(
void
*
payload
)
{
GIT_UNUSED
(
payload
);
if
(
_cl_restore_globalconfig
.
ptr
)
{
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_SET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
_cl_restore_globalconfig
.
ptr
));
git_buf_dispose
(
&
_cl_restore_globalconfig
);
}
}
void
cl_fake_globalconfig
(
void
)
{
git_str
path
=
GIT_STR_INIT
;
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_GET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
&
_cl_restore_globalconfig
));
cl_set_cleanup
(
cl_fake_globalconfig_cleanup
,
NULL
);
if
(
!
git_fs_path_exists
(
"globalconfig"
))
cl_must_pass
(
p_mkdir
(
"globalconfig"
,
0777
));
cl_git_pass
(
git_fs_path_prettify
(
&
path
,
"globalconfig"
,
NULL
));
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_SET_SEARCH_PATH
,
GIT_CONFIG_LEVEL_GLOBAL
,
path
.
ptr
));
git_str_dispose
(
&
path
);
...
...
This diff is collapsed.
Click to expand it.
tests/clar_libgit2.h
View file @
08ed0881
...
...
@@ -213,13 +213,23 @@ int cl_repo_get_bool(git_repository *repo, const char *cfg);
void
cl_repo_set_string
(
git_repository
*
repo
,
const
char
*
cfg
,
const
char
*
value
);
/* set up a fake "home" directory
and set libgit2 GLOBAL search path.
/* set up a fake "home" directory
*
* automatically configures cleanup function to restore the regular search
* path, although you can call it explicitly if you wish (with NULL).
*/
void
cl_fake_home
(
void
);
void
cl_fake_home_cleanup
(
void
*
);
void
cl_fake_homedir
(
void
);
void
cl_fake_homedir_cleanup
(
void
*
);
/*
* set up a fake directory for the libgit2 GLOBAL search path.
*
* automatically configures cleanup function to restore the regular search
* path, although you can call it explicitly if you wish (with NULL).
*/
void
cl_fake_globalconfig
(
void
);
void
cl_fake_globalconfig_cleanup
(
void
*
);
void
cl_sandbox_set_search_path_defaults
(
void
);
void
cl_sandbox_disable_ownership_validation
(
void
);
...
...
This diff is collapsed.
Click to expand it.
tests/ignore/path.c
View file @
08ed0881
...
...
@@ -290,10 +290,10 @@ void test_ignore_path__expand_tilde_to_homedir(void)
assert_is_ignored
(
false
,
"example.global_with_tilde"
);
cl_fake_
home
();
cl_fake_
globalconfig
();
/* construct fake home with fake global excludes */
cl_git_mkfile
(
"
home
/globalexclude"
,
"# found me
\n
*.global_with_tilde
\n
"
);
cl_git_mkfile
(
"
globalconfig
/globalexclude"
,
"# found me
\n
*.global_with_tilde
\n
"
);
cl_git_pass
(
git_repository_config
(
&
cfg
,
g_repo
));
cl_git_pass
(
git_config_set_string
(
cfg
,
"core.excludesfile"
,
"~/globalexclude"
));
...
...
@@ -305,7 +305,7 @@ void test_ignore_path__expand_tilde_to_homedir(void)
cl_git_pass
(
git_futils_rmdir_r
(
"home"
,
NULL
,
GIT_RMDIR_REMOVE_FILES
));
cl_fake_
home
_cleanup
(
NULL
);
cl_fake_
globalconfig
_cleanup
(
NULL
);
git_attr_cache_flush
(
g_repo
);
/* must reset to pick up change */
...
...
This diff is collapsed.
Click to expand it.
tests/ignore/status.c
View file @
08ed0881
...
...
@@ -385,8 +385,8 @@ void test_ignore_status__leading_slash_ignores(void)
make_test_data
(
test_repo_1
,
test_files_1
);
cl_fake_
home
();
cl_git_mkfile
(
"
home
/.gitignore"
,
"/ignore_me
\n
"
);
cl_fake_
globalconfig
();
cl_git_mkfile
(
"
globalconfig
/.gitignore"
,
"/ignore_me
\n
"
);
{
git_config
*
cfg
;
cl_git_pass
(
git_repository_config
(
&
cfg
,
g_repo
));
...
...
This diff is collapsed.
Click to expand it.
tests/online/clone.c
View file @
08ed0881
...
...
@@ -5,6 +5,7 @@
#include "remote.h"
#include "futils.h"
#include "refs.h"
#include "sysdir.h"
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
...
...
@@ -606,7 +607,7 @@ void test_online_clone__ssh_github(void)
if
(
!
_github_ssh_pubkey
||
!
_github_ssh_privkey
)
clar__skip
();
cl_fake_homedir
(
NULL
);
cl_fake_homedir
();
g_options
.
fetch_opts
.
callbacks
.
credentials
=
github_credentials
;
g_options
.
fetch_opts
.
callbacks
.
certificate_check
=
succeed_certificate_check
;
...
...
@@ -647,7 +648,7 @@ void test_online_clone__ssh_certcheck_accepts_unknown(void)
if
(
!
_github_ssh_pubkey
||
!
_github_ssh_privkey
)
clar__skip
();
cl_fake_homedir
(
NULL
);
cl_fake_homedir
();
g_options
.
fetch_opts
.
callbacks
.
credentials
=
github_credentials
;
...
...
@@ -678,7 +679,9 @@ void test_online_clone__ssh_certcheck_override_knownhosts(void)
g_options
.
fetch_opts
.
callbacks
.
credentials
=
github_credentials
;
cl_fake_homedir
(
&
knownhostsfile
);
cl_fake_homedir
();
cl_git_pass
(
git_sysdir_find_homedir
(
&
knownhostsfile
));
cl_git_pass
(
git_str_joinpath
(
&
knownhostsfile
,
knownhostsfile
.
ptr
,
".ssh"
));
cl_git_pass
(
p_mkdir
(
knownhostsfile
.
ptr
,
0777
));
...
...
This diff is collapsed.
Click to expand it.
tests/remote/httpproxy.c
View file @
08ed0881
...
...
@@ -132,7 +132,7 @@ static void assert_global_config_match(const char *config, const char *expected)
void
test_remote_httpproxy__config_overrides_detached_remote
(
void
)
{
cl_fake_
home
();
cl_fake_
globalconfig
();
assert_global_config_match
(
NULL
,
NULL
);
assert_global_config_match
(
"http.proxy"
,
"http://localhost:1/"
);
...
...
This diff is collapsed.
Click to expand it.
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