From patchwork Mon Nov 23 23:20:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11926851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19FD2C2D0E4 for ; Mon, 23 Nov 2020 23:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B12A0206A1 for ; Mon, 23 Nov 2020 23:20:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nqqHwq+D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726085AbgKWXUM (ORCPT ); Mon, 23 Nov 2020 18:20:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgKWXUM (ORCPT ); Mon, 23 Nov 2020 18:20:12 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D99BC061A4D for ; Mon, 23 Nov 2020 15:20:11 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id l1so20454933wrb.9 for ; Mon, 23 Nov 2020 15:20:11 -0800 (PST) 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=hXEJY3v6TTAJzFBcIm7ytbs9WZJxxSVV6Hw7lvdxUkE=; b=nqqHwq+D5PHkPhkoAuZalztkBiJLaKRHMDlg7P+5d/VFbbSW6Tq9EIg42WZik3CyIP MgMb9pjIGYp1pCpR5iVDtM7Uw6bmd3u9vlupJbwLF4WLseTfykeOmQvxHXfVreDCqN2z uHQT9IlE7RoiwmERLusiAH2Y5jsowtLpJj+ThfSs4Q1I20BxrdUTRZrXZPlXCFdCojQk nkdlWYS9w9IO2moqICgtSOhNbUuUJTt/TEinlLkorkrqr0u7Lw+dV7PjnlzIkej/siBZ RUHDrKqZj3+LhwGq0L4DBSNKkUboy2QEUngNfjlcr6JY2Afz713zIOmeR3lUsewPXTtE vEZg== 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=hXEJY3v6TTAJzFBcIm7ytbs9WZJxxSVV6Hw7lvdxUkE=; b=b8bBqtB80CrwyHLGa7lqe4rF4mpng1NskJgh3Ktf1W5PfZfwKSN6dEQMF2mu+zMtyG G/qkFAtrkgWhIUwJWi0p1zIFQzcJUtET5Uugosw6MIclaohc7s3Q5U1quHh+ajARZkc/ C12JAyQYsgjFykMJI7Sx+OEys5FW9rAxHNdU4i63BAo8Ph6YdrHKbOvSfeUGOX7NJuz2 V7qWmKKHpiqmFB5Hg+rCRsiaATK9YnvL/BDyJJhfaK0u0YxYRmz1YuHo1ukCyBq430LC Nnn4HMBs408oUycRE4rRwBPyt8wvJr7KJe7hYYIniM7s5kktEAZoG7d7PxGupAeOfTRy 83DA== X-Gm-Message-State: AOAM532SrFeWY8of4QuDXIxgoTupsaAdMgec+8pE8Q4N1bAliV4ozJkQ fCdUJnH3OIUWdm5idjlOQDiyxwz87vs= X-Google-Smtp-Source: ABdhPJxVYCp3sY2pW5Kp0QmILJ1wIDkHO1WMKXf0oIIncwTWUdNExiuUtQKhrsZp5hnxQkOsxmxD6A== X-Received: by 2002:a5d:488b:: with SMTP id g11mr2185807wrq.210.1606173610122; Mon, 23 Nov 2020 15:20:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w17sm22047294wru.82.2020.11.23.15.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 15:20:09 -0800 (PST) Message-Id: <483e490349165223a80a0bdf7716c5189560c977.1606173607.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 23:20:04 +0000 Subject: [PATCH v2 1/4] init: document `init.defaultBranch` better Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Our documentation does not mention any future plan to change 'master' to other value. It is a good idea to document this, though. Initial-patch-by: Junio C Hamano Signed-off-by: Johannes Schindelin --- Documentation/git-init.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt index 59ecda6c17..2b399cb73d 100644 --- a/Documentation/git-init.txt +++ b/Documentation/git-init.txt @@ -20,8 +20,9 @@ DESCRIPTION This command creates an empty Git repository - basically a `.git` directory with subdirectories for `objects`, `refs/heads`, -`refs/tags`, and template files. An initial `HEAD` file that -references the HEAD of the master branch is also created. +`refs/tags`, and template files. An initial branch without any +commits will be created (see the `--initial-branch` option below +for its name). If the `$GIT_DIR` environment variable is set then it specifies a path to use instead of `./.git` for the base of the repository. @@ -73,8 +74,10 @@ If this is reinitialization, the repository will be moved to the specified path. -b :: --initial-branch=:: -Use the specified name for the initial branch in the newly created repository. -If not specified, fall back to the default name: `master`. +Use the specified name for the initial branch in the newly created +repository. If not specified, fall back to the default name (currently +`master`, but that will be changed in the future; the name can be customized +via the `init.defaultBranch` configuration variable). --shared[=(false|true|umask|group|all|world|everybody|0xxx)]:: From patchwork Mon Nov 23 23:20:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11926857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7D16C63697 for ; Mon, 23 Nov 2020 23:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64E6420719 for ; Mon, 23 Nov 2020 23:20:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g/8ovk9T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726238AbgKWXUP (ORCPT ); Mon, 23 Nov 2020 18:20:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726155AbgKWXUO (ORCPT ); Mon, 23 Nov 2020 18:20:14 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97B0BC061A4D for ; Mon, 23 Nov 2020 15:20:12 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id 1so1091965wme.3 for ; Mon, 23 Nov 2020 15:20:12 -0800 (PST) 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=Sw5FFiK/t6evnu3E904I82pkwQ3g660/lP3rLmMmBPk=; b=g/8ovk9T2OxIKjNCyEnzpZBSx/alCFhGa9I5Q0QqWFKGQQtYSC6iCWPe/qDsM0cBmC Tf0KAJG+3XhYnDY2cdDMNYa6rAsytQisGxaQy7uI5QO2XNMoLPMlvJBEkm1UG66pLPRd CF3UZOkjSOAC9w/Dap/BMpT0dgCf3oMn9G0xj6YsUSjc67wMBU0BHeigOY1+w3Iap0Gu A/z34AUMfvHZ7R80ZBPXJfOq7EbH/eA6ABNJ+PRl+vQQcdeSXjws+CAg9RIeQSCdofuJ 37txxlO+GY/bZqjp7gn6Q9BWE1T7/9tTDE7nUUbd1mhAhSB+QVhPzjwosSkZsqyu94jL S/2g== 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=Sw5FFiK/t6evnu3E904I82pkwQ3g660/lP3rLmMmBPk=; b=jS6OuNhfqz77iQYlcDNe3jLk6hJFFhQ2eeX1A99w4QXRKdlZAYKpDPV9V5HxgRQa59 ZGvjEecWHGcTC8xgIsJ2J/hOriW2lTn9LdZ4yBA7WfvjfBz9g4SNK8Few1M+aIT5eIu6 XQzL3IqLfeU9xRQ2pEhjUshJSYxQXo/k+7OiYRqJ/9Fu6+3o7UpDdDnkTWqfKRVbVxh3 ZqUxLOPx7hj2aUfkubCMchj0+DVLt50Kz2rIdWIOIvC/d1CraC+PiC0l5AWEQaOQrC0V 1+6rneP/uI1QLkIx7l4SrGKBaJvqkPBOV6MJzfIQyuU2MzvmXiIrDXzZihF35fZYTSCR RZ8A== X-Gm-Message-State: AOAM531ny31D7uH3QyWIEeCJ1TazPxmwnuixylNHNkF1+416KOsxtg5u jlbo6OYIJhCtwga+Hg/uEiDtvWtTdvM= X-Google-Smtp-Source: ABdhPJzto4FToq+oIPwCE/ifvyBWNT6dQaPGTN0a3p2HZwmONolWrp58FlKDn5m+mNlkDldfYZtkrg== X-Received: by 2002:a1c:df8a:: with SMTP id w132mr1213028wmg.90.1606173611090; Mon, 23 Nov 2020 15:20:11 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f16sm1500797wmh.7.2020.11.23.15.20.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 15:20:10 -0800 (PST) Message-Id: <8de0c0eb228c8d9608d3a78c992cbd6829cb9329.1606173607.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 23:20:05 +0000 Subject: [PATCH v2 2/4] branch -m: allow renaming a yet-unborn branch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In one of the next commits, we would like to give users some advice regarding the initial branch name, and how to modify it. To that end, it would be good if `git branch -m ` worked in a freshly initialized repository without any commits. Let's make it so. Signed-off-by: Johannes Schindelin --- builtin/branch.c | 3 ++- t/t0001-init.sh | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/builtin/branch.c b/builtin/branch.c index efb30b8820..10609981e6 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -538,7 +538,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int strbuf_addf(&logmsg, "Branch: renamed %s to %s", oldref.buf, newref.buf); - if (!copy && rename_ref(oldref.buf, newref.buf, logmsg.buf)) + if (!copy && (oldname != head || !is_null_oid(&head_oid)) && + rename_ref(oldref.buf, newref.buf, logmsg.buf)) die(_("Branch rename failed")); if (copy && copy_existing_ref(oldref.buf, newref.buf, logmsg.buf)) die(_("Branch copy failed")); diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 69a320489f..69c5ad179c 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -571,4 +571,10 @@ test_expect_success 'invalid default branch name' ' test_i18ngrep "invalid branch name" err ' +test_expect_success 'branch -m with the initial branch' ' + git init rename-initial-branch && + git -C rename-initial-branch branch -m renamed && + test renamed = $(git -C rename-initial-branch symbolic-ref --short HEAD) +' + test_done From patchwork Mon Nov 23 23:20:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11926855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A3EAC63798 for ; Mon, 23 Nov 2020 23:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34F19206A1 for ; Mon, 23 Nov 2020 23:20:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rDnQfcTT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726188AbgKWXUP (ORCPT ); Mon, 23 Nov 2020 18:20:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725921AbgKWXUO (ORCPT ); Mon, 23 Nov 2020 18:20:14 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB886C0613CF for ; Mon, 23 Nov 2020 15:20:13 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id l1so20455003wrb.9 for ; Mon, 23 Nov 2020 15:20:13 -0800 (PST) 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=j7BCmDzGgwjvLopRsreJSrFUlkAwIXlafwC1ZI0e88g=; b=rDnQfcTTz+H6KJBB1axKnbr4zDizNIRVPz0qaTSt3zWQE0OQiF2/6UA6w2cTO7+0uB SFwkmKtHRavpRpixx0UTqIm4jKJfg2UGRN9K3u8ulfETktq+aoS5Uznd0ilQMC0t0uev IdDl4nTgSe2NBZW1wap+0wG76QYHNwpNK6e0cP+5et43L/UB4RPX2/qKL18pcRcoZe98 6En/HKBQwKU3X+uU4SV14/dtwpMCwWDRxjewSfK4YeTPM/JKkctF43YWKZ7/cjDawkTq HYhp+Hcm/F3K+OJjCIUkuzckLQXyGqHG7/Fk1Ow2hgDMRNk0d3g3ElbedbLGVPAHE8BA dViQ== 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=j7BCmDzGgwjvLopRsreJSrFUlkAwIXlafwC1ZI0e88g=; b=Lt7MJ3D30U65JgljwIUrpVvmyzdS5ml2OhP/7Wf9jqHosh1ggTyiB4wxGMXx2SNw0f ROoSWGS7pRe1k3/4LhjCc85fnfwJ5lUjkH+ha44IbGsvy2IQkP8aoBWyk6tdusGXKl0v UKjx42s+Mdhfptiw/iFZ7BbAKuGdMprURD7xGvIDFAC1+2ucS9kKaOOp+hiN4l5HO4vv kaeN75HAR6vhERYR3ixI3fx8dg2VxquXSfcAMWyHc0ZHlR1JEjE12ufMLjosZhoX9avJ yO4PgO2aFzTUt1s5PvG//gsHHMoIPeSO04mgKz4dXmKDQ8QA+DuICEsC6kNFdh5UQg7F ngaQ== X-Gm-Message-State: AOAM530eGXiwla5C1z+nheqkE+Pg88nVosXygv22ejdRTKeYb7J2U1BW PAdxNR1qP3qb8cUJXFy4KOOPlqWIW6g= X-Google-Smtp-Source: ABdhPJzm/ey/7yNhAgCBkOYtGYFn6n4EYGFJzWY+nMUsME36MeayMk/bCcLiSMTWPacTQeE/qSYMKg== X-Received: by 2002:adf:e449:: with SMTP id t9mr2020168wrm.257.1606173612117; Mon, 23 Nov 2020 15:20:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u16sm21689151wrn.55.2020.11.23.15.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 15:20:11 -0800 (PST) Message-Id: <03314f7ac6ae093d5a685bcbf0ca3d4403d6c5bb.1606173607.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 23 Nov 2020 23:20:06 +0000 Subject: [PATCH v2 3/4] get_default_branch_name(): prepare for showing some advice Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin We are about to introduce a message giving users running `git init` some advice about `init.defaultBranch`. This will necessarily be done in `repo_default_branch_name()`. Not all code paths want to show that advice, though. In particular, the `git clone` codepath _specifically_ asks for `init_db()` to be quiet, via the `INIT_DB_QUIET` flag. In preparation for showing users above-mentioned advice, let's change the function signature of `get_default_branch_name()` to accept the parameter `quiet`. Signed-off-by: Johannes Schindelin --- builtin/clone.c | 2 +- builtin/init-db.c | 8 +++++--- refs.c | 6 +++--- refs.h | 4 ++-- remote.c | 5 +++-- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index a0841923cf..64b1784011 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1323,7 +1323,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) remote_head = NULL; option_no_checkout = 1; if (!option_bare) { - const char *branch = git_default_branch_name(); + const char *branch = git_default_branch_name(0); char *ref = xstrfmt("refs/heads/%s", branch); install_branch_config(0, branch, remote_name, ref); diff --git a/builtin/init-db.c b/builtin/init-db.c index 01bc648d41..dcc45bef51 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -202,7 +202,8 @@ void initialize_repository_version(int hash_algo, int reinit) static int create_default_files(const char *template_path, const char *original_git_dir, const char *initial_branch, - const struct repository_format *fmt) + const struct repository_format *fmt, + int quiet) { struct stat st1; struct strbuf buf = STRBUF_INIT; @@ -267,7 +268,7 @@ static int create_default_files(const char *template_path, char *ref; if (!initial_branch) - initial_branch = git_default_branch_name(); + initial_branch = git_default_branch_name(quiet); ref = xstrfmt("refs/heads/%s", initial_branch); if (check_refname_format(ref, 0) < 0) @@ -438,7 +439,8 @@ int init_db(const char *git_dir, const char *real_git_dir, validate_hash_algorithm(&repo_fmt, hash); reinit = create_default_files(template_dir, original_git_dir, - initial_branch, &repo_fmt); + initial_branch, &repo_fmt, + flags & INIT_DB_QUIET); if (reinit && initial_branch) warning(_("re-init: ignored --initial-branch=%s"), initial_branch); diff --git a/refs.c b/refs.c index 392f0bbf68..8df03122d6 100644 --- a/refs.c +++ b/refs.c @@ -562,7 +562,7 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix) strvec_pushf(prefixes, *p, len, prefix); } -char *repo_default_branch_name(struct repository *r) +char *repo_default_branch_name(struct repository *r, int quiet) { const char *config_key = "init.defaultbranch"; const char *config_display_key = "init.defaultBranch"; @@ -585,12 +585,12 @@ char *repo_default_branch_name(struct repository *r) return ret; } -const char *git_default_branch_name(void) +const char *git_default_branch_name(int quiet) { static char *ret; if (!ret) - ret = repo_default_branch_name(the_repository); + ret = repo_default_branch_name(the_repository, quiet); return ret; } diff --git a/refs.h b/refs.h index 6695518156..ff05d2e9fe 100644 --- a/refs.h +++ b/refs.h @@ -170,8 +170,8 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **ref); * The return value of `repo_default_branch_name()` is an allocated string. The * return value of `git_default_branch_name()` is a singleton. */ -const char *git_default_branch_name(void); -char *repo_default_branch_name(struct repository *r); +const char *git_default_branch_name(int quiet); +char *repo_default_branch_name(struct repository *r, int quiet); /* * A ref_transaction represents a collection of reference updates that diff --git a/remote.c b/remote.c index 8a6dbbb903..bdb88d4b7d 100644 --- a/remote.c +++ b/remote.c @@ -284,7 +284,7 @@ static void read_branches_file(struct remote *remote) if (frag) *(frag++) = '\0'; else - frag = (char *)git_default_branch_name(); + frag = (char *)git_default_branch_name(0); add_url_alias(remote, strbuf_detach(&buf, NULL)); refspec_appendf(&remote->fetch, "refs/heads/%s:refs/heads/%s", @@ -2206,7 +2206,8 @@ struct ref *guess_remote_head(const struct ref *head, /* If a remote branch exists with the default branch name, let's use it. */ if (!all) { - char *ref = xstrfmt("refs/heads/%s", git_default_branch_name()); + char *ref = xstrfmt("refs/heads/%s", + git_default_branch_name(0)); r = find_ref_by_name(refs, ref); free(ref); From patchwork Mon Nov 23 23:20:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11926859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D58AFC6379F for ; Mon, 23 Nov 2020 23:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EC1A206B6 for ; Mon, 23 Nov 2020 23:20:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h8IFO6If" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbgKWXUR (ORCPT ); Mon, 23 Nov 2020 18:20:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725921AbgKWXUP (ORCPT ); Mon, 23 Nov 2020 18:20:15 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563CAC0613CF for ; Mon, 23 Nov 2020 15:20:15 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id c198so912958wmd.0 for ; Mon, 23 Nov 2020 15:20:15 -0800 (PST) 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=S1mJYwfot+/yR0Z+YdILZrd7BIOV3xV2oa6vSLvNCSc=; b=h8IFO6IfK5CRER7EaeOsHp4gf81Tf7NEkcqf4BYMCyS/DHkNqJRodPSYx6cdgmXxhv sZlMaXWefExuvkWfv77kuqGPOgi51Go+jnTI5gaVzKfWXM21pBDrclbQlOTlvDwp/6r0 gS8S1QjeOzfJt0v/n+eKiOlIEszhnXFqC/1kxsTm+cRjUyY6CPVfJPjWkgRw5RqEF0LG U7VTW+E7G7oV5Fk9j/8CGlK1TjyYClsZN82YdSdf0+ZyQhAevVf7Nh+GTooxlES6s6VB 0vhbc4FUV7/+daWblBvQY44NTnOl2xnHjR9J8QwKsS3XS/ZESTeW9cqLeU4VM5ulWqEv jYTQ== 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=S1mJYwfot+/yR0Z+YdILZrd7BIOV3xV2oa6vSLvNCSc=; b=oVOWjQrzwO7r+KbUtN/LoXCOXME8/4yesmtrSdF2ki69PwGsEXO+y9kjlFyeNN3Y95 Ok9Ms3p+NcEjWEwW+li3TKTvlnlchida1MTA32m+mxnsZNxOEaF4Ogq1VGK2QIohHjls NMElgcDwSN0KsmvBAqJXkEuQXQ4NiNw0PosPgeq38dkeoXd8EWCM0WuA5McBKzm8s3t0 K1mgdPrWwnQXnxbMwHGjEzjbtLwrX/NgomvDvi0FJne0vscVSFSPRTBhkxclhtW4mfAL xv4k9HpGfCEjKavWG0bILOoGkL6Bbzrny+VscdasxTv0IO40pca0Ma/03E2sieUQ9kCw riXw== X-Gm-Message-State: AOAM530vcWef2VBsrm8bSAYK5jJ+WRt51NQ2ieJngTQlM4ZusyX1gUJx ubSuKaNu8pLfA2M5+FmY7WP4gGahKOA= X-Google-Smtp-Source: ABdhPJyhm7ZDD2YlGyDDBjbYvYI3fveuI3qm8mY7orvAM1/4bUniiWj7b0qa14JJgNo/+X6nbCoQUQ== X-Received: by 2002:a1c:9ad3:: with SMTP id c202mr1157403wme.43.1606173613432; Mon, 23 Nov 2020 15:20:13 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u203sm1419485wme.32.2020.11.23.15.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2020 15:20:12 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 23 Nov 2020 23:20:07 +0000 Subject: [PATCH v2 4/4] init: provide useful advice about init.defaultBranch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin To give ample warning for users wishing to override Git's the fall-back for an unconfigured `init.defaultBranch` (in case we decide to change it in a future Git version), let's introduce some advice that is shown upon `git init` when that value is not set. Note: two test cases in Git's test suite want to verify that the `stderr` output of `git init` is empty. With this patch, that is only true if `init.defaultBranch` is configured, so let's do exactly that in those test cases. The same reasoning applies to `test_create_repo()`. Signed-off-by: Johannes Schindelin --- refs.c | 19 ++++++++++++++++++- t/t0001-init.sh | 9 ++++++++- t/t1510-repo-setup.sh | 2 +- t/test-lib-functions.sh | 3 ++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/refs.c b/refs.c index 8df03122d6..67275858fc 100644 --- a/refs.c +++ b/refs.c @@ -562,6 +562,20 @@ void expand_ref_prefix(struct strvec *prefixes, const char *prefix) strvec_pushf(prefixes, *p, len, prefix); } +static const char default_branch_name_advice[] = N_( +"Using '%s' as the name for the initial branch. This default branch name\n" +"is subject to change. To configure the initial branch name to use in all\n" +"of your new repositories, run:\n" +"\n" +"\tgit config --global init.defaultBranch \n" +"\n" +"Common names are 'main', 'trunk' and 'development'. If you merely wish\n" +"to suppress this warning, you can also use the current default branch\n" +"name. The current branch can be renamed via this command:\n" +"\n" +"\tgit branch -m \n" +); + char *repo_default_branch_name(struct repository *r, int quiet) { const char *config_key = "init.defaultbranch"; @@ -574,8 +588,11 @@ char *repo_default_branch_name(struct repository *r, int quiet) else if (repo_config_get_string(r, config_key, &ret) < 0) die(_("could not retrieve `%s`"), config_display_key); - if (!ret) + if (!ret) { ret = xstrdup("master"); + if (!quiet) + advise(_(default_branch_name_advice), ret); + } full_ref = xstrfmt("refs/heads/%s", ret); if (check_refname_format(full_ref, 0)) diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 69c5ad179c..6f693d9609 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -163,7 +163,7 @@ test_expect_success 'reinit' ' ( mkdir again && cd again && - git init >out1 2>err1 && + git -c init.defaultBranch=initial init >out1 2>err1 && git init >out2 2>err2 ) && test_i18ngrep "Initialized empty" again/out1 && @@ -558,6 +558,13 @@ test_expect_success 'overridden default initial branch name (config)' ' grep nmb actual ' +test_expect_success 'advice on unconfigured init.defaultBranch' ' + GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= git -c color.advice=always \ + init unconfigured-default-branch-name 2>err && + test_decode_color decoded && + test_i18ngrep "hint: " decoded +' + test_expect_success 'overridden default main branch name (env)' ' test_config_global init.defaultBranch nmb && GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=env git init main-branch-env && diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh index 9974457f56..5189a520a2 100755 --- a/t/t1510-repo-setup.sh +++ b/t/t1510-repo-setup.sh @@ -79,7 +79,7 @@ setup_repo () { name=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 && sane_unset GIT_DIR GIT_WORK_TREE && - git init "$name" && + git -c init.defaultBranch=repo init "$name" && maybe_config "$name/.git/config" core.worktree "$worktreecfg" && maybe_config "$name/.git/config" core.bare "$barecfg" && mkdir -p "$name/sub/sub" && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 59bbf75e83..68305a4939 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1202,7 +1202,8 @@ test_create_repo () { mkdir -p "$repo" ( cd "$repo" || error "Cannot setup test environment" - "${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" init \ + "${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \ + -c init.defaultBranch=${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master} init \ "--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 || error "cannot run git init -- have you built things yet?" mv .git/hooks .git/hooks-disabled