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
98c34149
Commit
98c34149
authored
Feb 28, 2016
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refs: honor strict object creation
parent
3ef01e77
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
9 deletions
+25
-9
src/refs.c
+1
-7
tests/refs/create.c
+24
-2
No files found.
src/refs.c
View file @
98c34149
...
@@ -377,15 +377,9 @@ static int reference__create(
...
@@ -377,15 +377,9 @@ static int reference__create(
return
error
;
return
error
;
if
(
oid
!=
NULL
)
{
if
(
oid
!=
NULL
)
{
git_odb
*
odb
;
assert
(
symbolic
==
NULL
);
assert
(
symbolic
==
NULL
);
/* Sanity check the reference being created - target must exist. */
if
(
!
git_object__is_valid
(
repo
,
oid
,
GIT_OBJ_ANY
))
{
if
((
error
=
git_repository_odb__weakptr
(
&
odb
,
repo
))
<
0
)
return
error
;
if
(
!
git_odb_exists
(
odb
,
oid
))
{
giterr_set
(
GITERR_REFERENCE
,
giterr_set
(
GITERR_REFERENCE
,
"Target OID for the reference doesn't exist on the repository"
);
"Target OID for the reference doesn't exist on the repository"
);
return
-
1
;
return
-
1
;
...
...
tests/refs/create.c
View file @
98c34149
...
@@ -18,6 +18,8 @@ void test_refs_create__initialize(void)
...
@@ -18,6 +18,8 @@ void test_refs_create__initialize(void)
void
test_refs_create__cleanup
(
void
)
void
test_refs_create__cleanup
(
void
)
{
{
cl_git_sandbox_cleanup
();
cl_git_sandbox_cleanup
();
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION
,
0
));
}
}
void
test_refs_create__symbolic
(
void
)
void
test_refs_create__symbolic
(
void
)
...
@@ -119,9 +121,27 @@ void test_refs_create__oid(void)
...
@@ -119,9 +121,27 @@ void test_refs_create__oid(void)
git_reference_free
(
looked_up_ref
);
git_reference_free
(
looked_up_ref
);
}
}
void
test_refs_create__oid_unknown
(
void
)
/* Can by default create a reference that targets at an unknown id */
void
test_refs_create__oid_unknown_succeeds_by_default
(
void
)
{
git_reference
*
new_reference
,
*
looked_up_ref
;
git_oid
id
;
const
char
*
new_head
=
"refs/heads/new-head"
;
git_oid_fromstr
(
&
id
,
"deadbeef3f795b2b4353bcce3a527ad0a4f7f644"
);
/* Create and write the new object id reference */
cl_git_pass
(
git_reference_create
(
&
new_reference
,
g_repo
,
new_head
,
&
id
,
0
,
NULL
));
/* Ensure the reference can't be looked-up... */
cl_git_pass
(
git_reference_lookup
(
&
looked_up_ref
,
g_repo
,
new_head
));
git_reference_free
(
looked_up_ref
);
}
/* Strict object enforcement enforces valid object id */
void
test_refs_create__oid_unknown_fails_strict_mode
(
void
)
{
{
// Can not create a new OID reference which targets at an unknown id
git_reference
*
new_reference
,
*
looked_up_ref
;
git_reference
*
new_reference
,
*
looked_up_ref
;
git_oid
id
;
git_oid
id
;
...
@@ -129,6 +149,8 @@ void test_refs_create__oid_unknown(void)
...
@@ -129,6 +149,8 @@ void test_refs_create__oid_unknown(void)
git_oid_fromstr
(
&
id
,
"deadbeef3f795b2b4353bcce3a527ad0a4f7f644"
);
git_oid_fromstr
(
&
id
,
"deadbeef3f795b2b4353bcce3a527ad0a4f7f644"
);
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION
,
1
));
/* Create and write the new object id reference */
/* Create and write the new object id reference */
cl_git_fail
(
git_reference_create
(
&
new_reference
,
g_repo
,
new_head
,
&
id
,
0
,
NULL
));
cl_git_fail
(
git_reference_create
(
&
new_reference
,
g_repo
,
new_head
,
&
id
,
0
,
NULL
));
...
...
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