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
89e5ed98
Commit
89e5ed98
authored
Feb 20, 2012
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add git_remote_save()
parent
bcb8c007
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
0 deletions
+84
-0
include/git2/remote.h
+8
-0
src/remote.c
+50
-0
tests-clar/network/remotes.c
+26
-0
No files found.
include/git2/remote.h
View file @
89e5ed98
...
...
@@ -54,6 +54,14 @@ GIT_EXTERN(int) git_remote_new(git_remote **out, git_repository *repo, const cha
GIT_EXTERN
(
int
)
git_remote_load
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
);
/**
* Save a remote to its repository's configuration
*
* @param remote the remote to save to config
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_remote_save
(
const
git_remote
*
remote
);
/**
* Get the remote's name
*
* @param remote the remote
...
...
src/remote.c
View file @
89e5ed98
...
...
@@ -187,6 +187,56 @@ cleanup:
return
error
;
}
int
git_remote_save
(
const
git_remote
*
remote
)
{
int
error
;
git_config
*
config
;
git_buf
buf
=
GIT_BUF_INIT
,
value
=
GIT_BUF_INIT
;
error
=
git_repository_config__weakptr
(
&
config
,
remote
->
repo
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
git_buf_printf
(
&
buf
,
"remote.%s.%s"
,
remote
->
name
,
"url"
);
if
(
git_buf_oom
(
&
buf
))
return
GIT_ENOMEM
;
error
=
git_config_set_string
(
config
,
git_buf_cstr
(
&
buf
),
remote
->
url
);
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
if
(
remote
->
fetch
.
src
!=
NULL
&&
remote
->
fetch
.
src
!=
NULL
)
{
git_buf_clear
(
&
buf
);
git_buf_clear
(
&
value
);
git_buf_printf
(
&
buf
,
"remote.%s.%s"
,
remote
->
name
,
"fetch"
);
git_buf_printf
(
&
value
,
"%s:%s"
,
remote
->
fetch
.
src
,
remote
->
fetch
.
dst
);
if
(
git_buf_oom
(
&
buf
)
||
git_buf_oom
(
&
value
))
return
GIT_ENOMEM
;
error
=
git_config_set_string
(
config
,
git_buf_cstr
(
&
buf
),
git_buf_cstr
(
&
value
));
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
}
if
(
remote
->
push
.
src
!=
NULL
&&
remote
->
push
.
src
!=
NULL
)
{
git_buf_clear
(
&
buf
);
git_buf_clear
(
&
value
);
git_buf_printf
(
&
buf
,
"remote.%s.%s"
,
remote
->
name
,
"push"
);
git_buf_printf
(
&
value
,
"%s:%s"
,
remote
->
push
.
src
,
remote
->
push
.
dst
);
if
(
git_buf_oom
(
&
buf
)
||
git_buf_oom
(
&
value
))
return
GIT_ENOMEM
;
error
=
git_config_set_string
(
config
,
git_buf_cstr
(
&
buf
),
git_buf_cstr
(
&
value
));
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
}
cleanup:
git_buf_free
(
&
buf
);
git_buf_free
(
&
value
);
return
error
;
}
const
char
*
git_remote_name
(
git_remote
*
remote
)
{
assert
(
remote
);
...
...
tests-clar/network/remotes.c
View file @
89e5ed98
...
...
@@ -52,6 +52,32 @@ void test_network_remotes__set_pushspec(void)
cl_assert
(
!
strcmp
(
git_refspec_dst
(
_refspec
),
"refs/*"
));
}
void
test_network_remotes__save
(
void
)
{
git_remote_free
(
_remote
);
/* Set up the remote and save it to config */
cl_git_pass
(
git_remote_new
(
&
_remote
,
_repo
,
"git://github.com/libgit2/libgit2"
,
"upstream"
));
cl_git_pass
(
git_remote_set_fetchspec
(
_remote
,
"refs/heads/*:refs/remotes/upstream/*"
));
cl_git_pass
(
git_remote_set_pushspec
(
_remote
,
"refs/heads/*:refs/heads/*"
));
cl_git_pass
(
git_remote_save
(
_remote
));
git_remote_free
(
_remote
);
_remote
=
NULL
;
/* Load it from config and make sure everything matches */
cl_git_pass
(
git_remote_load
(
&
_remote
,
_repo
,
"upstream"
));
_refspec
=
git_remote_fetchspec
(
_remote
);
cl_assert
(
_refspec
!=
NULL
);
cl_assert
(
!
strcmp
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
));
cl_assert
(
!
strcmp
(
git_refspec_dst
(
_refspec
),
"refs/remotes/upstream/*"
));
_refspec
=
git_remote_pushspec
(
_remote
);
cl_assert
(
_refspec
!=
NULL
);
cl_assert
(
!
strcmp
(
git_refspec_src
(
_refspec
),
"refs/heads/*"
));
cl_assert
(
!
strcmp
(
git_refspec_dst
(
_refspec
),
"refs/heads/*"
));
}
void
test_network_remotes__fnmatch
(
void
)
{
cl_git_pass
(
git_refspec_src_match
(
_refspec
,
"refs/heads/master"
));
...
...
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