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
d102bbba
Commit
d102bbba
authored
Jul 08, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #309 from schu/rr-flaw
reference_rename: fix flaw in force-renaming
parents
44b75a13
73294339
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
+41
-5
src/refs.c
+6
-2
tests/t10-refs.c
+35
-3
No files found.
src/refs.c
View file @
d102bbba
...
...
@@ -1309,8 +1309,12 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
new_name
=
normalized
;
error
=
git_reference_lookup
(
&
new_ref
,
ref
->
owner
,
new_name
);
if
(
error
==
GIT_SUCCESS
&&
!
force
)
return
git__throw
(
GIT_EEXISTS
,
"Failed to rename reference. Reference already exists"
);
if
(
error
==
GIT_SUCCESS
)
{
if
(
!
force
)
return
git__throw
(
GIT_EEXISTS
,
"Failed to rename reference. Reference already exists"
);
error
=
git_reference_delete
(
new_ref
);
}
if
(
error
<
GIT_SUCCESS
&&
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
...
...
tests/t10-refs.c
View file @
d102bbba
...
...
@@ -635,14 +635,16 @@ BEGIN_TEST(rename4, "can not rename a reference with an invalid name")
close_temp_repo
(
repo
);
END_TEST
BEGIN_TEST
(
rename5
,
"can force-rename a
reference with the name of an existing
reference"
)
BEGIN_TEST
(
rename5
,
"can force-rename a
packed reference with the name of an existing loose and packed
reference"
)
git_reference
*
looked_up_ref
;
git_repository
*
repo
;
git_oid
oid
;
must_pass
(
open_temp_repo
(
&
repo
,
REPOSITORY_FOLDER
));
/* An existing reference... */
must_pass
(
git_reference_lookup
(
&
looked_up_ref
,
repo
,
packed_head_name
));
git_oid_cpy
(
&
oid
,
git_reference_oid
(
looked_up_ref
));
/* Can be force-renamed to the name of another existing reference. */
must_pass
(
git_reference_rename
(
looked_up_ref
,
packed_test_head_name
,
1
));
...
...
@@ -650,6 +652,35 @@ BEGIN_TEST(rename5, "can force-rename a reference with the name of an existing r
/* Check we actually renamed it */
must_pass
(
git_reference_lookup
(
&
looked_up_ref
,
repo
,
packed_test_head_name
));
must_be_true
(
!
strcmp
(
looked_up_ref
->
name
,
packed_test_head_name
));
must_be_true
(
!
git_oid_cmp
(
&
oid
,
git_reference_oid
(
looked_up_ref
)));
/* And that the previous one doesn't exist any longer */
must_fail
(
git_reference_lookup
(
&
looked_up_ref
,
repo
,
packed_head_name
));
close_temp_repo
(
repo
);
END_TEST
BEGIN_TEST
(
rename6
,
"can force-rename a loose reference with the name of an existing loose reference"
)
git_reference
*
looked_up_ref
;
git_repository
*
repo
;
git_oid
oid
;
must_pass
(
open_temp_repo
(
&
repo
,
REPOSITORY_FOLDER
));
/* An existing reference... */
must_pass
(
git_reference_lookup
(
&
looked_up_ref
,
repo
,
"refs/heads/br2"
));
git_oid_cpy
(
&
oid
,
git_reference_oid
(
looked_up_ref
));
/* Can be force-renamed to the name of another existing reference. */
must_pass
(
git_reference_rename
(
looked_up_ref
,
"refs/heads/test"
,
1
));
/* Check we actually renamed it */
must_pass
(
git_reference_lookup
(
&
looked_up_ref
,
repo
,
"refs/heads/test"
));
must_be_true
(
!
strcmp
(
looked_up_ref
->
name
,
"refs/heads/test"
));
must_be_true
(
!
git_oid_cmp
(
&
oid
,
git_reference_oid
(
looked_up_ref
)));
/* And that the previous one doesn't exist any longer */
must_fail
(
git_reference_lookup
(
&
looked_up_ref
,
repo
,
"refs/heads/br2"
));
close_temp_repo
(
repo
);
END_TEST
...
...
@@ -658,7 +689,7 @@ static const char *ref_one_name = "refs/heads/one/branch";
static
const
char
*
ref_one_name_new
=
"refs/heads/two/branch"
;
static
const
char
*
ref_two_name
=
"refs/heads/two"
;
BEGIN_TEST
(
rename
6
,
"can not overwrite name of existing reference"
)
BEGIN_TEST
(
rename
7
,
"can not overwrite name of existing reference"
)
git_reference
*
ref
,
*
ref_one
,
*
ref_one_new
,
*
ref_two
;
git_repository
*
repo
;
git_oid
id
;
...
...
@@ -688,7 +719,7 @@ END_TEST
static
const
char
*
ref_two_name_new
=
"refs/heads/two/two"
;
BEGIN_TEST
(
rename
7
,
"can be renamed to a new name prefixed with the old name"
)
BEGIN_TEST
(
rename
8
,
"can be renamed to a new name prefixed with the old name"
)
git_reference
*
ref
,
*
ref_two
,
*
looked_up_ref
;
git_repository
*
repo
;
git_oid
id
;
...
...
@@ -1000,6 +1031,7 @@ BEGIN_SUITE(refs)
ADD_TEST
(
rename5
);
ADD_TEST
(
rename6
);
ADD_TEST
(
rename7
);
ADD_TEST
(
rename8
);
ADD_TEST
(
delete0
);
ADD_TEST
(
list0
);
...
...
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