diff options
Diffstat (limited to 'builtin/clone.c')
| -rw-r--r-- | builtin/clone.c | 55 | 
1 files changed, 36 insertions, 19 deletions
diff --git a/builtin/clone.c b/builtin/clone.c index 552f3409e3..43e772ccdb 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -62,23 +62,22 @@ static struct option builtin_clone_options[] = {  	OPT__VERBOSITY(&option_verbosity),  	OPT_BOOL(0, "progress", &option_progress,  		 N_("force progress reporting")), -	OPT_BOOLEAN('n', "no-checkout", &option_no_checkout, -		    N_("don't create a checkout")), -	OPT_BOOLEAN(0, "bare", &option_bare, N_("create a bare repository")), -	{ OPTION_BOOLEAN, 0, "naked", &option_bare, NULL, -		N_("create a bare repository"), -		PARSE_OPT_NOARG | PARSE_OPT_HIDDEN }, -	OPT_BOOLEAN(0, "mirror", &option_mirror, -		    N_("create a mirror repository (implies bare)")), +	OPT_BOOL('n', "no-checkout", &option_no_checkout, +		 N_("don't create a checkout")), +	OPT_BOOL(0, "bare", &option_bare, N_("create a bare repository")), +	OPT_HIDDEN_BOOL(0, "naked", &option_bare, +			N_("create a bare repository")), +	OPT_BOOL(0, "mirror", &option_mirror, +		 N_("create a mirror repository (implies bare)")),  	OPT_BOOL('l', "local", &option_local,  		N_("to clone from a local repository")), -	OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks, +	OPT_BOOL(0, "no-hardlinks", &option_no_hardlinks,  		    N_("don't use local hardlinks, always copy")), -	OPT_BOOLEAN('s', "shared", &option_shared, +	OPT_BOOL('s', "shared", &option_shared,  		    N_("setup as shared repository")), -	OPT_BOOLEAN(0, "recursive", &option_recursive, +	OPT_BOOL(0, "recursive", &option_recursive,  		    N_("initialize submodules in the clone")), -	OPT_BOOLEAN(0, "recurse-submodules", &option_recursive, +	OPT_BOOL(0, "recurse-submodules", &option_recursive,  		    N_("initialize submodules in the clone")),  	OPT_STRING(0, "template", &option_template, N_("template-directory"),  		   N_("directory from which templates will be used")), @@ -253,6 +252,12 @@ static int add_one_reference(struct string_list_item *item, void *cb_data)  		die(_("reference repository '%s' is not a local repository."),  		    item->string); +	if (!access(mkpath("%s/shallow", ref_git), F_OK)) +		die(_("reference repository '%s' is shallow"), item->string); + +	if (!access(mkpath("%s/info/grafts", ref_git), F_OK)) +		die(_("reference repository '%s' is grafted"), item->string); +  	strbuf_addf(&alternate, "%s/objects", ref_git);  	add_to_alternates_file(alternate.buf);  	strbuf_release(&alternate); @@ -509,9 +514,9 @@ static void write_followtags(const struct ref *refs, const char *msg)  {  	const struct ref *ref;  	for (ref = refs; ref; ref = ref->next) { -		if (prefixcmp(ref->name, "refs/tags/")) +		if (!starts_with(ref->name, "refs/tags/"))  			continue; -		if (!suffixcmp(ref->name, "^{}")) +		if (ends_with(ref->name, "^{}"))  			continue;  		if (!has_sha1_file(ref->old_sha1))  			continue; @@ -557,7 +562,7 @@ static void update_remote_refs(const struct ref *refs,  							      0, &rm, transport))  			die(_("remote did not send all necessary objects"));  		if (transport->progress) -			fprintf(stderr, _("done\n")); +			fprintf(stderr, _("done.\n"));  	}  	if (refs) { @@ -579,7 +584,7 @@ static void update_remote_refs(const struct ref *refs,  static void update_head(const struct ref *our, const struct ref *remote,  			const char *msg)  { -	if (our && !prefixcmp(our->name, "refs/heads/")) { +	if (our && starts_with(our->name, "refs/heads/")) {  		/* Local default branch link */  		create_symref("HEAD", our->name, NULL);  		if (!option_bare) { @@ -626,7 +631,7 @@ static int checkout(void)  		if (advice_detached_head)  			detach_advice(sha1_to_hex(sha1));  	} else { -		if (prefixcmp(head, "refs/heads/")) +		if (!starts_with(head, "refs/heads/"))  			die(_("HEAD not found below refs/heads!"));  	}  	free(head); @@ -792,11 +797,22 @@ int cmd_clone(int argc, const char **argv, const char *prefix)  	else  		repo = repo_name;  	is_local = option_local != 0 && path && !is_bundle; -	if (is_local && option_depth) -		warning(_("--depth is ignored in local clones; use file:// instead.")); +	if (is_local) { +		if (option_depth) +			warning(_("--depth is ignored in local clones; use file:// instead.")); +		if (!access(mkpath("%s/shallow", path), F_OK)) { +			if (option_local > 0) +				warning(_("source repository is shallow, ignoring --local")); +			is_local = 0; +		} +	}  	if (option_local > 0 && !is_local)  		warning(_("--local is ignored")); +	/* no need to be strict, transport_set_option() will validate it again */ +	if (option_depth && atoi(option_depth) < 1) +		die(_("depth %s is not a positive number"), option_depth); +  	if (argc == 2)  		dir = xstrdup(argv[1]);  	else @@ -884,6 +900,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)  	remote = remote_get(option_origin);  	transport = transport_get(remote, remote->url[0]); +	transport->cloning = 1;  	if (!transport->get_refs_list || (!is_local && !transport->fetch))  		die(_("Don't know how to clone %s"), transport->url);  | 
