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
270303ca
Commit
270303ca
authored
Mar 31, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved more assertions inside Clar test helpers.
parent
9297b6e0
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
105 additions
and
166 deletions
+105
-166
tests-clar/index/tests.c
+10
-16
tests-clar/object/raw/hash.c
+20
-16
tests-clar/object/raw/write.c
+23
-53
tests-clar/object/tag/read.c
+9
-9
tests-clar/object/tag/write.c
+4
-6
tests-clar/refs/reflog.c
+8
-19
tests-clar/repo/discover.c
+31
-47
No files found.
tests-clar/index/tests.c
View file @
270303ca
...
...
@@ -26,49 +26,43 @@ static struct test_entry test_entries[] = {
// Helpers
static
int
copy_file
(
const
char
*
src
,
const
char
*
dst
)
static
void
copy_file
(
const
char
*
src
,
const
char
*
dst
)
{
git_buf
source_buf
=
GIT_BUF_INIT
;
git_file
dst_fd
;
int
error
=
GIT_ERROR
;
if
(
git_futils_readbuffer
(
&
source_buf
,
src
)
<
GIT_SUCCESS
)
return
GIT_ENOTFOUND
;
cl_git_pass
(
git_futils_readbuffer
(
&
source_buf
,
src
));
dst_fd
=
git_futils_creat_withpath
(
dst
,
0777
,
0666
);
if
(
dst_fd
<
0
)
goto
cleanup
;
error
=
p_write
(
dst_fd
,
source_buf
.
ptr
,
source_buf
.
size
);
cl_git_pass
(
p_write
(
dst_fd
,
source_buf
.
ptr
,
source_buf
.
size
)
);
cleanup:
git_buf_free
(
&
source_buf
);
p_close
(
dst_fd
);
return
error
;
}
static
int
cmp_files
(
const
char
*
a
,
const
char
*
b
)
static
void
files_are_equal
(
const
char
*
a
,
const
char
*
b
)
{
git_buf
buf_a
=
GIT_BUF_INIT
;
git_buf
buf_b
=
GIT_BUF_INIT
;
int
error
=
GIT_ERROR
;
int
pass
;
if
(
git_futils_readbuffer
(
&
buf_a
,
a
)
<
GIT_SUCCESS
)
return
GIT_ERROR
;
cl_assert
(
0
)
;
if
(
git_futils_readbuffer
(
&
buf_b
,
b
)
<
GIT_SUCCESS
)
{
git_buf_free
(
&
buf_a
);
return
GIT_ERROR
;
cl_assert
(
0
)
;
}
if
(
buf_a
.
size
==
buf_b
.
size
&&
!
memcmp
(
buf_a
.
ptr
,
buf_b
.
ptr
,
buf_a
.
size
))
error
=
GIT_SUCCESS
;
pass
=
(
buf_a
.
size
==
buf_b
.
size
&&
!
memcmp
(
buf_a
.
ptr
,
buf_b
.
ptr
,
buf_a
.
size
));
git_buf_free
(
&
buf_a
);
git_buf_free
(
&
buf_b
);
return
error
;
}
...
...
@@ -168,13 +162,13 @@ void test_index_tests__write(void)
{
git_index
*
index
;
c
l_git_pass
(
copy_file
(
TEST_INDEXBIG_PATH
,
"index_rewrite"
)
);
c
opy_file
(
TEST_INDEXBIG_PATH
,
"index_rewrite"
);
cl_git_pass
(
git_index_open
(
&
index
,
"index_rewrite"
));
cl_assert
(
index
->
on_disk
);
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
cmp_files
(
TEST_INDEXBIG_PATH
,
"index_rewrite"
)
);
files_are_equal
(
TEST_INDEXBIG_PATH
,
"index_rewrite"
);
git_index_free
(
index
);
...
...
tests-clar/object/raw/hash.c
View file @
270303ca
...
...
@@ -6,9 +6,13 @@
#include "data.h"
static
int
hash_object
(
git_oid
*
oid
,
git_rawobj
*
obj
)
static
void
hash_object_pass
(
git_oid
*
oid
,
git_rawobj
*
obj
)
{
return
git_odb_hash
(
oid
,
obj
->
data
,
obj
->
len
,
obj
->
type
);
cl_git_pass
(
git_odb_hash
(
oid
,
obj
->
data
,
obj
->
len
,
obj
->
type
));
}
static
void
hash_object_fail
(
git_oid
*
oid
,
git_rawobj
*
obj
)
{
cl_git_fail
(
git_odb_hash
(
oid
,
obj
->
data
,
obj
->
len
,
obj
->
type
));
}
static
char
*
hello_id
=
"22596363b3de40b06f981fb85d82312e8c0ed511"
;
...
...
@@ -74,28 +78,28 @@ void test_object_raw_hash__hash_junk_data(void)
/* invalid types: */
junk_obj
.
data
=
some_data
;
cl_git_fail
(
hash_object
(
&
id
,
&
junk_obj
)
);
hash_object_fail
(
&
id
,
&
junk_obj
);
junk_obj
.
type
=
GIT_OBJ__EXT1
;
cl_git_fail
(
hash_object
(
&
id
,
&
junk_obj
)
);
hash_object_fail
(
&
id
,
&
junk_obj
);
junk_obj
.
type
=
GIT_OBJ__EXT2
;
cl_git_fail
(
hash_object
(
&
id
,
&
junk_obj
)
);
hash_object_fail
(
&
id
,
&
junk_obj
);
junk_obj
.
type
=
GIT_OBJ_OFS_DELTA
;
cl_git_fail
(
hash_object
(
&
id
,
&
junk_obj
)
);
hash_object_fail
(
&
id
,
&
junk_obj
);
junk_obj
.
type
=
GIT_OBJ_REF_DELTA
;
cl_git_fail
(
hash_object
(
&
id
,
&
junk_obj
)
);
hash_object_fail
(
&
id
,
&
junk_obj
);
/* data can be NULL only if len is zero: */
junk_obj
.
type
=
GIT_OBJ_BLOB
;
junk_obj
.
data
=
NULL
;
cl_git_pass
(
hash_object
(
&
id
,
&
junk_obj
)
);
hash_object_pass
(
&
id
,
&
junk_obj
);
cl_assert
(
git_oid_cmp
(
&
id
,
&
id_zero
)
==
0
);
junk_obj
.
len
=
1
;
cl_git_fail
(
hash_object
(
&
id
,
&
junk_obj
)
);
hash_object_fail
(
&
id
,
&
junk_obj
);
}
void
test_object_raw_hash__hash_commit_object
(
void
)
...
...
@@ -103,7 +107,7 @@ void test_object_raw_hash__hash_commit_object(void)
git_oid
id1
,
id2
;
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
commit_id
));
cl_git_pass
(
hash_object
(
&
id2
,
&
commit_obj
)
);
hash_object_pass
(
&
id2
,
&
commit_obj
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
...
...
@@ -112,7 +116,7 @@ void test_object_raw_hash__hash_tree_object(void)
git_oid
id1
,
id2
;
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
tree_id
));
cl_git_pass
(
hash_object
(
&
id2
,
&
tree_obj
)
);
hash_object_pass
(
&
id2
,
&
tree_obj
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
...
...
@@ -121,7 +125,7 @@ void test_object_raw_hash__hash_tag_object(void)
git_oid
id1
,
id2
;
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
tag_id
));
cl_git_pass
(
hash_object
(
&
id2
,
&
tag_obj
)
);
hash_object_pass
(
&
id2
,
&
tag_obj
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
...
...
@@ -130,7 +134,7 @@ void test_object_raw_hash__hash_zero_length_object(void)
git_oid
id1
,
id2
;
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
zero_id
));
cl_git_pass
(
hash_object
(
&
id2
,
&
zero_obj
)
);
hash_object_pass
(
&
id2
,
&
zero_obj
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
...
...
@@ -139,7 +143,7 @@ void test_object_raw_hash__hash_one_byte_object(void)
git_oid
id1
,
id2
;
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
one_id
));
cl_git_pass
(
hash_object
(
&
id2
,
&
one_obj
)
);
hash_object_pass
(
&
id2
,
&
one_obj
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
...
...
@@ -148,7 +152,7 @@ void test_object_raw_hash__hash_two_byte_object(void)
git_oid
id1
,
id2
;
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
two_id
));
cl_git_pass
(
hash_object
(
&
id2
,
&
two_obj
)
);
hash_object_pass
(
&
id2
,
&
two_obj
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
...
...
@@ -157,6 +161,6 @@ void test_object_raw_hash__hash_multi_byte_object(void)
git_oid
id1
,
id2
;
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
some_id
));
cl_git_pass
(
hash_object
(
&
id2
,
&
some_obj
)
);
hash_object_pass
(
&
id2
,
&
some_obj
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
}
tests-clar/object/raw/write.c
View file @
270303ca
...
...
@@ -16,73 +16,43 @@ void test_body(object_data *d, git_rawobj *o);
// Helpers
static
int
remove_object_files
(
object_data
*
d
)
static
void
remove_object_files
(
object_data
*
d
)
{
if
(
p_unlink
(
d
->
file
)
<
0
)
{
fprintf
(
stderr
,
"can't delete object file
\"
%s
\"\n
"
,
d
->
file
);
return
-
1
;
}
if
((
p_rmdir
(
d
->
dir
)
<
0
)
&&
(
errno
!=
ENOTEMPTY
))
{
fprintf
(
stderr
,
"can't remove directory
\"
%s
\"\n
"
,
d
->
dir
);
return
-
1
;
}
if
(
p_rmdir
(
odb_dir
)
<
0
)
{
fprintf
(
stderr
,
"can't remove directory
\"
%s
\"\n
"
,
odb_dir
);
return
-
1
;
}
return
0
;
cl_git_pass
(
p_unlink
(
d
->
file
));
cl_git_pass
(
p_rmdir
(
d
->
dir
));
cl_assert
(
errno
!=
ENOTEMPTY
);
cl_git_pass
(
p_rmdir
(
odb_dir
)
<
0
);
}
static
int
streaming_write
(
git_oid
*
oid
,
git_odb
*
odb
,
git_rawobj
*
raw
)
static
void
streaming_write
(
git_oid
*
oid
,
git_odb
*
odb
,
git_rawobj
*
raw
)
{
git_odb_stream
*
stream
;
int
error
;
if
((
error
=
git_odb_open_wstream
(
&
stream
,
odb
,
raw
->
len
,
raw
->
type
))
<
GIT_SUCCESS
)
return
error
;
cl_git_pass
(
git_odb_open_wstream
(
&
stream
,
odb
,
raw
->
len
,
raw
->
type
));
stream
->
write
(
stream
,
raw
->
data
,
raw
->
len
);
error
=
stream
->
finalize_write
(
oid
,
stream
);
stream
->
free
(
stream
);
return
error
;
cl_git_pass
(
error
);
}
static
int
check_object_files
(
object_data
*
d
)
static
void
check_object_files
(
object_data
*
d
)
{
if
(
git_path_exists
(
d
->
dir
)
<
0
)
return
-
1
;
if
(
git_path_exists
(
d
->
file
)
<
0
)
return
-
1
;
return
0
;
cl_git_pass
(
git_path_exists
(
d
->
dir
));
cl_git_pass
(
git_path_exists
(
d
->
file
));
}
static
int
cmp_objects
(
git_rawobj
*
o1
,
git_rawobj
*
o2
)
static
void
cmp_objects
(
git_rawobj
*
o1
,
git_rawobj
*
o2
)
{
if
(
o1
->
type
!=
o2
->
type
)
return
-
1
;
if
(
o1
->
len
!=
o2
->
len
)
return
-
1
;
if
((
o1
->
len
>
0
)
&&
(
memcmp
(
o1
->
data
,
o2
->
data
,
o1
->
len
)
!=
0
))
return
-
1
;
return
0
;
cl_assert
(
o1
->
type
==
o2
->
type
);
cl_assert
(
o1
->
len
==
o2
->
len
);
if
(
o1
->
len
>
0
)
cl_assert
(
memcmp
(
o1
->
data
,
o2
->
data
,
o1
->
len
)
==
0
);
}
static
int
make_odb_dir
(
void
)
static
void
make_odb_dir
(
void
)
{
if
(
p_mkdir
(
odb_dir
,
GIT_OBJECT_DIR_MODE
)
<
0
)
{
int
err
=
errno
;
fprintf
(
stderr
,
"can't make directory
\"
%s
\"
"
,
odb_dir
);
if
(
err
==
EEXIST
)
fprintf
(
stderr
,
" (already exists)"
);
fprintf
(
stderr
,
"
\n
"
);
return
-
1
;
}
return
0
;
cl_git_pass
(
p_mkdir
(
odb_dir
,
GIT_OBJECT_DIR_MODE
));
}
...
...
@@ -93,20 +63,20 @@ void test_body(object_data *d, git_rawobj *o)
git_oid
id1
,
id2
;
git_odb_object
*
obj
;
cl_git_pass
(
make_odb_dir
()
);
make_odb_dir
(
);
cl_git_pass
(
git_odb_open
(
&
db
,
odb_dir
));
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
d
->
id
));
cl_git_pass
(
streaming_write
(
&
id2
,
db
,
o
)
);
streaming_write
(
&
id2
,
db
,
o
);
cl_assert
(
git_oid_cmp
(
&
id1
,
&
id2
)
==
0
);
c
l_git_pass
(
check_object_files
(
d
)
);
c
heck_object_files
(
d
);
cl_git_pass
(
git_odb_read
(
&
obj
,
db
,
&
id1
));
c
l_git_pass
(
cmp_objects
(
&
obj
->
raw
,
o
)
);
c
mp_objects
(
&
obj
->
raw
,
o
);
git_odb_object_free
(
obj
);
git_odb_free
(
db
);
cl_git_pass
(
remove_object_files
(
d
)
);
remove_object_files
(
d
);
}
...
...
tests-clar/object/tag/read.c
View file @
270303ca
...
...
@@ -12,7 +12,7 @@ static git_repository *g_repo;
// Helpers
static
int
ensure_tag_pattern_match
(
git_repository
*
repo
,
const
char
*
pattern
,
const
size_t
expected_matches
)
static
void
ensure_tag_pattern_match
(
git_repository
*
repo
,
const
char
*
pattern
,
const
size_t
expected_matches
)
{
git_strarray
tag_list
;
int
error
=
GIT_SUCCESS
;
...
...
@@ -25,7 +25,7 @@ static int ensure_tag_pattern_match(git_repository *repo, const char *pattern, c
exit:
git_strarray_free
(
&
tag_list
);
return
error
;
cl_git_pass
(
error
)
;
}
...
...
@@ -87,13 +87,13 @@ void test_object_tag_read__list(void)
void
test_object_tag_read__list_pattern
(
void
)
{
// list all tag names from the repository matching a specified pattern
cl_git_pass
(
ensure_tag_pattern_match
(
g_repo
,
""
,
3
)
);
cl_git_pass
(
ensure_tag_pattern_match
(
g_repo
,
"*"
,
3
)
);
cl_git_pass
(
ensure_tag_pattern_match
(
g_repo
,
"t*"
,
1
)
);
cl_git_pass
(
ensure_tag_pattern_match
(
g_repo
,
"*b"
,
2
)
);
cl_git_pass
(
ensure_tag_pattern_match
(
g_repo
,
"e"
,
0
)
);
cl_git_pass
(
ensure_tag_pattern_match
(
g_repo
,
"e90810b"
,
1
)
);
cl_git_pass
(
ensure_tag_pattern_match
(
g_repo
,
"e90810[ab]"
,
1
)
);
ensure_tag_pattern_match
(
g_repo
,
""
,
3
);
ensure_tag_pattern_match
(
g_repo
,
"*"
,
3
);
ensure_tag_pattern_match
(
g_repo
,
"t*"
,
1
);
ensure_tag_pattern_match
(
g_repo
,
"*b"
,
2
);
ensure_tag_pattern_match
(
g_repo
,
"e"
,
0
);
ensure_tag_pattern_match
(
g_repo
,
"e90810b"
,
1
);
ensure_tag_pattern_match
(
g_repo
,
"e90810[ab]"
,
1
);
}
void
test_object_tag_read__parse_without_tagger
(
void
)
...
...
tests-clar/object/tag/write.c
View file @
270303ca
...
...
@@ -42,17 +42,15 @@ static void locate_loose_object(const char *repository_folder, git_object *objec
*
out_folder
=
top_folder
;
}
static
int
loose_object_mode
(
const
char
*
repository_folder
,
git_object
*
object
)
static
void
loose_object_mode
(
const
char
*
repository_folder
,
git_object
*
object
)
{
char
*
object_path
;
struct
stat
st
;
locate_loose_object
(
repository_folder
,
object
,
&
object_path
,
NULL
);
if
(
p_stat
(
object_path
,
&
st
)
<
0
)
return
0
;
cl_git_pass
(
p_stat
(
object_path
,
&
st
));
free
(
object_path
);
return
st
.
st_mode
;
cl_assert
((
st
.
st_mode
&
0777
)
==
GIT_OBJECT_FILE_MODE
);
}
#endif
...
...
@@ -117,7 +115,7 @@ void test_object_tag_write__basic(void)
cl_git_pass
(
git_reference_delete
(
ref_tag
));
#ifndef GIT_WIN32
// TODO: Get this to work on Linux
//
cl_assert((loose_object_mode("testrepo", (git_object *)tag) & 0777) == GIT_OBJECT_FILE_MODE
);
//
loose_object_mode("testrepo/", (git_object *)tag
);
#endif
git_tag_free
(
tag
);
...
...
tests-clar/refs/reflog.c
View file @
270303ca
...
...
@@ -13,24 +13,13 @@ static git_repository *g_repo;
// helpers
static
int
assert_signature
(
git_signature
*
expected
,
git_signature
*
actual
)
static
void
assert_signature
(
git_signature
*
expected
,
git_signature
*
actual
)
{
if
(
actual
==
NULL
)
return
GIT_ERROR
;
if
(
strcmp
(
expected
->
name
,
actual
->
name
)
!=
0
)
return
GIT_ERROR
;
if
(
strcmp
(
expected
->
email
,
actual
->
email
)
!=
0
)
return
GIT_ERROR
;
if
(
expected
->
when
.
offset
!=
actual
->
when
.
offset
)
return
GIT_ERROR
;
if
(
expected
->
when
.
time
!=
actual
->
when
.
time
)
return
GIT_ERROR
;
return
GIT_SUCCESS
;
cl_assert
(
actual
);
cl_assert
(
0
==
strcmp
(
expected
->
name
,
actual
->
name
));
cl_assert
(
0
==
strcmp
(
expected
->
email
,
actual
->
email
));
cl_assert
(
expected
->
when
.
offset
==
actual
->
when
.
offset
);
cl_assert
(
expected
->
when
.
time
==
actual
->
when
.
time
);
}
...
...
@@ -82,7 +71,7 @@ void test_refs_reflog__write_then_read(void)
cl_assert
(
reflog
->
entries
.
length
==
2
);
entry
=
(
git_reflog_entry
*
)
git_vector_get
(
&
reflog
->
entries
,
0
);
cl_git_pass
(
assert_signature
(
committer
,
entry
->
committer
)
);
assert_signature
(
committer
,
entry
->
committer
);
git_oid_tostr
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_old
);
cl_assert
(
strcmp
(
"0000000000000000000000000000000000000000"
,
oid_str
)
==
0
);
git_oid_tostr
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_cur
);
...
...
@@ -90,7 +79,7 @@ void test_refs_reflog__write_then_read(void)
cl_assert
(
entry
->
msg
==
NULL
);
entry
=
(
git_reflog_entry
*
)
git_vector_get
(
&
reflog
->
entries
,
1
);
cl_git_pass
(
assert_signature
(
committer
,
entry
->
committer
)
);
assert_signature
(
committer
,
entry
->
committer
);
git_oid_tostr
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_old
);
cl_assert
(
strcmp
(
current_master_tip
,
oid_str
)
==
0
);
git_oid_tostr
(
oid_str
,
GIT_OID_HEXSZ
+
1
,
&
entry
->
oid_cur
);
...
...
tests-clar/repo/discover.c
View file @
270303ca
...
...
@@ -23,61 +23,45 @@
#define ALTERNATE_MALFORMED_FOLDER3 DISCOVER_FOLDER "/alternate_malformed_repo3"
#define ALTERNATE_NOT_FOUND_FOLDER DISCOVER_FOLDER "/alternate_not_found_repo"
static
int
ensure_repository_discover
(
const
char
*
start_path
,
const
char
*
ceiling_dirs
,
const
char
*
expected_path
)
static
void
ensure_repository_discover
(
const
char
*
start_path
,
const
char
*
ceiling_dirs
,
const
char
*
expected_path
)
{
int
error
;
char
found_path
[
GIT_PATH_MAX
];
error
=
git_repository_discover
(
found_path
,
sizeof
(
found_path
),
start_path
,
0
,
ceiling_dirs
);
cl_git_pass
(
git_repository_discover
(
found_path
,
sizeof
(
found_path
),
start_path
,
0
,
ceiling_dirs
));
//across_fs is always 0 as we can't automate the filesystem change tests
if
(
error
<
GIT_SUCCESS
)
return
error
;
return
strcmp
(
found_path
,
expected_path
)
?
GIT_ERROR
:
GIT_SUCCESS
;
cl_assert
(
0
==
strcmp
(
found_path
,
expected_path
));
}
static
int
write_file
(
const
char
*
path
,
const
char
*
content
)
static
void
write_file
(
const
char
*
path
,
const
char
*
content
)
{
int
error
;
git_file
file
;
int
error
;
if
(
git_path_exists
(
path
)
==
GIT_SUCCESS
)
{
error
=
p_unlink
(
path
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
cl_git_pass
(
p_unlink
(
path
));
}
file
=
git_futils_creat_withpath
(
path
,
0777
,
0666
);
if
(
file
<
GIT_SUCCESS
)
return
file
;
cl_assert
(
file
>=
0
);
error
=
p_write
(
file
,
content
,
strlen
(
content
)
*
sizeof
(
char
));
p_close
(
file
);
return
error
;
cl_git_pass
(
error
);
}
//no check is performed on ceiling_dirs length, so be sure it's long enough
static
int
append_ceiling_dir
(
git_buf
*
ceiling_dirs
,
const
char
*
path
)
static
void
append_ceiling_dir
(
git_buf
*
ceiling_dirs
,
const
char
*
path
)
{
git_buf
pretty_path
=
GIT_BUF_INIT
;
int
error
;
char
ceiling_separator
[
2
]
=
{
GIT_PATH_LIST_SEPARATOR
,
'\0'
};
error
=
git_path_prettify_dir
(
&
pretty_path
,
path
,
NULL
);
if
(
error
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to append ceiling directory."
);
cl_git_pass
(
git_path_prettify_dir
(
&
pretty_path
,
path
,
NULL
));
if
(
ceiling_dirs
->
size
>
0
)
git_buf_puts
(
ceiling_dirs
,
ceiling_separator
);
git_buf_puts
(
ceiling_dirs
,
pretty_path
.
ptr
);
git_buf_free
(
&
pretty_path
);
return
git_buf_lasterror
(
ceiling_dirs
);
cl_git_pass
(
git_buf_lasterror
(
ceiling_dirs
));
}
void
test_repo_discover__0
(
void
)
...
...
@@ -92,7 +76,7 @@ void test_repo_discover__0(void)
const
mode_t
mode
=
0777
;
git_futils_mkdir_r
(
DISCOVER_FOLDER
,
NULL
,
mode
);
cl_git_pass
(
append_ceiling_dir
(
&
ceiling_dirs_buf
,
TEMP_REPO_FOLDER
)
);
append_ceiling_dir
(
&
ceiling_dirs_buf
,
TEMP_REPO_FOLDER
);
ceiling_dirs
=
git_buf_cstr
(
&
ceiling_dirs_buf
);
cl_assert
(
git_repository_discover
(
repository_path
,
sizeof
(
repository_path
),
DISCOVER_FOLDER
,
0
,
ceiling_dirs
)
==
GIT_ENOTAREPO
);
...
...
@@ -106,33 +90,33 @@ void test_repo_discover__0(void)
cl_git_pass
(
git_repository_discover
(
sub_repository_path
,
sizeof
(
sub_repository_path
),
SUB_REPOSITORY_FOLDER
,
0
,
ceiling_dirs
));
cl_git_pass
(
git_futils_mkdir_r
(
SUB_REPOSITORY_FOLDER_SUB_SUB_SUB
,
NULL
,
mode
));
cl_git_pass
(
ensure_repository_discover
(
SUB_REPOSITORY_FOLDER_SUB
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
SUB_REPOSITORY_FOLDER_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
SUB_REPOSITORY_FOLDER_SUB_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
)
);
ensure_repository_discover
(
SUB_REPOSITORY_FOLDER_SUB
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
SUB_REPOSITORY_FOLDER_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
SUB_REPOSITORY_FOLDER_SUB_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
);
cl_git_pass
(
git_futils_mkdir_r
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
,
NULL
,
mode
));
cl_git_pass
(
write_file
(
REPOSITORY_ALTERNATE_FOLDER
"/"
DOT_GIT
,
"gitdir: ../"
SUB_REPOSITORY_FOLDER_NAME
"/"
DOT_GIT
)
);
cl_git_pass
(
write_file
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB
"/"
DOT_GIT
,
"gitdir: ../../../"
SUB_REPOSITORY_FOLDER_NAME
"/"
DOT_GIT
)
);
cl_git_pass
(
write_file
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
"/"
DOT_GIT
,
"gitdir: ../../../../"
)
);
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
,
ceiling_dirs
,
repository_path
)
);
write_file
(
REPOSITORY_ALTERNATE_FOLDER
"/"
DOT_GIT
,
"gitdir: ../"
SUB_REPOSITORY_FOLDER_NAME
"/"
DOT_GIT
);
write_file
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB
"/"
DOT_GIT
,
"gitdir: ../../../"
SUB_REPOSITORY_FOLDER_NAME
"/"
DOT_GIT
);
write_file
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
"/"
DOT_GIT
,
"gitdir: ../../../../"
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
,
ceiling_dirs
,
repository_path
);
cl_git_pass
(
git_futils_mkdir_r
(
ALTERNATE_MALFORMED_FOLDER1
,
NULL
,
mode
));
cl_git_pass
(
write_file
(
ALTERNATE_MALFORMED_FOLDER1
"/"
DOT_GIT
,
"Anything but not gitdir:"
)
);
write_file
(
ALTERNATE_MALFORMED_FOLDER1
"/"
DOT_GIT
,
"Anything but not gitdir:"
);
cl_git_pass
(
git_futils_mkdir_r
(
ALTERNATE_MALFORMED_FOLDER2
,
NULL
,
mode
));
cl_git_pass
(
write_file
(
ALTERNATE_MALFORMED_FOLDER2
"/"
DOT_GIT
,
"gitdir:"
)
);
write_file
(
ALTERNATE_MALFORMED_FOLDER2
"/"
DOT_GIT
,
"gitdir:"
);
cl_git_pass
(
git_futils_mkdir_r
(
ALTERNATE_MALFORMED_FOLDER3
,
NULL
,
mode
));
cl_git_pass
(
write_file
(
ALTERNATE_MALFORMED_FOLDER3
"/"
DOT_GIT
,
"gitdir:
\n\n\n
"
)
);
write_file
(
ALTERNATE_MALFORMED_FOLDER3
"/"
DOT_GIT
,
"gitdir:
\n\n\n
"
);
cl_git_pass
(
git_futils_mkdir_r
(
ALTERNATE_NOT_FOUND_FOLDER
,
NULL
,
mode
));
cl_git_pass
(
write_file
(
ALTERNATE_NOT_FOUND_FOLDER
"/"
DOT_GIT
,
"gitdir: a_repository_that_surely_does_not_exist"
)
);
write_file
(
ALTERNATE_NOT_FOUND_FOLDER
"/"
DOT_GIT
,
"gitdir: a_repository_that_surely_does_not_exist"
);
cl_git_fail
(
git_repository_discover
(
found_path
,
sizeof
(
found_path
),
ALTERNATE_MALFORMED_FOLDER1
,
0
,
ceiling_dirs
));
cl_git_fail
(
git_repository_discover
(
found_path
,
sizeof
(
found_path
),
ALTERNATE_MALFORMED_FOLDER2
,
0
,
ceiling_dirs
));
cl_git_fail
(
git_repository_discover
(
found_path
,
sizeof
(
found_path
),
ALTERNATE_MALFORMED_FOLDER3
,
0
,
ceiling_dirs
));
cl_git_fail
(
git_repository_discover
(
found_path
,
sizeof
(
found_path
),
ALTERNATE_NOT_FOUND_FOLDER
,
0
,
ceiling_dirs
));
cl_git_pass
(
append_ceiling_dir
(
&
ceiling_dirs_buf
,
SUB_REPOSITORY_FOLDER
)
);
append_ceiling_dir
(
&
ceiling_dirs_buf
,
SUB_REPOSITORY_FOLDER
);
ceiling_dirs
=
git_buf_cstr
(
&
ceiling_dirs_buf
);
//this must pass as ceiling_directories cannot predent the current
...
...
@@ -143,10 +127,10 @@ void test_repo_discover__0(void)
cl_git_fail
(
git_repository_discover
(
found_path
,
sizeof
(
found_path
),
SUB_REPOSITORY_FOLDER_SUB_SUB_SUB
,
0
,
ceiling_dirs
));
//.gitfile redirection should not be affected by ceiling directories
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
)
);
cl_git_pass
(
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
,
ceiling_dirs
,
repository_path
)
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB
,
ceiling_dirs
,
sub_repository_path
);
ensure_repository_discover
(
REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB
,
ceiling_dirs
,
repository_path
);
cl_git_pass
(
git_futils_rmdir_r
(
TEMP_REPO_FOLDER
,
1
));
git_repository_free
(
repo
);
...
...
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