From patchwork Tue Jun 23 22:33:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Passaro via GitGitGadget X-Patchwork-Id: 11622009 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 639F760D for ; Tue, 23 Jun 2020 22:48:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4ABB72078E for ; Tue, 23 Jun 2020 22:48:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eNZBpC25" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388606AbgFWWr4 (ORCPT ); Tue, 23 Jun 2020 18:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388294AbgFWWr1 (ORCPT ); Tue, 23 Jun 2020 18:47:27 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D94DBC0612AD for ; Tue, 23 Jun 2020 15:33:40 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id f18so383705wml.3 for ; Tue, 23 Jun 2020 15:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Q0pF5yj7wjNRE2JCBd7v1az84w+LZ8K2+6NNlyKt2yU=; b=eNZBpC25EtILpKiY+Y7hfedPXXc7FStEO26EiQiHbpCex76YPAsb14ZXy2aOjUuV6j zPgpSQlcg4jifbu4bLfuwpKYRdhy2KNMvXy/SOsA9Vlc3DI4AJIqZHbSWWXeG0Qv00bT dOZsHWBlL9gqF5Du43c+zqtkvbkGoz18tCn8+1KtOoNvltzj/PnYa/mBXvwezw+vlNCK 4axGfNurxJFNj/otDYiTxshWB5YAkShV7sQ8TfiwVJlD3kiXOHMNQcyjS9a6TF/pL6dc QOwIEnbtzpB8NQDwavdImocN8F+VrXmqi+OWj4jgHdrMtef15LFdMXlQ43zTTgJ8I2qq AFOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Q0pF5yj7wjNRE2JCBd7v1az84w+LZ8K2+6NNlyKt2yU=; b=ZpE6+M78i3S08gos/wV9fwgy0uW2GtoBhKa53b9HjHKmOzvW939FbgHxFDj9C4k7a0 uOdeiB1xSWKqq1lDo7Zfpow02cOx2LvVhmwTBHoIRW1wKA88pqTI+EqATiwLu/ZqVx1m MadFZz8ZZSuIfuTdCf+ihKGBmM1FbIeB2MtVYAWEZDH1alNdLxapjn7PGENmLi1sM86S THHkH+e4Ksmb7h3Qk/WXGYSs1UNtP7oJGlPE38cIp+nA7Dz7sTuUPtRgX24/aNILFex/ UyfT0s5pkj5gUuBrLNQcuoJkIk19oB/Rlk3+S7B482Wk7SvZQMopmrrhUXPL6gf04HPp C/jw== X-Gm-Message-State: AOAM532AMTeylu4M9S1J/w/ML7XE6+LFl/KF7tYBJBg5Wu0Wy/od/Y/m xzjAGMdPeiqa4SeZHpKWpN7BapAt X-Google-Smtp-Source: ABdhPJzQzCkwhkAnIaUbnfNtiH0/M/+lHMjTTkQQpPUWGZhGGJefqEvlIdojQMZXObZr8EBcb1CPuw== X-Received: by 2002:a7b:c5d5:: with SMTP id n21mr26441258wmk.106.1592951618389; Tue, 23 Jun 2020 15:33:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z1sm10657582wrh.14.2020.06.23.15.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 15:33:37 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Tue, 23 Jun 2020 22:33:28 +0000 Subject: [PATCH v3 6/8] clone: use configured default branch name when appropriate Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: don@goodman-wilson.com, stolee@gmail.com, peff@peff.net, sandals@crustytoothpaste.net, Matt Rogers , Eric Sunshine , Taylor Blau , Phillip Wood , Alban Gruin , Johannes Sixt , Denton Liu , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Johannes Schindelin , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin When cloning a repository without any branches, Git chooses a default branch name for the as-yet unborn branch. As part of the implicit initialization of the local repository, Git just learned to respect `init.defaultBranch` to choose a different initial branch name. We now really want that branch name to be used as a fall-back. Signed-off-by: Johannes Schindelin --- Documentation/config/init.txt | 4 ++-- builtin/clone.c | 10 +++++++--- t/t5606-clone-options.sh | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Documentation/config/init.txt b/Documentation/config/init.txt index 6ae4a38416..dc77f8c844 100644 --- a/Documentation/config/init.txt +++ b/Documentation/config/init.txt @@ -3,5 +3,5 @@ init.templateDir:: (See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].) init.defaultBranch:: - Allows overriding the default branch name when initializing - a new repository. + Allows overriding the default branch name e.g. when initializing + a new repository or when cloning an empty repository. diff --git a/builtin/clone.c b/builtin/clone.c index b751bdf13e..9a3f91b268 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1267,9 +1267,13 @@ int cmd_clone(int argc, const char **argv, const char *prefix) remote_head_points_at = NULL; remote_head = NULL; option_no_checkout = 1; - if (!option_bare) - install_branch_config(0, "master", option_origin, - "refs/heads/master"); + if (!option_bare) { + const char *branch = git_default_branch_name(); + char *ref = xstrfmt("refs/heads/%s", branch); + + install_branch_config(0, branch, option_origin, ref); + free(ref); + } } write_refspec_config(src_ref_prefix, our_head_points_at, diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index 9e24ec88e6..286bfd93ac 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -35,4 +35,19 @@ test_expect_success 'redirected clone -v does show progress' ' ' +test_expect_success 'chooses correct default initial branch name' ' + git init --bare empty && + git -c init.defaultBranch=up clone empty whats-up && + test refs/heads/up = $(git -C whats-up symbolic-ref HEAD) && + test refs/heads/up = $(git -C whats-up config branch.up.merge) +' + +test_expect_success 'guesses initial branch name correctly' ' + git init --initial-branch=guess initial-branch && + test_commit -C initial-branch no-spoilers && + git -C initial-branch branch abc guess && + git clone initial-branch is-it && + test refs/heads/guess = $(git -C is-it symbolic-ref HEAD) +' + test_done