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
716e20b4
Commit
716e20b4
authored
Jun 06, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2404 from libgit2/cmn/remote-rename-fixes
Remote rename fixes
parents
c073184e
a52ab4b8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
7 deletions
+39
-7
src/remote.c
+9
-7
tests/network/remote/rename.c
+30
-0
No files found.
src/remote.c
View file @
716e20b4
...
...
@@ -1380,7 +1380,7 @@ static int rename_one_remote_reference(
goto
cleanup
;
error
=
git_reference_rename
(
NULL
,
reference
,
git_buf_cstr
(
&
new_name
),
0
,
NULL
,
reference
,
git_buf_cstr
(
&
new_name
),
1
,
NULL
,
git_buf_cstr
(
&
log_message
));
git_reference_free
(
reference
);
...
...
@@ -1396,18 +1396,20 @@ static int rename_remote_references(
const
char
*
new_name
)
{
int
error
;
git_buf
buf
=
GIT_BUF_INIT
;
git_reference
*
ref
;
git_reference_iterator
*
iter
;
if
((
error
=
git_
reference_iterator_new
(
&
iter
,
repo
))
<
0
)
if
((
error
=
git_
buf_printf
(
&
buf
,
GIT_REFS_REMOTES_DIR
"%s/*"
,
old_name
))
<
0
)
return
error
;
while
((
error
=
git_reference_next
(
&
ref
,
iter
))
==
0
)
{
if
(
git__prefixcmp
(
ref
->
name
,
GIT_REFS_REMOTES_DIR
))
{
git_reference_free
(
ref
);
continue
;
}
error
=
git_reference_iterator_glob_new
(
&
iter
,
repo
,
git_buf_cstr
(
&
buf
));
git_buf_free
(
&
buf
);
if
(
error
<
0
)
return
error
;
while
((
error
=
git_reference_next
(
&
ref
,
iter
))
==
0
)
{
if
((
error
=
rename_one_remote_reference
(
ref
,
old_name
,
new_name
))
<
0
)
break
;
}
...
...
tests/network/remote/rename.c
View file @
716e20b4
...
...
@@ -172,3 +172,33 @@ void test_network_remote_rename__cannot_rename_an_inmemory_remote(void)
git_remote_free
(
remote
);
}
void
test_network_remote_rename__overwrite_ref_in_target
(
void
)
{
git_oid
id
;
char
idstr
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
git_remote
*
remote
;
git_reference
*
ref
;
git_branch_t
btype
;
git_branch_iterator
*
iter
;
cl_git_pass
(
git_oid_fromstr
(
&
id
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
));
cl_git_pass
(
git_reference_create
(
&
ref
,
_repo
,
"refs/remotes/renamed/master"
,
&
id
,
1
,
NULL
,
NULL
));
git_reference_free
(
ref
);
cl_git_pass
(
git_remote_load
(
&
remote
,
_repo
,
"test"
));
cl_git_pass
(
git_remote_rename
(
remote
,
"renamed"
,
dont_call_me_cb
,
NULL
));
git_remote_free
(
remote
);
/* make sure there's only one remote-tracking branch */
cl_git_pass
(
git_branch_iterator_new
(
&
iter
,
_repo
,
GIT_BRANCH_REMOTE
));
cl_git_pass
(
git_branch_next
(
&
ref
,
&
btype
,
iter
));
cl_assert_equal_s
(
"refs/remotes/renamed/master"
,
git_reference_name
(
ref
));
git_oid_fmt
(
idstr
,
git_reference_target
(
ref
));
cl_assert_equal_s
(
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644"
,
idstr
);
git_reference_free
(
ref
);
cl_git_fail_with
(
GIT_ITEROVER
,
git_branch_next
(
&
ref
,
&
btype
,
iter
));
git_branch_iterator_free
(
iter
);
}
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