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
2546030d
Commit
2546030d
authored
Jul 06, 2022
by
Miguel Arroz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #6344: git_branch_move now renames the reflog instead of deleting.
parent
1a94d97e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
5 deletions
+38
-5
src/libgit2/refdb_fs.c
+16
-5
tests/libgit2/refs/branches/move.c
+22
-0
No files found.
src/libgit2/refdb_fs.c
View file @
2546030d
...
...
@@ -1769,6 +1769,15 @@ static int refdb_fs_backend__rename(
(
error
=
refdb_fs_backend__lookup
(
&
old
,
_backend
,
old_name
))
<
0
)
return
error
;
/* Try to rename the refog; it's ok if the old doesn't exist */
/* Must be done before calling refdb_fs_backend__delete, otherwise */
/* the reflog is deleted before being renamed. */
error
=
refdb_reflog_fs__rename
(
_backend
,
old_name
,
new_name
);
if
((
error
!=
0
)
&&
(
error
!=
GIT_ENOTFOUND
))
{
git_reference_free
(
old
);
return
error
;
}
if
((
error
=
refdb_fs_backend__delete
(
_backend
,
old_name
,
NULL
,
NULL
))
<
0
)
{
git_reference_free
(
old
);
return
error
;
...
...
@@ -1785,10 +1794,7 @@ static int refdb_fs_backend__rename(
return
error
;
}
/* Try to rename the refog; it's ok if the old doesn't exist */
error
=
refdb_reflog_fs__rename
(
_backend
,
old_name
,
new_name
);
if
(((
error
==
0
)
||
(
error
==
GIT_ENOTFOUND
))
&&
((
error
=
reflog_append
(
backend
,
new
,
git_reference_target
(
new
),
NULL
,
who
,
message
))
<
0
))
{
if
((
error
=
reflog_append
(
backend
,
new
,
git_reference_target
(
new
),
NULL
,
who
,
message
))
<
0
)
{
git_reference_free
(
new
);
git_filebuf_cleanup
(
&
file
);
return
error
;
...
...
@@ -2368,7 +2374,12 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
if
((
error
=
reflog_path
(
&
path
,
backend
->
repo
,
name
))
<
0
)
goto
out
;
if
(
!
git_fs_path_exists
(
path
.
ptr
))
/*
* If a reference was moved downwards, eg refs/heads/br2 -> refs/heads/br2/new-name,
* refs/heads/br2 does exist but it's a directory. That's a valid situation.
* Proceed only if it's a file.
*/
if
(
!
git_fs_path_isfile
(
path
.
ptr
))
goto
out
;
if
((
error
=
p_unlink
(
path
.
ptr
))
<
0
)
...
...
tests/libgit2/refs/branches/move.c
View file @
2546030d
...
...
@@ -210,3 +210,25 @@ void test_refs_branches_move__can_move_with_unicode(void)
git_reference_free
(
original_ref
);
git_reference_free
(
new_ref
);
}
void
test_refs_branches_move__moves_reflog_correctly
(
void
)
{
git_reference
*
original_ref
,
*
new_ref
;
git_reflog
*
original_reflog
,
*
new_reflog
;
cl_git_pass
(
git_reference_lookup
(
&
original_ref
,
repo
,
"refs/heads/br2"
));
cl_git_pass
(
git_reflog_read
(
&
original_reflog
,
repo
,
"refs/heads/br2"
));
cl_assert_equal_i
(
2
,
git_reflog_entrycount
(
original_reflog
));
cl_git_pass
(
git_branch_move
(
&
new_ref
,
original_ref
,
NEW_BRANCH_NAME
,
0
));
cl_assert_equal_s
(
GIT_REFS_HEADS_DIR
NEW_BRANCH_NAME
,
git_reference_name
(
new_ref
));
cl_git_pass
(
git_reflog_read
(
&
new_reflog
,
repo
,
GIT_REFS_HEADS_DIR
NEW_BRANCH_NAME
));
cl_assert_equal_i
(
3
,
git_reflog_entrycount
(
new_reflog
));
git_reference_free
(
original_ref
);
git_reference_free
(
new_ref
);
git_reflog_free
(
original_reflog
);
git_reflog_free
(
new_reflog
);
}
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