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
a71c27cc
Commit
a71c27cc
authored
Dec 12, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow creation of dangling remotes
parent
6cacd44b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
38 deletions
+60
-38
include/git2/remote.h
+3
-3
src/remote.c
+47
-35
tests-clar/network/remotes.c
+10
-0
No files found.
include/git2/remote.h
View file @
a71c27cc
...
...
@@ -43,10 +43,10 @@ typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, voi
* See `git_tag_create()` for rules about valid names.
*
* @param out pointer to the new remote object
* @param repo the associated repository
* @param name the optional remote's name
* @param repo the associated repository
. May be NULL for a "dangling" remote.
* @param name the optional remote's name
. May be NULL.
* @param url the remote repository's URL
* @param fetch the fetch refspec to use for this remote
* @param fetch the fetch refspec to use for this remote
. May be NULL for defaults.
* @return 0, GIT_EINVALIDSPEC or an error code
*/
GIT_EXTERN
(
int
)
git_remote_new
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
url
,
const
char
*
fetch
);
...
...
src/remote.c
View file @
a71c27cc
...
...
@@ -88,7 +88,7 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con
git_remote
*
remote
;
/* name is optional */
assert
(
out
&&
repo
&&
url
);
assert
(
out
&&
url
);
remote
=
git__calloc
(
1
,
sizeof
(
git_remote
));
GITERR_CHECK_ALLOC
(
remote
);
...
...
@@ -289,6 +289,11 @@ int git_remote_save(const git_remote *remote)
assert
(
remote
);
if
(
!
remote
->
repo
)
{
giterr_set
(
GITERR_INVALID
,
"Can't save a dangling remote."
);
return
GIT_ERROR
;
}
if
((
error
=
ensure_remote_name_is_valid
(
remote
->
name
))
<
0
)
return
error
;
...
...
@@ -543,7 +548,7 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
assert
(
remote
);
if
(
!
proxy_url
)
if
(
!
proxy_url
||
!
remote
->
repo
)
return
-
1
;
*
proxy_url
=
NULL
;
...
...
@@ -745,6 +750,11 @@ int git_remote_update_tips(git_remote *remote)
assert
(
remote
);
if
(
!
remote
->
repo
)
{
giterr_set
(
GITERR_INVALID
,
"Can't update tips on a dangling remote."
);
return
GIT_ERROR
;
}
spec
=
&
remote
->
fetch
;
if
(
git_repository_odb__weakptr
(
&
odb
,
remote
->
repo
)
<
0
)
...
...
@@ -1293,49 +1303,51 @@ int git_remote_rename(
assert
(
remote
&&
new_name
);
if
((
error
=
ensure_remote_doesnot_exist
(
remote
->
repo
,
new_name
))
<
0
)
return
error
;
if
((
error
=
ensure_remote_name_is_valid
(
new_name
))
<
0
)
return
error
;
if
(
!
remote
->
name
)
{
if
((
error
=
rename_fetch_refspecs
(
remote
,
new_name
,
callback
,
payload
))
<
0
)
if
(
remote
->
repo
)
{
if
((
error
=
ensure_remote_doesnot_exist
(
remote
->
repo
,
new_name
))
<
0
)
return
error
;
remote
->
name
=
git__strdup
(
new_name
);
if
(
!
remote
->
name
)
{
if
((
error
=
rename_fetch_refspecs
(
remote
,
new_name
,
callback
,
payload
))
<
0
)
return
error
;
return
git_remote_save
(
remote
);
}
remote
->
name
=
git__strdup
(
new_name
);
if
((
error
=
rename_remote_config_section
(
remote
->
repo
,
remote
->
name
,
new_name
))
<
0
)
return
error
;
return
git_remote_save
(
remote
);
}
if
((
error
=
update_branch_remote_config_entry
(
remote
->
repo
,
remote
->
name
,
new_name
))
<
0
)
return
error
;
if
((
error
=
rename_remote_config_section
(
remote
->
repo
,
remote
->
name
,
new_name
))
<
0
)
return
error
;
if
((
error
=
rename_remote_references
(
remote
->
repo
,
remote
->
name
,
new_name
))
<
0
)
return
error
;
if
((
error
=
update_branch_remote_config_entry
(
remote
->
repo
,
remote
->
name
,
new_name
))
<
0
)
return
error
;
if
((
error
=
rename_fetch_refspecs
(
remote
,
new_name
,
callback
,
payload
))
<
0
)
return
error
;
if
((
error
=
rename_remote_references
(
remote
->
repo
,
remote
->
name
,
new_name
))
<
0
)
return
error
;
if
((
error
=
rename_fetch_refspecs
(
remote
,
new_name
,
callback
,
payload
))
<
0
)
return
error
;
}
git__free
(
remote
->
name
);
remote
->
name
=
git__strdup
(
new_name
);
...
...
tests-clar/network/remotes.c
View file @
a71c27cc
...
...
@@ -326,3 +326,13 @@ void test_network_remotes__check_structure_version(void)
err
=
giterr_last
();
cl_assert_equal_i
(
GITERR_INVALID
,
err
->
klass
);
}
void
test_network_remotes__dangling
(
void
)
{
cl_git_pass
(
git_remote_new
(
&
_remote
,
NULL
,
"upstream"
,
"git://github.com/libgit2/libgit2"
,
NULL
));
cl_git_fail
(
git_remote_save
(
_remote
));
cl_git_fail
(
git_remote_update_tips
(
_remote
));
cl_git_pass
(
git_remote_rename
(
_remote
,
"newname"
,
NULL
,
NULL
));
cl_assert_equal_s
(
git_remote_name
(
_remote
),
"newname"
);
}
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