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
a4b5ac64
Commit
a4b5ac64
authored
Feb 26, 2017
by
Edward Thomson
Committed by
GitHub
Feb 26, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4138 from richardipsum/symbolic-create-arbitrary-tgt-test
tests: Add create__symbolic_with_arbitrary_content
parents
55d911d6
b84e58f4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
5 deletions
+54
-5
tests/refs/create.c
+54
-5
No files found.
tests/refs/create.c
View file @
a4b5ac64
...
...
@@ -12,19 +12,20 @@ static git_repository *g_repo;
void
test_refs_create__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
}
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
,
1
));
cl_git_pass
(
git_libgit2_opts
(
GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION
,
1
));
}
void
test_refs_create__symbolic
(
void
)
{
// create a new symbolic reference
/* create a new symbolic reference */
git_reference
*
new_reference
,
*
looked_up_ref
,
*
resolved_ref
;
git_repository
*
repo2
;
git_oid
id
;
...
...
@@ -65,9 +66,57 @@ void test_refs_create__symbolic(void)
git_reference_free
(
resolved_ref
);
}
void
test_refs_create__symbolic_with_arbitrary_content
(
void
)
{
git_reference
*
new_reference
,
*
looked_up_ref
;
git_repository
*
repo2
;
git_oid
id
;
const
char
*
new_head_tracker
=
"ANOTHER_HEAD_TRACKER"
;
const
char
*
arbitrary_target
=
"ARBITRARY DATA"
;
git_oid_fromstr
(
&
id
,
current_master_tip
);
/* Attempt to create symbolic ref with arbitrary data in target
* fails by default
*/
cl_git_fail
(
git_reference_symbolic_create
(
&
new_reference
,
g_repo
,
new_head_tracker
,
arbitrary_target
,
0
,
NULL
));
git_libgit2_opts
(
GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION
,
0
);
/* With strict target validation disabled, ref creation succeeds */
cl_git_pass
(
git_reference_symbolic_create
(
&
new_reference
,
g_repo
,
new_head_tracker
,
arbitrary_target
,
0
,
NULL
));
/* Ensure the reference can be looked-up... */
cl_git_pass
(
git_reference_lookup
(
&
looked_up_ref
,
g_repo
,
new_head_tracker
));
cl_assert
(
git_reference_type
(
looked_up_ref
)
&
GIT_REF_SYMBOLIC
);
cl_assert
(
reference_is_packed
(
looked_up_ref
)
==
0
);
cl_assert_equal_s
(
looked_up_ref
->
name
,
new_head_tracker
);
/* Ensure the target is what we expect it to be */
cl_assert_equal_s
(
git_reference_symbolic_target
(
new_reference
),
arbitrary_target
);
/* Similar test with a fresh new repository object */
cl_git_pass
(
git_repository_open
(
&
repo2
,
"testrepo"
));
/* Ensure the reference can be looked-up... */
cl_git_pass
(
git_reference_lookup
(
&
looked_up_ref
,
repo2
,
new_head_tracker
));
cl_assert
(
git_reference_type
(
looked_up_ref
)
&
GIT_REF_SYMBOLIC
);
cl_assert
(
reference_is_packed
(
looked_up_ref
)
==
0
);
cl_assert_equal_s
(
looked_up_ref
->
name
,
new_head_tracker
);
/* Ensure the target is what we expect it to be */
cl_assert_equal_s
(
git_reference_symbolic_target
(
new_reference
),
arbitrary_target
);
git_repository_free
(
repo2
);
git_reference_free
(
new_reference
);
git_reference_free
(
looked_up_ref
);
}
void
test_refs_create__deep_symbolic
(
void
)
{
// create a deep symbolic reference
/* create a deep symbolic reference */
git_reference
*
new_reference
,
*
looked_up_ref
,
*
resolved_ref
;
git_oid
id
;
...
...
@@ -87,7 +136,7 @@ void test_refs_create__deep_symbolic(void)
void
test_refs_create__oid
(
void
)
{
// create a new OID reference
/* create a new OID reference */
git_reference
*
new_reference
,
*
looked_up_ref
;
git_repository
*
repo2
;
git_oid
id
;
...
...
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