static int deepen;
static char *option_template, *option_depth, *option_since;
static char *option_origin = NULL;
-static char *remote_name = "origin";
+static char *remote_name = NULL;
static char *option_branch = NULL;
static struct string_list option_not = STRING_LIST_INIT_NODUP;
static const char *real_git_dir;
static int git_clone_config(const char *k, const char *v, void *cb)
{
+ if (!strcmp(k, "clone.defaultremotename")) {
+ free(remote_name);
+ remote_name = xstrdup(v);
+ }
return git_default_config(k, v, cb);
}
option_no_checkout = 1;
}
- if (option_origin)
- remote_name = option_origin;
-
- if (!valid_remote_name(remote_name))
- die(_("'%s' is not a valid remote name"), remote_name);
-
repo_name = argv[0];
path = get_repo_path(repo_name, &is_bundle);
*/
git_config(git_clone_config, NULL);
+ /*
+ * apply the remote name provided by --origin only after this second
+ * call to git_config, to ensure it overrides all config-based values.
+ */
+ if (option_origin != NULL)
+ remote_name = xstrdup(option_origin);
+
+ if (remote_name == NULL)
+ remote_name = xstrdup("origin");
+
+ if (!valid_remote_name(remote_name))
+ die(_("'%s' is not a valid remote name"), remote_name);
+
if (option_bare) {
if (option_mirror)
src_ref_prefix = "refs/";
junk_mode = JUNK_LEAVE_REPO;
err = checkout(submodule_progress);
+ free(remote_name);
strbuf_release(&reflog_msg);
strbuf_release(&branch_top);
strbuf_release(&key);
'
+test_expect_success 'rejects invalid -o/--origin' '
+
+ test_must_fail git clone -o "bad...name" parent clone-bad-name 2>err &&
+ test_i18ngrep "'\''bad...name'\'' is not a valid remote name" err
+
+'
+
test_expect_success 'disallows --bare with --origin' '
test_must_fail git clone -o foo --bare parent clone-bare-o 2>err &&
'
+test_expect_success 'prefers config "clone.defaultRemoteName" over default' '
+
+ test_config_global clone.defaultRemoteName from_config &&
+ git clone parent clone-config-origin &&
+ git -C clone-config-origin rev-parse --verify refs/remotes/from_config/master
+
+'
+
+test_expect_success 'prefers --origin over -c config' '
+
+ git clone -c clone.defaultRemoteName=inline --origin from_option parent clone-o-and-inline-config &&
+ git -C clone-o-and-inline-config rev-parse --verify refs/remotes/from_option/master
+
+'
+
test_expect_success 'redirected clone does not show progress' '
git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&