X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=builtin-clone.c;h=49d2eb9c2ba574f2c1484717f0755208e7ed8147;hb=fd631d5828ec6b89e86e0568e5e798787fed9bbd;hp=8612d59dd22202bc8af3436bffcade2e2dba5fcf;hpb=57b0fc4516249e1aa86169718d148fbf2940dc0c;p=git.git diff --git a/builtin-clone.c b/builtin-clone.c index 8612d59dd..49d2eb9c2 100644 --- a/builtin-clone.c +++ b/builtin-clone.c @@ -58,7 +58,7 @@ static struct option builtin_clone_options[] = { OPT_STRING(0, "reference", &option_reference, "repo", "reference repository"), OPT_STRING('o', "origin", &option_origin, "branch", - "use instead or 'origin' to track upstream"), + "use instead of 'origin' to track upstream"), OPT_STRING('u', "upload-pack", &option_upload_pack, "path", "path to git-upload-pack on the remote"), OPT_STRING(0, "depth", &option_depth, "depth", @@ -77,7 +77,7 @@ static char *get_repo_path(const char *repo, int *is_bundle) for (i = 0; i < ARRAY_SIZE(suffix); i++) { const char *path; path = mkpath("%s%s", repo, suffix[i]); - if (!stat(path, &st) && S_ISDIR(st.st_mode)) { + if (is_directory(path)) { *is_bundle = 0; return xstrdup(make_nonrelative_path(path)); } @@ -140,11 +140,13 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) return xstrndup(start, end - start); } -static int is_directory(const char *path) +static void strip_trailing_slashes(char *dir) { - struct stat buf; + char *end = dir + strlen(dir); - return !stat(path, &buf) && S_ISDIR(buf.st_mode); + while (dir < end - 1 && is_dir_sep(end[-1])) + end--; + *end = '\0'; } static void setup_reference(const char *repo) @@ -330,7 +332,8 @@ static struct ref *write_remote_refs(const struct ref *refs, struct ref *r; get_fetch_map(refs, refspec, &tail, 0); - get_fetch_map(refs, tag_refspec, &tail, 0); + if (!option_mirror) + get_fetch_map(refs, tag_refspec, &tail, 0); for (r = local_refs; r; r = r->next) add_extra_ref(r->peer_ref->name, r->old_sha1, 0); @@ -386,7 +389,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) path = get_repo_path(repo_name, &is_bundle); if (path) - repo = path; + repo = xstrdup(make_nonrelative_path(repo_name)); else if (!strchr(repo_name, ':')) repo = xstrdup(make_absolute_path(repo_name)); else @@ -396,6 +399,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) dir = xstrdup(argv[1]); else dir = guess_dir_name(repo_name, is_bundle, option_bare); + strip_trailing_slashes(dir); if (!stat(dir, &buf)) die("destination directory '%s' already exists.", dir); @@ -421,10 +425,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (!option_bare) { junk_work_tree = work_tree; if (safe_create_leading_directories_const(work_tree) < 0) - die("could not create leading directories of '%s'", - work_tree); + die("could not create leading directories of '%s': %s", + work_tree, strerror(errno)); if (mkdir(work_tree, 0755)) - die("could not create work tree dir '%s'.", work_tree); + die("could not create work tree dir '%s': %s.", + work_tree, strerror(errno)); set_git_work_tree(work_tree); } junk_git_dir = git_dir;