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
80212ecb
Commit
80212ecb
authored
Nov 12, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflog: Deploy EINVALIDSPEC usage
parent
e4aa7f58
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
4 deletions
+28
-4
include/git2/reflog.h
+4
-1
src/reflog.c
+12
-3
tests-clar/refs/reflog/reflog.c
+12
-0
No files found.
include/git2/reflog.h
View file @
80212ecb
...
...
@@ -63,9 +63,12 @@ GIT_EXTERN(int) git_reflog_append(git_reflog *reflog, const git_oid *id, const g
*
* The reflog to be renamed is expected to already exist
*
* The new name will be checked for validity.
* See `git_reference_create_symbolic()` for rules about valid names.
*
* @param ref the reference
* @param name the new name of the reference
* @return 0 or an error code
* @return 0 o
n success, GIT_EINVALIDSPEC o
r an error code
*/
GIT_EXTERN
(
int
)
git_reflog_rename
(
git_reference
*
ref
,
const
char
*
name
);
...
...
src/reflog.c
View file @
80212ecb
...
...
@@ -340,21 +340,29 @@ cleanup:
int
git_reflog_rename
(
git_reference
*
ref
,
const
char
*
new_name
)
{
int
error
=
-
1
,
fd
;
int
error
,
fd
;
git_buf
old_path
=
GIT_BUF_INIT
;
git_buf
new_path
=
GIT_BUF_INIT
;
git_buf
temp_path
=
GIT_BUF_INIT
;
git_buf
normalized
=
GIT_BUF_INIT
;
assert
(
ref
&&
new_name
);
if
((
error
=
git_reference__normalize_name
(
&
normalized
,
new_name
,
GIT_REF_FORMAT_ALLOW_ONELEVEL
))
<
0
)
goto
cleanup
;
error
=
-
1
;
if
(
git_buf_joinpath
(
&
temp_path
,
git_reference_owner
(
ref
)
->
path_repository
,
GIT_REFLOG_DIR
)
<
0
)
return
-
1
;
if
(
git_buf_joinpath
(
&
old_path
,
git_buf_cstr
(
&
temp_path
),
ref
->
name
)
<
0
)
goto
cleanup
;
if
(
git_buf_joinpath
(
&
new_path
,
git_buf_cstr
(
&
temp_path
),
new_name
)
<
0
)
goto
cleanup
;
if
(
git_buf_joinpath
(
&
new_path
,
git_buf_cstr
(
&
temp_path
),
git_buf_cstr
(
&
normalized
))
<
0
)
goto
cleanup
;
/*
* Move the reflog to a temporary place. This two-phase renaming is required
...
...
@@ -386,6 +394,7 @@ cleanup:
git_buf_free
(
&
temp_path
);
git_buf_free
(
&
old_path
);
git_buf_free
(
&
new_path
);
git_buf_free
(
&
normalized
);
return
error
;
}
...
...
tests-clar/refs/reflog/reflog.c
View file @
80212ecb
...
...
@@ -170,3 +170,15 @@ void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
git_buf_free
(
&
moved_log_path
);
git_buf_free
(
&
master_log_path
);
}
void
test_refs_reflog_reflog__renaming_with_an_invalid_name_returns_EINVALIDSPEC
(
void
)
{
git_reference
*
master
;
cl_git_pass
(
git_reference_lookup
(
&
master
,
g_repo
,
"refs/heads/master"
));
cl_assert_equal_i
(
GIT_EINVALIDSPEC
,
git_reflog_rename
(
master
,
"refs/heads/Inv@{id"
));
git_reference_free
(
master
);
}
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