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
d3650294
Commit
d3650294
authored
Jun 20, 2018
by
Etienne Samson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remote: add a flag to prevent generation of the default fetchspec
parent
fdb116b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
9 deletions
+21
-9
include/git2/remote.h
+3
-0
src/remote.c
+17
-4
tests/remote/create.c
+1
-5
No files found.
include/git2/remote.h
View file @
d3650294
...
...
@@ -47,6 +47,9 @@ GIT_EXTERN(int) git_remote_create(
typedef
enum
{
/** Ignore the repository apply.insteadOf configuration */
GIT_REMOTE_CREATE_SKIP_INSTEADOF
=
(
1
<<
0
),
/** Don't build a fetchspec from the name if none is set */
GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
=
(
1
<<
1
),
}
git_remote_create_flags
;
/**
...
...
src/remote.c
View file @
d3650294
...
...
@@ -230,6 +230,7 @@ static int create_internal(git_remote **out, const char *url, const git_remote_c
git_config
*
config_ro
=
NULL
,
*
config_rw
;
git_buf
canonical_url
=
GIT_BUF_INIT
;
git_buf
var
=
GIT_BUF_INIT
;
git_buf
specbuf
=
GIT_BUF_INIT
;
const
git_remote_create_options
dummy_opts
=
GIT_REMOTE_CREATE_OPTIONS_INIT
;
int
error
=
-
1
;
...
...
@@ -282,13 +283,24 @@ static int create_internal(git_remote **out, const char *url, const git_remote_c
goto
on_error
;
}
if
(
opts
->
fetchspec
!=
NULL
)
{
if
((
error
=
add_refspec
(
remote
,
opts
->
fetchspec
,
true
))
<
0
)
if
(
opts
->
fetchspec
!=
NULL
||
(
opts
->
name
&&
!
(
opts
->
flags
&
GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
)))
{
const
char
*
fetch
=
NULL
;
if
(
opts
->
fetchspec
)
{
fetch
=
opts
->
fetchspec
;
}
else
{
if
((
error
=
default_fetchspec_for_name
(
&
specbuf
,
opts
->
name
))
<
0
)
goto
on_error
;
fetch
=
git_buf_cstr
(
&
specbuf
);
}
if
((
error
=
add_refspec
(
remote
,
fetch
,
true
))
<
0
)
goto
on_error
;
/* only write for named remotes with a repository */
if
(
opts
->
repository
&&
opts
->
name
&&
((
error
=
write_add_refspec
(
opts
->
repository
,
opts
->
name
,
opts
->
fetchspec
,
true
))
<
0
||
((
error
=
write_add_refspec
(
opts
->
repository
,
opts
->
name
,
fetch
,
true
))
<
0
||
(
error
=
lookup_remote_prune_config
(
remote
,
config_ro
,
opts
->
name
))
<
0
))
goto
on_error
;
...
...
@@ -314,6 +326,7 @@ on_error:
git_remote_free
(
remote
);
git_config_free
(
config_ro
);
git_buf_dispose
(
&
specbuf
);
git_buf_dispose
(
&
canonical_url
);
git_buf_dispose
(
&
var
);
return
error
;
...
...
@@ -336,7 +349,6 @@ int git_remote_create(git_remote **out, git_repository *repo, const char *name,
opts
.
repository
=
repo
;
opts
.
name
=
name
;
opts
.
fetchspec
=
git_buf_cstr
(
&
buf
);
error
=
create_internal
(
out
,
url
,
&
opts
);
...
...
@@ -361,6 +373,7 @@ int git_remote_create_with_fetchspec(git_remote **out, git_repository *repo, con
opts
.
repository
=
repo
;
opts
.
name
=
name
;
opts
.
fetchspec
=
fetch
;
opts
.
flags
=
GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
;
return
create_internal
(
out
,
url
,
&
opts
);
}
...
...
tests/remote/create.c
View file @
d3650294
...
...
@@ -52,8 +52,6 @@ void test_remote_create__named(void)
git_config
*
cfg
;
const
char
*
cfg_val
;
cl_skip
();
// Later
size_t
section_count
=
count_config_entries_match
(
_repo
,
"remote
\\
."
);
cl_git_pass
(
git_remote_create
(
&
remote
,
_repo
,
"valid-name"
,
TEST_URL
));
...
...
@@ -200,8 +198,6 @@ void test_remote_create__with_opts_named(void)
opts
.
name
=
"test-new"
;
opts
.
repository
=
_repo
;
cl_skip
();
// Later
cl_git_pass
(
git_remote_create_with_opts
(
&
remote
,
TEST_URL
,
&
opts
));
cl_assert_equal_s
(
git_remote_name
(
remote
),
"test-new"
);
cl_assert_equal_s
(
git_remote_url
(
remote
),
TEST_URL
);
...
...
@@ -246,7 +242,7 @@ void test_remote_create__with_opts_named_no_fetchspec(void)
opts
.
name
=
"test-new"
;
opts
.
repository
=
_repo
;
// opts.flags = GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC; // Later
opts
.
flags
=
GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
;
cl_git_pass
(
git_remote_create_with_opts
(
&
remote
,
TEST_URL
,
&
opts
));
cl_assert_equal_s
(
git_remote_name
(
remote
),
"test-new"
);
...
...
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