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
1f796cd1
Commit
1f796cd1
authored
May 08, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #676 from carlosmn/remotes
Add git_remote_add() and change signature for _new()
parents
19579847
baaa8a44
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
13 deletions
+68
-13
examples/network/fetch.c
+1
-1
examples/network/ls-remote.c
+1
-1
include/git2/remote.h
+13
-2
src/config_file.c
+6
-6
src/remote.c
+33
-1
tests-clar/network/remotelocal.c
+1
-1
tests-clar/network/remotes.c
+13
-1
No files found.
examples/network/fetch.c
View file @
1f796cd1
...
...
@@ -69,7 +69,7 @@ int fetch(git_repository *repo, int argc, char **argv)
// Figure out whether it's a named remote or a URL
printf
(
"Fetching %s
\n
"
,
argv
[
1
]);
if
(
git_remote_load
(
&
remote
,
repo
,
argv
[
1
])
<
0
)
{
if
(
git_remote_new
(
&
remote
,
repo
,
argv
[
1
],
NULL
)
<
0
)
if
(
git_remote_new
(
&
remote
,
repo
,
NULL
,
argv
[
1
],
NULL
)
<
0
)
return
-
1
;
}
...
...
examples/network/ls-remote.c
View file @
1f796cd1
...
...
@@ -19,7 +19,7 @@ int use_unnamed(git_repository *repo, const char *url)
// Create an instance of a remote from the URL. The transport to use
// is detected from the URL
error
=
git_remote_new
(
&
remote
,
repo
,
url
,
NULL
);
error
=
git_remote_new
(
&
remote
,
repo
,
NULL
,
url
,
NULL
);
if
(
error
<
GIT_SUCCESS
)
goto
cleanup
;
...
...
include/git2/remote.h
View file @
1f796cd1
...
...
@@ -38,11 +38,12 @@ GIT_BEGIN_DECL
*
* @param out pointer to the new remote object
* @param repo the associtated repository
* @param url the remote repository's URL
* @param name the remote's name
* @param url the remote repository's URL
* @param fetch the fetch refspec to use for this remote
* @return GIT_SUCCESS or an error code
*/
GIT_EXTERN
(
int
)
git_remote_new
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
url
,
const
char
*
name
);
GIT_EXTERN
(
int
)
git_remote_new
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
url
,
const
char
*
fetch
);
/**
* Get the information for a particular remote
...
...
@@ -218,6 +219,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/config_file.c
View file @
1f796cd1
...
...
@@ -258,18 +258,17 @@ static int config_set(git_config_file *cfg, const char *name, const char *value)
GITERR_CHECK_ALLOC
(
var
->
value
);
}
if
(
config_write
(
b
,
key
,
NULL
,
value
)
<
0
)
{
cvar_free
(
var
);
return
-
1
;
}
git_strmap_insert2
(
b
->
values
,
key
,
var
,
old_var
,
rval
);
if
(
rval
<
0
)
return
-
1
;
if
(
old_var
!=
NULL
)
cvar_free
(
old_var
);
if
(
config_write
(
b
,
key
,
NULL
,
value
)
<
0
)
{
git_strmap_delete
(
b
->
values
,
var
->
key
);
cvar_free
(
var
);
return
-
1
;
}
return
0
;
}
...
...
@@ -1018,6 +1017,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
pre_end
=
post_start
=
cfg
->
reader
.
read_ptr
;
git__free
(
current_section
);
current_section
=
NULL
;
if
(
parse_section_header
(
cfg
,
&
current_section
)
<
0
)
goto
rewrite_fail
;
...
...
src/remote.c
View file @
1f796cd1
...
...
@@ -54,7 +54,7 @@ static int parse_remote_refspec(git_config *cfg, git_refspec *refspec, const cha
return
refspec_parse
(
refspec
,
val
);
}
int
git_remote_new
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
url
,
const
char
*
name
)
int
git_remote_new
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
url
,
const
char
*
fetch
)
{
git_remote
*
remote
;
...
...
@@ -78,8 +78,17 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *url, cons
GITERR_CHECK_ALLOC
(
remote
->
name
);
}
if
(
fetch
!=
NULL
)
{
if
(
refspec_parse
(
&
remote
->
fetch
,
fetch
)
<
0
)
goto
on_error
;
}
*
out
=
remote
;
return
0
;
on_error:
git_remote_free
(
remote
);
return
-
1
;
}
int
git_remote_load
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
)
...
...
@@ -476,3 +485,26 @@ 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_buf_printf
(
&
buf
,
"refs/heads/*:refs/remotes/%s/*"
,
name
)
<
0
)
return
-
1
;
if
(
git_remote_new
(
out
,
repo
,
name
,
url
,
git_buf_cstr
(
&
buf
))
<
0
)
goto
on_error
;
git_buf_free
(
&
buf
);
if
(
git_remote_save
(
*
out
)
<
0
)
goto
on_error
;
return
0
;
on_error:
git_buf_free
(
&
buf
);
git_remote_free
(
*
out
);
return
-
1
;
}
tests-clar/network/remotelocal.c
View file @
1f796cd1
...
...
@@ -85,7 +85,7 @@ static void connect_to_local_repository(const char *local_repository)
{
build_local_file_url
(
&
file_path_buf
,
local_repository
);
cl_git_pass
(
git_remote_new
(
&
remote
,
repo
,
git_buf_cstr
(
&
file_path_buf
),
NULL
));
cl_git_pass
(
git_remote_new
(
&
remote
,
repo
,
NULL
,
git_buf_cstr
(
&
file_path_buf
),
NULL
));
cl_git_pass
(
git_remote_connect
(
remote
,
GIT_DIR_FETCH
));
}
...
...
tests-clar/network/remotes.c
View file @
1f796cd1
...
...
@@ -78,7 +78,7 @@ 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_new
(
&
_remote
,
_repo
,
"
upstream"
,
"git://github.com/libgit2/libgit2"
,
NULL
));
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
));
...
...
@@ -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