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
c652f3d1
Commit
c652f3d1
authored
Jul 19, 2022
by
yuangli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable cloning of shallow repo
parent
3e64f150
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
src/clone.c
+1
-0
tests/clone/shallow.c
+16
-9
No files found.
src/clone.c
View file @
c652f3d1
...
@@ -409,6 +409,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
...
@@ -409,6 +409,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch
memcpy
(
&
fetch_opts
,
opts
,
sizeof
(
git_fetch_options
));
memcpy
(
&
fetch_opts
,
opts
,
sizeof
(
git_fetch_options
));
fetch_opts
.
update_fetchhead
=
0
;
fetch_opts
.
update_fetchhead
=
0
;
if
(
fetch_opts
.
depth
==
-
1
)
fetch_opts
.
download_tags
=
GIT_REMOTE_DOWNLOAD_TAGS_ALL
;
fetch_opts
.
download_tags
=
GIT_REMOTE_DOWNLOAD_TAGS_ALL
;
git_buf_printf
(
&
reflog_message
,
"clone: from %s"
,
git_remote_url
(
remote
));
git_buf_printf
(
&
reflog_message
,
"clone: from %s"
,
git_remote_url
(
remote
));
...
...
tests/clone/shallow.c
View file @
c652f3d1
...
@@ -15,6 +15,15 @@ void test_clone_shallow__cleanup(void)
...
@@ -15,6 +15,15 @@ void test_clone_shallow__cleanup(void)
#define CLONE_DEPTH 5
#define CLONE_DEPTH 5
static
int
remote_single_branch
(
git_remote
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
url
,
void
*
payload
)
{
GIT_UNUSED
(
payload
);
cl_git_pass
(
git_remote_create_with_fetchspec
(
out
,
repo
,
name
,
url
,
"+refs/heads/master:refs/remotes/origin/master"
));
return
0
;
}
void
test_clone_shallow__clone_depth
(
void
)
void
test_clone_shallow__clone_depth
(
void
)
{
{
git_buf
path
=
GIT_BUF_INIT
;
git_buf
path
=
GIT_BUF_INIT
;
...
@@ -27,6 +36,7 @@ void test_clone_shallow__clone_depth(void)
...
@@ -27,6 +36,7 @@ void test_clone_shallow__clone_depth(void)
int
error
=
0
;
int
error
=
0
;
clone_opts
.
fetch_opts
.
depth
=
CLONE_DEPTH
;
clone_opts
.
fetch_opts
.
depth
=
CLONE_DEPTH
;
clone_opts
.
remote_cb
=
remote_single_branch
;
git_buf_joinpath
(
&
path
,
clar_sandbox_path
(),
"shallowclone"
);
git_buf_joinpath
(
&
path
,
clar_sandbox_path
(),
"shallowclone"
);
...
@@ -35,21 +45,18 @@ void test_clone_shallow__clone_depth(void)
...
@@ -35,21 +45,18 @@ void test_clone_shallow__clone_depth(void)
cl_assert_equal_b
(
true
,
git_repository_is_shallow
(
repo
));
cl_assert_equal_b
(
true
,
git_repository_is_shallow
(
repo
));
cl_git_pass
(
git_repository_shallow_roots
(
&
roots
,
repo
));
cl_git_pass
(
git_repository_shallow_roots
(
&
roots
,
repo
));
cl_assert_equal_i
(
1
,
roots
.
count
);
cl_assert_equal_i
(
3
,
roots
.
count
);
cl_assert_equal_s
(
"83834a7afdaa1a1260568567f6ad90020389f664"
,
git_oid_tostr_s
(
&
roots
.
ids
[
0
]));
cl_assert_equal_s
(
"c070ad8c08840c8116da865b2d65593a6bb9cd2a"
,
git_oid_tostr_s
(
&
roots
.
ids
[
0
]));
cl_assert_equal_s
(
"0966a434eb1a025db6b71485ab63a3bfbea520b6"
,
git_oid_tostr_s
(
&
roots
.
ids
[
1
]));
cl_assert_equal_s
(
"83834a7afdaa1a1260568567f6ad90020389f664"
,
git_oid_tostr_s
(
&
roots
.
ids
[
2
]));
git_revwalk_new
(
&
walk
,
repo
);
git_revwalk_new
(
&
walk
,
repo
);
git_revwalk_push_head
(
walk
);
git_revwalk_push_head
(
walk
);
while
((
error
=
git_revwalk_next
(
&
oid
,
walk
))
==
GIT_OK
)
{
while
((
error
=
git_revwalk_next
(
&
oid
,
walk
))
==
GIT_OK
)
{
//if (depth + 1 > CLONE_DEPTH)
if
(
depth
+
1
>
CLONE_DEPTH
)
//cl_fail("expected depth mismatch");
cl_fail
(
"expected depth mismatch"
);
char
str
[
GIT_OID_HEXSZ
+
1
];
git_oid_fmt
(
str
,
&
oid
);
printf
(
str
);
printf
(
"
\n
"
);
depth
++
;
}
}
cl_git_pass
(
error
);
cl_git_pass
(
error
);
...
...
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