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
eb41276f
Commit
eb41276f
authored
Sep 16, 2021
by
Laurence McGlashan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow proxy options when connecting with a detached remote.
parent
7d195b9c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
4 deletions
+56
-4
src/remote.c
+15
-3
tests/remote/httpproxy.c
+41
-1
No files found.
src/remote.c
View file @
eb41276f
...
...
@@ -888,11 +888,21 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
git_buf
buf
=
GIT_BUF_INIT
;
git_net_url
lookup_url
=
GIT_NET_URL_INIT
;
int
error
;
int
cleanup_config
=
0
;
if
((
error
=
git_net_url_dup
(
&
lookup_url
,
url
))
<
0
||
(
error
=
git_repository_config__weakptr
(
&
cfg
,
remote
->
repo
))
<
0
)
if
((
error
=
git_net_url_dup
(
&
lookup_url
,
url
))
<
0
)
goto
done
;
if
(
remote
->
repo
)
{
if
((
error
=
git_repository_config__weakptr
(
&
cfg
,
remote
->
repo
))
<
0
)
goto
done
;
}
else
{
if
((
error
=
git_config_open_default
(
&
cfg
))
<
0
)
goto
done
;
cleanup_config
=
1
;
}
/* remote.<name>.proxy config setting */
if
(
remote
->
name
&&
remote
->
name
[
0
])
{
git_buf_clear
(
&
buf
);
...
...
@@ -922,6 +932,9 @@ static int http_proxy_config(char **out, git_remote *remote, git_net_url *url)
error
=
lookup_config
(
out
,
cfg
,
"http.proxy"
);
done:
if
(
cleanup_config
)
git_config_free
(
cfg
);
git_buf_dispose
(
&
buf
);
git_net_url_dispose
(
&
lookup_url
);
return
error
;
...
...
@@ -971,7 +984,6 @@ int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url)
GIT_ASSERT_ARG
(
out
);
GIT_ASSERT_ARG
(
remote
);
GIT_ASSERT_ARG
(
remote
->
repo
);
*
out
=
NULL
;
...
...
tests/remote/httpproxy.c
View file @
eb41276f
#include "clar_libgit2.h"
#include "
remote
.h"
#include "
futils
.h"
#include "net.h"
#include "remote.h"
static
git_repository
*
repo
;
static
git_net_url
url
=
GIT_NET_URL_INIT
;
...
...
@@ -105,6 +106,45 @@ void test_remote_httpproxy__config_empty_overrides(void)
assert_config_match
(
"remote.lg2.proxy"
,
""
);
}
void
assert_global_config_match
(
const
char
*
config
,
const
char
*
expected
)
{
git_remote
*
remote
;
char
*
proxy
;
git_config
*
cfg
;
if
(
config
)
{
cl_git_pass
(
git_config_open_default
(
&
cfg
));
git_config_set_string
(
cfg
,
config
,
expected
);
git_config_free
(
cfg
);
}
cl_git_pass
(
git_remote_create_detached
(
&
remote
,
"https://github.com/libgit2/libgit2"
));
cl_git_pass
(
git_remote__http_proxy
(
&
proxy
,
remote
,
&
url
));
if
(
expected
)
cl_assert_equal_s
(
proxy
,
expected
);
else
cl_assert_equal_p
(
proxy
,
expected
);
git_remote_free
(
remote
);
git__free
(
proxy
);
}
void
test_remote_httpproxy__config_overrides_detached_remote
(
void
)
{
cl_fake_home
();
assert_global_config_match
(
NULL
,
NULL
);
assert_global_config_match
(
"http.proxy"
,
"http://localhost:1/"
);
assert_global_config_match
(
"http.https://github.com.proxy"
,
"http://localhost:2/"
);
assert_global_config_match
(
"http.https://github.com/.proxy"
,
"http://localhost:3/"
);
assert_global_config_match
(
"http.https://github.com/libgit2.proxy"
,
"http://localhost:4/"
);
assert_global_config_match
(
"http.https://github.com/libgit2/.proxy"
,
"http://localhost:5/"
);
assert_global_config_match
(
"http.https://github.com/libgit2/libgit2.proxy"
,
"http://localhost:6/"
);
cl_git_pass
(
git_futils_rmdir_r
(
"home"
,
NULL
,
GIT_RMDIR_REMOVE_FILES
));
}
void
test_remote_httpproxy__env
(
void
)
{
orig_http_proxy
=
cl_getenv
(
"HTTP_PROXY"
);
...
...
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