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
6640266e
Commit
6640266e
authored
Sep 18, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #398 from carlosmn/config-autohome
git_repository_config: open global config file automatically
parents
71b84c63
f9d4b0c3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
23 deletions
+58
-23
include/git2/repository.h
+7
-12
src/repository.c
+3
-5
tests/t15-config.c
+16
-2
tests/t16-remotes.c
+32
-4
No files found.
include/git2/repository.h
View file @
6640266e
...
...
@@ -284,13 +284,10 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
/**
* Retrieve the relevant configuration for a repository
*
* By default he returned `git_config` instance contains a single
* configuration file, the `.gitconfig' file that may be found
* inside the repository.
*
* If the `user_config_path` variable is not NULL, the given config
* file will be also included in the configuration set. On most UNIX
* systems, this file may be found on `$HOME/.gitconfig`.
* By default he returned `git_config` instance contains the two most
* common configuration files, the `config' file that may be found
* inside the repository, and the `$HOME/.gitconfig' "global"
* configuration file.
*
* If the `system_config_path` variable is not NULL, the given config
* file will be also included in the configuration set. On most UNIX
...
...
@@ -300,23 +297,21 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
* order:
*
* - Repository configuration file
* -
User
configuration file
* -
Global
configuration file
* - System configuration file
*
* The method will fail if any of the passed
config files cannot be
*
found
or accessed.
* The method will fail if any of the passed
system config file found
* or accessed.
*
* The returned `git_config` instance is owned by the caller and must
* be manually free'd once it's no longer on use.
*
* @param out the repository's configuration
* @param repo the repository for which to get the config
* @param user_config_path Path to the user config file
* @param system_config_path Path to the system-wide config file
*/
GIT_EXTERN
(
int
)
git_repository_config
(
git_config
**
out
,
git_repository
*
repo
,
const
char
*
user_config_path
,
const
char
*
system_config_path
);
/** @} */
...
...
src/repository.c
View file @
6640266e
...
...
@@ -270,7 +270,6 @@ cleanup:
int
git_repository_config
(
git_config
**
out
,
git_repository
*
repo
,
const
char
*
user_config_path
,
const
char
*
system_config_path
)
{
char
config_path
[
GIT_PATH_MAX
];
...
...
@@ -287,10 +286,9 @@ int git_repository_config(
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
if
(
user_config_path
!=
NULL
)
{
error
=
git_config_add_file_ondisk
(
*
out
,
user_config_path
,
2
);
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
error
=
git_config_find_global
(
config_path
);
if
(
error
==
GIT_SUCCESS
)
{
error
=
git_config_add_file_ondisk
(
*
out
,
config_path
,
2
);
}
if
(
system_config_path
!=
NULL
)
{
...
...
tests/t15-config.c
View file @
6640266e
...
...
@@ -214,26 +214,40 @@ BEGIN_TEST(config10, "a repo's config overrides the global config")
git_repository
*
repo
;
git_config
*
cfg
;
int
version
;
char
*
old_home
;
old_home
=
git__strdup
(
getenv
(
"HOME"
));
setenv
(
"HOME"
,
CONFIG_BASE
,
1
);
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
CONFIG_BASE
"/.gitconfig"
,
NULL
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
));
must_pass
(
git_config_get_int
(
cfg
,
"core.repositoryformatversion"
,
&
version
));
must_be_true
(
version
==
0
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
setenv
(
"HOME"
,
old_home
,
1
);
free
(
old_home
);
END_TEST
BEGIN_TEST
(
config11
,
"fall back to the global config"
)
git_repository
*
repo
;
git_config
*
cfg
;
int
num
;
char
*
old_home
;
old_home
=
git__strdup
(
getenv
(
"HOME"
));
setenv
(
"HOME"
,
CONFIG_BASE
,
1
);
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
CONFIG_BASE
"/.gitconfig"
,
NULL
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
));
must_pass
(
git_config_get_int
(
cfg
,
"core.something"
,
&
num
));
must_be_true
(
num
==
2
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
setenv
(
"HOME"
,
old_home
,
1
);
free
(
old_home
);
END_TEST
BEGIN_TEST
(
config12
,
"delete a value"
)
...
...
tests/t16-remotes.c
View file @
6640266e
...
...
@@ -31,9 +31,13 @@ BEGIN_TEST(remotes0, "remote parsing works")
git_remote
*
remote
;
git_repository
*
repo
;
git_config
*
cfg
;
char
*
old_home
;
old_home
=
git__strdup
(
getenv
(
"HOME"
));
setenv
(
"HOME"
,
"/dev/null"
,
1
);
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
,
NULL
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
));
must_pass
(
git_remote_get
(
&
remote
,
cfg
,
"test"
));
must_be_true
(
!
strcmp
(
git_remote_name
(
remote
),
"test"
));
must_be_true
(
!
strcmp
(
git_remote_url
(
remote
),
"git://github.com/libgit2/libgit2"
));
...
...
@@ -41,6 +45,9 @@ BEGIN_TEST(remotes0, "remote parsing works")
git_remote_free
(
remote
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
setenv
(
"HOME"
,
old_home
,
1
);
free
(
old_home
);
END_TEST
BEGIN_TEST
(
refspec0
,
"remote with refspec works"
)
...
...
@@ -48,9 +55,13 @@ BEGIN_TEST(refspec0, "remote with refspec works")
git_repository
*
repo
;
git_config
*
cfg
;
const
git_refspec
*
refspec
=
NULL
;
char
*
old_home
;
old_home
=
git__strdup
(
getenv
(
"HOME"
));
setenv
(
"HOME"
,
"/dev/null"
,
1
);
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
,
NULL
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
));
must_pass
(
git_remote_get
(
&
remote
,
cfg
,
"test"
));
refspec
=
git_remote_fetchspec
(
remote
);
must_be_true
(
refspec
!=
NULL
);
...
...
@@ -59,6 +70,9 @@ BEGIN_TEST(refspec0, "remote with refspec works")
git_remote_free
(
remote
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
setenv
(
"HOME"
,
old_home
,
1
);
free
(
old_home
);
END_TEST
BEGIN_TEST
(
refspec1
,
"remote fnmatch works as expected"
)
...
...
@@ -66,9 +80,13 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected")
git_repository
*
repo
;
git_config
*
cfg
;
const
git_refspec
*
refspec
=
NULL
;
char
*
old_home
;
old_home
=
git__strdup
(
getenv
(
"HOME"
));
setenv
(
"HOME"
,
"/dev/null"
,
1
);
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
,
NULL
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
));
must_pass
(
git_remote_get
(
&
remote
,
cfg
,
"test"
));
refspec
=
git_remote_fetchspec
(
remote
);
must_be_true
(
refspec
!=
NULL
);
...
...
@@ -77,6 +95,9 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected")
git_remote_free
(
remote
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
setenv
(
"HOME"
,
old_home
,
1
);
free
(
old_home
);
END_TEST
BEGIN_TEST
(
refspec2
,
"refspec transform"
)
...
...
@@ -85,9 +106,13 @@ BEGIN_TEST(refspec2, "refspec transform")
git_config
*
cfg
;
const
git_refspec
*
refspec
=
NULL
;
char
ref
[
1024
]
=
{
0
};
char
*
old_home
;
old_home
=
git__strdup
(
getenv
(
"HOME"
));
setenv
(
"HOME"
,
"/dev/null"
,
1
);
must_pass
(
git_repository_open
(
&
repo
,
REPOSITORY_FOLDER
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
,
NULL
));
must_pass
(
git_repository_config
(
&
cfg
,
repo
,
NULL
));
must_pass
(
git_remote_get
(
&
remote
,
cfg
,
"test"
));
refspec
=
git_remote_fetchspec
(
remote
);
must_be_true
(
refspec
!=
NULL
);
...
...
@@ -96,6 +121,9 @@ BEGIN_TEST(refspec2, "refspec transform")
git_remote_free
(
remote
);
git_config_free
(
cfg
);
git_repository_free
(
repo
);
setenv
(
"HOME"
,
old_home
,
1
);
free
(
old_home
);
END_TEST
BEGIN_SUITE
(
remotes
)
...
...
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