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
a209a025
Commit
a209a025
authored
May 03, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remote: add git_remote_add()
Helper function to create a remote with the default settings
parent
3df9cc59
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
+47
-0
include/git2/remote.h
+10
-0
src/remote.c
+25
-0
tests-clar/network/remotes.c
+12
-0
No files found.
include/git2/remote.h
View file @
a209a025
...
...
@@ -218,6 +218,16 @@ GIT_EXTERN(int) git_remote_supported_url(const char* url);
*/
GIT_EXTERN
(
int
)
git_remote_list
(
git_strarray
*
remotes_list
,
git_repository
*
repo
);
/**
* Add a remote with the default fetch refspec to the repository's configuration
*
* @param out the resulting remote
* @param repo the repository in which to create the remote
* @param name the remote's name
* @param url the remote's url
*/
GIT_EXTERN
(
int
)
git_remote_add
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
url
);
/** @} */
GIT_END_DECL
#endif
src/remote.c
View file @
a209a025
...
...
@@ -476,3 +476,28 @@ int git_remote_list(git_strarray *remotes_list, git_repository *repo)
return
0
;
}
int
git_remote_add
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
url
)
{
git_buf
buf
=
GIT_BUF_INIT
;
if
(
git_remote_new
(
out
,
repo
,
url
,
name
)
<
0
)
return
-
1
;
if
(
git_buf_printf
(
&
buf
,
"refs/heads/*:refs/remotes/%s/*"
,
name
)
<
0
)
goto
on_error
;
if
(
git_remote_set_fetchspec
(
*
out
,
git_buf_cstr
(
&
buf
))
<
0
)
goto
on_error
;
git_buf_free
(
&
buf
);
if
(
git_remote_save
(
*
out
)
<
0
)
return
-
1
;
return
0
;
on_error:
git_buf_free
(
&
buf
);
git_remote_free
(
*
out
);
return
-
1
;
}
tests-clar/network/remotes.c
View file @
a209a025
...
...
@@ -158,3 +158,15 @@ void test_network_remotes__loading_a_missing_remote_returns_ENOTFOUND(void)
{
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_remote_load
(
&
_remote
,
_repo
,
"just-left-few-minutes-ago"
));
}
void
test_network_remotes__add
(
void
)
{
git_remote_free
(
_remote
);
cl_git_pass
(
git_remote_add
(
&
_remote
,
_repo
,
"addtest"
,
"http://github.com/libgit2/libgit2"
));
git_remote_free
(
_remote
);
cl_git_pass
(
git_remote_load
(
&
_remote
,
_repo
,
"addtest"
));
_refspec
=
git_remote_fetchspec
(
_remote
);
cl_assert
(
!
strcmp
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
));
cl_assert
(
!
strcmp
(
git_refspec_dst
(
_refspec
),
"refs/remotes/addtest/*"
));
}
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