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
3c79bafc
Commit
3c79bafc
authored
Jul 06, 2022
by
Miguel Arroz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reverting reflog move if an error happens.
parent
2546030d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
src/libgit2/refdb_fs.c
+3
-0
tests/libgit2/refs/branches/move.c
+16
-0
No files found.
src/libgit2/refdb_fs.c
View file @
3c79bafc
...
...
@@ -1779,17 +1779,20 @@ static int refdb_fs_backend__rename(
}
if
((
error
=
refdb_fs_backend__delete
(
_backend
,
old_name
,
NULL
,
NULL
))
<
0
)
{
refdb_reflog_fs__rename
(
_backend
,
new_name
,
old_name
);
git_reference_free
(
old
);
return
error
;
}
new
=
git_reference__realloc
(
&
old
,
new_name
);
if
(
!
new
)
{
refdb_reflog_fs__rename
(
_backend
,
new_name
,
old_name
);
git_reference_free
(
old
);
return
-
1
;
}
if
((
error
=
loose_lock
(
&
file
,
backend
,
new
->
name
))
<
0
)
{
refdb_reflog_fs__rename
(
_backend
,
new_name
,
old_name
);
git_reference_free
(
new
);
return
error
;
}
...
...
tests/libgit2/refs/branches/move.c
View file @
3c79bafc
...
...
@@ -232,3 +232,19 @@ void test_refs_branches_move__moves_reflog_correctly(void)
git_reflog_free
(
original_reflog
);
git_reflog_free
(
new_reflog
);
}
void
test_refs_branches_move__failed_move_restores_reflog
(
void
)
{
git_reference
*
original_ref
,
*
new_ref
;
git_reflog
*
recovered_reflog
;
cl_git_pass
(
git_reference_lookup
(
&
original_ref
,
repo
,
"refs/heads/br2"
));
cl_assert_equal_i
(
GIT_EINVALIDSPEC
,
git_branch_move
(
&
new_ref
,
original_ref
,
"Inv@{id"
,
0
));
cl_git_pass
(
git_reflog_read
(
&
recovered_reflog
,
repo
,
"refs/heads/br2"
));
cl_assert_equal_i
(
2
,
git_reflog_entrycount
(
recovered_reflog
));
git_reference_free
(
original_ref
);
git_reflog_free
(
recovered_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