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
04cddffe
Commit
04cddffe
authored
2 years ago
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli: add --depth option to clone
parent
43db9288
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
src/cli/cmd_clone.c
+22
-6
No files found.
src/cli/cmd_clone.c
View file @
04cddffe
...
...
@@ -18,7 +18,7 @@
#define COMMAND_NAME "clone"
static
char
*
branch
,
*
remote_path
,
*
local_path
;
static
char
*
branch
,
*
remote_path
,
*
local_path
,
*
depth
;
static
int
show_help
,
quiet
,
checkout
=
1
,
bare
;
static
bool
local_path_exists
;
static
cli_progress
progress
=
CLI_PROGRESS_INIT
;
...
...
@@ -36,6 +36,8 @@ static const cli_opt_spec opts[] = {
CLI_OPT_USAGE_DEFAULT
,
NULL
,
"don't create a working directory"
},
{
CLI_OPT_TYPE_VALUE
,
"branch"
,
'b'
,
&
branch
,
0
,
CLI_OPT_USAGE_DEFAULT
,
"name"
,
"branch to check out"
},
{
CLI_OPT_TYPE_VALUE
,
"depth"
,
0
,
&
depth
,
0
,
CLI_OPT_USAGE_DEFAULT
,
"depth"
,
"commit depth to check out "
},
{
CLI_OPT_TYPE_LITERAL
},
{
CLI_OPT_TYPE_ARG
,
"repository"
,
0
,
&
remote_path
,
0
,
CLI_OPT_USAGE_REQUIRED
,
"repository"
,
"repository path"
},
...
...
@@ -71,6 +73,22 @@ static char *compute_local_path(const char *orig_path)
return
local_path
;
}
static
int
compute_depth
(
const
char
*
depth
)
{
int64_t
i
;
const
char
*
endptr
;
if
(
!
depth
)
return
0
;
if
(
git__strntol64
(
&
i
,
depth
,
strlen
(
depth
),
&
endptr
,
10
)
<
0
||
i
<
0
||
i
>
INT_MAX
||
*
endptr
)
{
fprintf
(
stderr
,
"fatal: depth '%s' is not valid.
\n
"
,
depth
);
exit
(
128
);
}
return
(
int
)
i
;
}
static
bool
validate_local_path
(
const
char
*
path
)
{
if
(
!
git_fs_path_exists
(
path
))
...
...
@@ -127,11 +145,9 @@ int cmd_clone(int argc, char **argv)
goto
done
;
}
if
(
bare
)
clone_opts
.
bare
=
1
;
if
(
branch
)
clone_opts
.
checkout_branch
=
branch
;
clone_opts
.
bare
=
!!
bare
;
clone_opts
.
checkout_branch
=
branch
;
clone_opts
.
fetch_opts
.
depth
=
compute_depth
(
depth
);
if
(
!
checkout
)
clone_opts
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_NONE
;
...
...
This diff is collapsed.
Click to expand it.
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