summaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-02-26 23:11:53 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-02-26 23:11:53 -0500
commitcf7def1477822d6555bd50e72d22ce9581e41a30 (patch)
tree512ce81421d2c323a41a5cfb8ec18466a9c952ff /src/cli
parentb862be9b09176b3e292694678abf6d5bb29ee14e (diff)
downloadlibgit2-cf7def1477822d6555bd50e72d22ce9581e41a30.tar.gz
cli: support bare clones
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/cmd_clone.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/cli/cmd_clone.c b/src/cli/cmd_clone.c
index 196c95bda..34eedfe87 100644
--- a/src/cli/cmd_clone.c
+++ b/src/cli/cmd_clone.c
@@ -19,6 +19,8 @@
static int show_help;
static int quiet;
+static git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
+
static char *remote_path, *local_path;
static bool local_path_exists;
static cli_progress progress = CLI_PROGRESS_INIT;
@@ -30,6 +32,8 @@ static const cli_opt_spec opts[] = {
{ CLI_OPT_TYPE_BOOL, "quiet", 'q', &quiet, 0,
CLI_OPT_USAGE_DEFAULT, NULL, "do not display progress output" },
+ { CLI_OPT_TYPE_BOOL, "bare", 0, &clone_opts.bare, 1,
+ CLI_OPT_USAGE_DEFAULT, NULL, "don't create a working directory" },
{ CLI_OPT_TYPE_LITERAL },
{ CLI_OPT_TYPE_ARG, "repository", 0, &remote_path, 0,
@@ -54,16 +58,24 @@ static void print_help(void)
static char *compute_local_path(const char *orig_path)
{
+ git_str local_path = GIT_STR_INIT;
const char *slash;
- char *local_path;
if ((slash = strrchr(orig_path, '/')) == NULL &&
(slash = strrchr(orig_path, '\\')) == NULL)
- local_path = git__strdup(orig_path);
+ git_str_puts(&local_path, orig_path);
else
- local_path = git__strdup(slash + 1);
+ git_str_puts(&local_path, slash + 1);
+
+ if (clone_opts.bare) {
+ if (!git_str_endswith(&local_path, ".git"))
+ git_str_puts(&local_path, ".git");
+ } else {
+ if (git_str_endswith(&local_path, ".git"))
+ git_str_shorten(&local_path, 4);
+ }
- return local_path;
+ return git_str_detach(&local_path);
}
static bool validate_local_path(const char *path)
@@ -101,7 +113,6 @@ static void interrupt_cleanup(void)
int cmd_clone(int argc, char **argv)
{
- git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_repository *repo = NULL;
cli_opt invalid_opt;
char *computed_path = NULL;