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
7a830f28
Commit
7a830f28
authored
Dec 30, 2017
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refs:iterator: add tests to recurse symlinks
Ensure that we can recurse into directories via symbolic links.
parent
9e94b6af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
18 deletions
+66
-18
tests/refs/iterator.c
+66
-18
No files found.
tests/refs/iterator.c
View file @
7a830f28
...
...
@@ -6,12 +6,12 @@ static git_repository *repo;
void
test_refs_iterator__initialize
(
void
)
{
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
))
);
repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
}
void
test_refs_iterator__cleanup
(
void
)
{
git_repository_free
(
repo
);
cl_git_sandbox_cleanup
(
);
}
static
const
char
*
refnames
[]
=
{
...
...
@@ -36,6 +36,36 @@ static const char *refnames[] = {
"refs/tags/taggerless"
,
"refs/tags/test"
,
"refs/tags/wrapped_tag"
,
NULL
};
static
const
char
*
refnames_with_symlink
[]
=
{
"refs/heads/br2"
,
"refs/heads/cannot-fetch"
,
"refs/heads/chomped"
,
"refs/heads/haacked"
,
"refs/heads/link/a"
,
"refs/heads/link/b"
,
"refs/heads/link/c"
,
"refs/heads/link/d"
,
"refs/heads/master"
,
"refs/heads/not-good"
,
"refs/heads/packed"
,
"refs/heads/packed-test"
,
"refs/heads/subtrees"
,
"refs/heads/test"
,
"refs/heads/track-local"
,
"refs/heads/trailing"
,
"refs/notes/fanout"
,
"refs/remotes/test/master"
,
"refs/tags/annotated_tag_to_blob"
,
"refs/tags/e90810b"
,
"refs/tags/hard_tag"
,
"refs/tags/point_to_blob"
,
"refs/tags/taggerless"
,
"refs/tags/test"
,
"refs/tags/wrapped_tag"
,
NULL
};
static
int
refcmp_cb
(
const
void
*
a
,
const
void
*
b
)
...
...
@@ -46,21 +76,21 @@ static int refcmp_cb(const void *a, const void *b)
return
strcmp
(
refa
->
name
,
refb
->
name
);
}
static
void
assert_all_refnames_match
(
git_vector
*
output
)
static
void
assert_all_refnames_match
(
const
char
**
expected
,
git_vector
*
names
)
{
size_t
i
;
git_reference
*
ref
;
cl_assert_equal_sz
(
output
->
length
,
ARRAY_SIZE
(
refnames
));
git_vector_sort
(
output
);
git_vector_sort
(
names
);
git_vector_foreach
(
output
,
i
,
ref
)
{
cl_assert_equal_s
(
ref
->
name
,
refnames
[
i
]);
git_vector_foreach
(
names
,
i
,
ref
)
{
cl_assert
(
expected
[
i
]
!=
NULL
);
cl_assert_equal_s
(
expected
[
i
],
ref
->
name
);
git_reference_free
(
ref
);
}
cl_assert
(
expected
[
i
]
==
NULL
);
git_vector_free
(
output
);
git_vector_free
(
names
);
}
void
test_refs_iterator__list
(
void
)
...
...
@@ -82,7 +112,7 @@ void test_refs_iterator__list(void)
git_reference_iterator_free
(
iter
);
assert_all_refnames_match
(
&
output
);
assert_all_refnames_match
(
refnames
,
&
output
);
}
void
test_refs_iterator__empty
(
void
)
...
...
@@ -115,7 +145,29 @@ void test_refs_iterator__foreach(void)
git_vector
output
;
cl_git_pass
(
git_vector_init
(
&
output
,
32
,
&
refcmp_cb
));
cl_git_pass
(
git_reference_foreach
(
repo
,
refs_foreach_cb
,
&
output
));
assert_all_refnames_match
(
&
output
);
assert_all_refnames_match
(
refnames
,
&
output
);
}
void
test_refs_iterator__foreach_through_symlink
(
void
)
{
git_vector
output
;
#ifdef GIT_WIN32
cl_skip
();
#endif
cl_git_pass
(
git_vector_init
(
&
output
,
32
,
&
refcmp_cb
));
cl_git_pass
(
p_mkdir
(
"refs"
,
0777
));
cl_git_mkfile
(
"refs/a"
,
"1234567890123456789012345678901234567890"
);
cl_git_mkfile
(
"refs/b"
,
"1234567890123456789012345678901234567890"
);
cl_git_mkfile
(
"refs/c"
,
"1234567890123456789012345678901234567890"
);
cl_git_mkfile
(
"refs/d"
,
"1234567890123456789012345678901234567890"
);
cl_git_pass
(
p_symlink
(
"../../../refs"
,
"testrepo.git/refs/heads/link"
));
cl_git_pass
(
git_reference_foreach
(
repo
,
refs_foreach_cb
,
&
output
));
assert_all_refnames_match
(
refnames_with_symlink
,
&
output
);
}
static
int
refs_foreach_cancel_cb
(
git_reference
*
reference
,
void
*
payload
)
...
...
@@ -156,12 +208,11 @@ void test_refs_iterator__foreach_name(void)
cl_git_pass
(
git_reference_foreach_name
(
repo
,
refs_foreach_name_cb
,
&
output
));
cl_assert_equal_sz
(
output
.
length
,
ARRAY_SIZE
(
refnames
));
git_vector_sort
(
&
output
);
git_vector_foreach
(
&
output
,
i
,
name
)
{
cl_assert
_equal_s
(
name
,
refnames
[
i
]
);
git__free
(
name
);
cl_assert
(
refnames
[
i
]
!=
NULL
);
cl_assert_equal_s
(
refnames
[
i
],
name
);
}
git_vector_free
(
&
output
);
...
...
@@ -194,7 +245,7 @@ void test_refs_iterator__concurrent_delete(void)
const
char
*
name
;
int
error
;
git_repository_free
(
repo
);
cl_git_sandbox_cleanup
(
);
repo
=
cl_git_sandbox_init
(
"testrepo"
);
cl_git_pass
(
git_reference_iterator_new
(
&
iter
,
repo
));
...
...
@@ -215,7 +266,4 @@ void test_refs_iterator__concurrent_delete(void)
cl_assert_equal_i
(
GIT_ITEROVER
,
error
);
cl_assert_equal_i
(
full_count
,
concurrent_count
);
cl_git_sandbox_cleanup
();
repo
=
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