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
2139c9b7
Commit
2139c9b7
authored
Oct 10, 2014
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2542 from linquize/fetch-head
Do not error out when fetching from second remote
parents
a60d0f11
8deea589
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
src/remote.c
+12
-3
tests/network/fetchlocal.c
+34
-0
No files found.
src/remote.c
View file @
2139c9b7
...
...
@@ -927,13 +927,15 @@ static int remote_head_for_fetchspec_src(git_remote_head **out, git_vector *upda
return
0
;
}
static
int
remote_head_for_ref
(
git_remote_head
**
out
,
git_refspec
*
spec
,
git_vector
*
update_heads
,
git_reference
*
ref
)
static
int
remote_head_for_ref
(
git_remote_head
**
out
,
git_re
mote
*
remote
,
git_re
fspec
*
spec
,
git_vector
*
update_heads
,
git_reference
*
ref
)
{
git_reference
*
resolved_ref
=
NULL
;
git_buf
remote_name
=
GIT_BUF_INIT
;
git_buf
upstream_name
=
GIT_BUF_INIT
;
git_buf
config_key
=
GIT_BUF_INIT
;
git_repository
*
repo
;
const
char
*
ref_name
;
git_config
*
config
=
NULL
;
const
char
*
ref_name
,
*
branch_remote
;
int
error
=
0
;
assert
(
out
&&
spec
&&
ref
);
...
...
@@ -953,6 +955,11 @@ static int remote_head_for_ref(git_remote_head **out, git_refspec *spec, git_vec
}
if
((
!
git_reference__is_branch
(
ref_name
))
||
(
error
=
git_repository_config_snapshot
(
&
config
,
repo
))
<
0
||
(
error
=
git_buf_printf
(
&
config_key
,
"branch.%s.remote"
,
ref_name
+
strlen
(
GIT_REFS_HEADS_DIR
)))
<
0
||
(
error
=
git_config_get_string
(
&
branch_remote
,
config
,
git_buf_cstr
(
&
config_key
)))
<
0
||
git__strcmp
(
git_remote_name
(
remote
),
branch_remote
)
||
(
error
=
git_branch_upstream_name
(
&
upstream_name
,
repo
,
ref_name
))
<
0
||
(
error
=
git_refspec_rtransform
(
&
remote_name
,
spec
,
upstream_name
.
ptr
))
<
0
)
{
/* Not an error if there is no upstream */
...
...
@@ -968,6 +975,8 @@ cleanup:
git_reference_free
(
resolved_ref
);
git_buf_free
(
&
remote_name
);
git_buf_free
(
&
upstream_name
);
git_buf_free
(
&
config_key
);
git_config_free
(
config
);
return
error
;
}
...
...
@@ -996,7 +1005,7 @@ static int git_remote_write_fetchhead(git_remote *remote, git_refspec *spec, git
/* Determine what to merge: if refspec was a wildcard, just use HEAD */
if
(
git_refspec_is_wildcard
(
spec
))
{
if
((
error
=
git_reference_lookup
(
&
head_ref
,
remote
->
repo
,
GIT_HEAD_FILE
))
<
0
||
(
error
=
remote_head_for_ref
(
&
merge_remote_ref
,
spec
,
update_heads
,
head_ref
))
<
0
)
(
error
=
remote_head_for_ref
(
&
merge_remote_ref
,
remote
,
spec
,
update_heads
,
head_ref
))
<
0
)
goto
cleanup
;
}
else
{
/* If we're fetching a single refspec, that's the only thing that should be in FETCH_HEAD. */
...
...
tests/network/fetchlocal.c
View file @
2139c9b7
...
...
@@ -127,3 +127,37 @@ void test_network_fetchlocal__clone_into_mirror(void)
git_repository_free
(
repo
);
cl_fixture_cleanup
(
"./foo.git"
);
}
void
test_network_fetchlocal__multi_remotes
(
void
)
{
git_repository
*
repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
git_remote
*
test
,
*
test2
;
git_strarray
refnames
=
{
0
};
git_remote_callbacks
callbacks
=
GIT_REMOTE_CALLBACKS_INIT
;
callbacks
.
transfer_progress
=
transfer_cb
;
cl_git_pass
(
git_remote_load
(
&
test
,
repo
,
"test"
));
cl_git_pass
(
git_remote_set_url
(
test
,
cl_git_fixture_url
(
"testrepo.git"
)));
git_remote_set_callbacks
(
test
,
&
callbacks
);
cl_git_pass
(
git_remote_connect
(
test
,
GIT_DIRECTION_FETCH
));
cl_git_pass
(
git_remote_download
(
test
));
cl_git_pass
(
git_remote_update_tips
(
test
,
NULL
,
NULL
));
cl_git_pass
(
git_reference_list
(
&
refnames
,
repo
));
cl_assert_equal_i
(
32
,
(
int
)
refnames
.
count
);
cl_git_pass
(
git_remote_load
(
&
test2
,
repo
,
"test_with_pushurl"
));
cl_git_pass
(
git_remote_set_url
(
test2
,
cl_git_fixture_url
(
"testrepo.git"
)));
git_remote_set_callbacks
(
test2
,
&
callbacks
);
cl_git_pass
(
git_remote_connect
(
test2
,
GIT_DIRECTION_FETCH
));
cl_git_pass
(
git_remote_download
(
test2
));
cl_git_pass
(
git_remote_update_tips
(
test2
,
NULL
,
NULL
));
cl_git_pass
(
git_reference_list
(
&
refnames
,
repo
));
cl_assert_equal_i
(
44
,
(
int
)
refnames
.
count
);
git_strarray_free
(
&
refnames
);
git_remote_free
(
test
);
git_remote_free
(
test2
);
git_repository_free
(
repo
);
}
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