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
4f2b6093
Commit
4f2b6093
authored
9 years ago
by
Matt Burke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tell the git_transport about the custom_headers
parent
9da32a62
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
43 additions
and
24 deletions
+43
-24
include/git2/remote.h
+2
-1
include/git2/sys/transport.h
+5
-0
src/push.c
+2
-1
src/push.h
+1
-0
src/remote.c
+16
-5
tests/network/remote/defaultbranch.c
+3
-3
tests/network/remote/local.c
+4
-4
tests/network/remote/remotes.c
+3
-3
tests/online/fetch.c
+6
-6
tests/online/push.c
+1
-1
No files found.
include/git2/remote.h
View file @
4f2b6093
...
...
@@ -241,9 +241,10 @@ GIT_EXTERN(const git_refspec *)git_remote_get_refspec(const git_remote *remote,
* @param direction GIT_DIRECTION_FETCH if you want to fetch or
* GIT_DIRECTION_PUSH if you want to push
* @param callbacks the callbacks to use for this connection
* @param custom_headers extra HTTP headers to use in this connection
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_remote_connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
);
GIT_EXTERN
(
int
)
git_remote_connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
,
const
git_strarray
*
custom_headers
);
/**
* Get the remote repository's reference advertisement list
...
...
This diff is collapsed.
Click to expand it.
include/git2/sys/transport.h
View file @
4f2b6093
...
...
@@ -40,6 +40,11 @@ struct git_transport {
git_transport_certificate_check_cb
certificate_check_cb
,
void
*
payload
);
/* Set custom headers for HTTP requests */
int
(
*
set_custom_headers
)(
git_transport
*
transport
,
const
git_strarray
*
custom_headers
);
/* Connect the transport to the remote repository, using the given
* direction. */
int
(
*
connect
)(
...
...
This diff is collapsed.
Click to expand it.
src/push.c
View file @
4f2b6093
...
...
@@ -73,6 +73,7 @@ int git_push_set_options(git_push *push, const git_push_options *opts)
GITERR_CHECK_VERSION
(
opts
,
GIT_PUSH_OPTIONS_VERSION
,
"git_push_options"
);
push
->
pb_parallelism
=
opts
->
pb_parallelism
;
push
->
custom_headers
=
&
opts
->
custom_headers
;
return
0
;
}
...
...
@@ -638,7 +639,7 @@ int git_push_finish(git_push *push, const git_remote_callbacks *callbacks)
int
error
;
if
(
!
git_remote_connected
(
push
->
remote
)
&&
(
error
=
git_remote_connect
(
push
->
remote
,
GIT_DIRECTION_PUSH
,
callbacks
))
<
0
)
(
error
=
git_remote_connect
(
push
->
remote
,
GIT_DIRECTION_PUSH
,
callbacks
,
push
->
custom_headers
))
<
0
)
return
error
;
if
((
error
=
filter_refs
(
push
->
remote
))
<
0
||
...
...
This diff is collapsed.
Click to expand it.
src/push.h
View file @
4f2b6093
...
...
@@ -38,6 +38,7 @@ struct git_push {
/* options */
unsigned
pb_parallelism
;
const
git_strarray
*
custom_headers
;
};
/**
...
...
This diff is collapsed.
Click to expand it.
src/remote.c
View file @
4f2b6093
...
...
@@ -687,7 +687,15 @@ int set_transport_callbacks(git_transport *t, const git_remote_callbacks *cbs)
cbs
->
certificate_check
,
cbs
->
payload
);
}
int
git_remote_connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
)
int
set_transport_custom_headers
(
git_transport
*
t
,
const
git_strarray
*
custom_headers
)
{
if
(
!
t
->
set_custom_headers
||
!
custom_headers
)
return
0
;
return
t
->
set_custom_headers
(
t
,
custom_headers
);
}
int
git_remote_connect
(
git_remote
*
remote
,
git_direction
direction
,
const
git_remote_callbacks
*
callbacks
,
const
git_strarray
*
custom_headers
)
{
git_transport
*
t
;
const
char
*
url
;
...
...
@@ -726,6 +734,9 @@ int git_remote_connect(git_remote *remote, git_direction direction, const git_re
if
(
!
t
&&
(
error
=
git_transport_new
(
&
t
,
remote
,
url
))
<
0
)
return
error
;
if
((
error
=
set_transport_custom_headers
(
t
,
custom_headers
))
!=
0
)
goto
on_error
;
if
((
error
=
set_transport_callbacks
(
t
,
callbacks
))
<
0
||
(
error
=
t
->
connect
(
t
,
url
,
credentials
,
payload
,
direction
,
flags
))
!=
0
)
goto
on_error
;
...
...
@@ -893,7 +904,7 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs, const
}
if
(
!
git_remote_connected
(
remote
)
&&
(
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
cbs
))
<
0
)
(
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
cbs
,
NULL
))
<
0
)
goto
on_error
;
if
(
ls_to_vector
(
&
refs
,
remote
)
<
0
)
...
...
@@ -966,7 +977,7 @@ int git_remote_fetch(
}
/* Connect and download everything */
if
((
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
cbs
))
!=
0
)
if
((
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
cbs
,
NULL
))
!=
0
)
return
error
;
error
=
git_remote_download
(
remote
,
refspecs
,
opts
);
...
...
@@ -2384,7 +2395,7 @@ int git_remote_upload(git_remote *remote, const git_strarray *refspecs, const gi
cbs
=
&
opts
->
callbacks
;
if
(
!
git_remote_connected
(
remote
)
&&
(
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_PUSH
,
cbs
))
<
0
)
(
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_PUSH
,
cbs
,
&
opts
->
custom_headers
))
<
0
)
goto
cleanup
;
free_refspecs
(
&
remote
->
active_refspecs
);
...
...
@@ -2441,7 +2452,7 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
assert
(
remote
&&
refspecs
);
if
((
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_PUSH
,
cbs
))
<
0
)
if
((
error
=
git_remote_connect
(
remote
,
GIT_DIRECTION_PUSH
,
cbs
,
&
opts
->
custom_headers
))
<
0
)
return
error
;
if
((
error
=
git_remote_upload
(
remote
,
refspecs
,
opts
))
<
0
)
...
...
This diff is collapsed.
Click to expand it.
tests/network/remote/defaultbranch.c
View file @
4f2b6093
...
...
@@ -26,7 +26,7 @@ static void assert_default_branch(const char *should)
{
git_buf
name
=
GIT_BUF_INIT
;
cl_git_pass
(
git_remote_connect
(
g_remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
g_remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_git_pass
(
git_remote_default_branch
(
&
name
,
g_remote
));
cl_assert_equal_s
(
should
,
name
.
ptr
);
git_buf_free
(
&
name
);
...
...
@@ -57,7 +57,7 @@ void test_network_remote_defaultbranch__no_default_branch(void)
git_buf
buf
=
GIT_BUF_INIT
;
cl_git_pass
(
git_remote_create
(
&
remote_b
,
g_repo_b
,
"self"
,
git_repository_path
(
g_repo_b
)));
cl_git_pass
(
git_remote_connect
(
remote_b
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote_b
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_git_pass
(
git_remote_ls
(
&
heads
,
&
len
,
remote_b
));
cl_assert_equal_i
(
0
,
len
);
...
...
@@ -80,7 +80,7 @@ void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void)
cl_git_pass
(
git_reference_create
(
&
ref
,
g_repo_a
,
"refs/foo/bar"
,
&
id
,
1
,
NULL
));
git_reference_free
(
ref
);
cl_git_pass
(
git_remote_connect
(
g_remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
g_remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_git_fail_with
(
GIT_ENOTFOUND
,
git_remote_default_branch
(
&
buf
,
g_remote
));
cl_git_pass
(
git_clone
(
&
cloned_repo
,
git_repository_path
(
g_repo_a
),
"./local-detached"
,
NULL
));
...
...
This diff is collapsed.
Click to expand it.
tests/network/remote/local.c
View file @
4f2b6093
...
...
@@ -40,7 +40,7 @@ static void connect_to_local_repository(const char *local_repository)
git_buf_sets
(
&
file_path_buf
,
cl_git_path_url
(
local_repository
));
cl_git_pass
(
git_remote_create_anonymous
(
&
remote
,
repo
,
git_buf_cstr
(
&
file_path_buf
)));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
}
void
test_network_remote_local__connected
(
void
)
...
...
@@ -214,7 +214,7 @@ void test_network_remote_local__push_to_bare_remote(void)
/* Connect to the bare repo */
cl_git_pass
(
git_remote_create_anonymous
(
&
localremote
,
repo
,
"./localbare.git"
));
cl_git_pass
(
git_remote_connect
(
localremote
,
GIT_DIRECTION_PUSH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
localremote
,
GIT_DIRECTION_PUSH
,
NULL
,
NULL
));
/* Try to push */
cl_git_pass
(
git_remote_upload
(
localremote
,
&
push_array
,
NULL
));
...
...
@@ -253,7 +253,7 @@ void test_network_remote_local__push_to_bare_remote_with_file_url(void)
/* Connect to the bare repo */
cl_git_pass
(
git_remote_create_anonymous
(
&
localremote
,
repo
,
url
));
cl_git_pass
(
git_remote_connect
(
localremote
,
GIT_DIRECTION_PUSH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
localremote
,
GIT_DIRECTION_PUSH
,
NULL
,
NULL
));
/* Try to push */
cl_git_pass
(
git_remote_upload
(
localremote
,
&
push_array
,
NULL
));
...
...
@@ -290,7 +290,7 @@ void test_network_remote_local__push_to_non_bare_remote(void)
/* Connect to the bare repo */
cl_git_pass
(
git_remote_create_anonymous
(
&
localremote
,
repo
,
"./localnonbare"
));
cl_git_pass
(
git_remote_connect
(
localremote
,
GIT_DIRECTION_PUSH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
localremote
,
GIT_DIRECTION_PUSH
,
NULL
,
NULL
));
/* Try to push */
cl_git_fail_with
(
GIT_EBAREREPO
,
git_remote_upload
(
localremote
,
&
push_array
,
NULL
));
...
...
This diff is collapsed.
Click to expand it.
tests/network/remote/remotes.c
View file @
4f2b6093
...
...
@@ -93,7 +93,7 @@ void test_network_remote_remotes__error_when_no_push_available(void)
cl_git_pass
(
git_remote_create_anonymous
(
&
r
,
_repo
,
cl_fixture
(
"testrepo.git"
)));
callbacks
.
transport
=
git_transport_local
;
cl_git_pass
(
git_remote_connect
(
r
,
GIT_DIRECTION_PUSH
,
&
callbacks
));
cl_git_pass
(
git_remote_connect
(
r
,
GIT_DIRECTION_PUSH
,
&
callbacks
,
NULL
));
/* Make sure that push is really not available */
r
->
transport
->
push
=
NULL
;
...
...
@@ -359,7 +359,7 @@ void test_network_remote_remotes__can_load_with_an_empty_url(void)
cl_assert
(
remote
->
url
==
NULL
);
cl_assert
(
remote
->
pushurl
==
NULL
);
cl_git_fail
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_fail
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_assert
(
giterr_last
()
!=
NULL
);
cl_assert
(
giterr_last
()
->
klass
==
GITERR_INVALID
);
...
...
@@ -376,7 +376,7 @@ void test_network_remote_remotes__can_load_with_only_an_empty_pushurl(void)
cl_assert
(
remote
->
url
==
NULL
);
cl_assert
(
remote
->
pushurl
==
NULL
);
cl_git_fail
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_fail
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
git_remote_free
(
remote
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/online/fetch.c
View file @
4f2b6093
...
...
@@ -81,11 +81,11 @@ void test_online_fetch__fetch_twice(void)
{
git_remote
*
remote
;
cl_git_pass
(
git_remote_create
(
&
remote
,
_repo
,
"test"
,
"git://github.com/libgit2/TestGitRepository.git"
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_git_pass
(
git_remote_download
(
remote
,
NULL
,
NULL
));
git_remote_disconnect
(
remote
);
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
);
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
);
cl_git_pass
(
git_remote_download
(
remote
,
NULL
,
NULL
));
git_remote_disconnect
(
remote
);
...
...
@@ -117,7 +117,7 @@ void test_online_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date
cl_git_pass
(
git_repository_open
(
&
_repository
,
"./fetch/lg2"
));
cl_git_pass
(
git_remote_lookup
(
&
remote
,
_repository
,
"origin"
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_assert_equal_i
(
false
,
invoked
);
...
...
@@ -155,7 +155,7 @@ void test_online_fetch__can_cancel(void)
options
.
callbacks
.
transfer_progress
=
cancel_at_half
;
options
.
callbacks
.
payload
=
&
bytes_received
;
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_git_fail_with
(
git_remote_download
(
remote
,
NULL
,
&
options
),
-
4321
);
git_remote_disconnect
(
remote
);
git_remote_free
(
remote
);
...
...
@@ -169,7 +169,7 @@ void test_online_fetch__ls_disconnected(void)
cl_git_pass
(
git_remote_create
(
&
remote
,
_repo
,
"test"
,
"http://github.com/libgit2/TestGitRepository.git"
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
cl_git_pass
(
git_remote_ls
(
&
refs
,
&
refs_len_before
,
remote
));
git_remote_disconnect
(
remote
);
cl_git_pass
(
git_remote_ls
(
&
refs
,
&
refs_len_after
,
remote
));
...
...
@@ -187,7 +187,7 @@ void test_online_fetch__remote_symrefs(void)
cl_git_pass
(
git_remote_create
(
&
remote
,
_repo
,
"test"
,
"http://github.com/libgit2/TestGitRepository.git"
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIRECTION_FETCH
,
NULL
,
NULL
));
git_remote_disconnect
(
remote
);
cl_git_pass
(
git_remote_ls
(
&
refs
,
&
refs_len
,
remote
));
...
...
This diff is collapsed.
Click to expand it.
tests/online/push.c
View file @
4f2b6093
...
...
@@ -373,7 +373,7 @@ void test_online_push__initialize(void)
record_callbacks_data_clear
(
&
_record_cbs_data
);
cl_git_pass
(
git_remote_connect
(
_remote
,
GIT_DIRECTION_PUSH
,
&
_record_cbs
));
cl_git_pass
(
git_remote_connect
(
_remote
,
GIT_DIRECTION_PUSH
,
&
_record_cbs
,
NULL
));
/* Clean up previously pushed branches. Fails if receive.denyDeletes is
* set on the remote. Also, on Git 1.7.0 and newer, you must run
...
...
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