From patchwork Tue Nov 24 15:07:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11929173 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 EFC96C2D0E4 for ; Tue, 24 Nov 2020 15:08:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 979D8206F9 for ; Tue, 24 Nov 2020 15:08:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h0OFgS4g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389584AbgKXPHf (ORCPT ); Tue, 24 Nov 2020 10:07:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389084AbgKXPHf (ORCPT ); Tue, 24 Nov 2020 10:07:35 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C41C1C0617A6 for ; Tue, 24 Nov 2020 07:07:34 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id r3so4363302wrt.2 for ; Tue, 24 Nov 2020 07:07:34 -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=h0OFgS4g2N5TM92OTK3f2V8c0znNK18rM+UVtqTa6fbZabN8P+owDmCOnTZxNr4Sy5 TnRLmk9GfqwvNdNWR2yYQbEeXI+8pBK3Mgz0PqVEWTl46y7wnnEkyLb5tC5Zw+frR4W3 WIjfvwCFa8mYna2rfYup2R3zwKkqGoIruKYjtMRgF/kmptB8frYO72bDUbSiz7+M6cQT vkYLOcz9lNh9ZsS0FVt3m7Qte3Z7byB0zvgh3+oRjONly+pkq02vBcxSb1bLhrw37uUY 6LNXJlK3LOchHH3ImXevMmfxIyVu1FJdeyiBLQ2rnn542DSSElJY8Z2FRx0/BBEle1dO H+Pw== 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=QCoXQ8WbFOKrxFxoAi7UCBYw+YKzjLpl0sqh37d3GMjhPXzrMTSYGusRQqE+wue4pp 327GLlUMMOBJOzkuyB9uVc9EPiPwtT5Jj+1Zj4hTcQDn9SaI3T6n9bF6m8BO5yJcNeqw IA0kr3PFIXc3gyKR/xyKX4pvLQAq42vNEuhKE8UNuRIhySp2bDXyWqgdKXlaKqKY+yZf pOAl74xa/kLalHvNFY99dY5GZpoc5Shzaiz88UbTBqSKJfs2BNYxwOr0SOnB2UvvIwDh QkJF5i6gT5OQfImnNNaNDJ5ry0Uk/zydzVPhELzU0ayzH5NKHstLDbcCX8xU4JvZsfzx vJsQ== X-Gm-Message-State: AOAM532M0gjw2eZroycIIf3uBn/ShVZn9UmZO/4SvbQmkniF6jc7fIWU e3MBzMqYuLEz1MAqf+zd8nd7TK2SE1Y= X-Google-Smtp-Source: ABdhPJysGNmrNhdSX/w8Xmyw/edh7WnJ2znu5Ak3odAeKEJ8xvXfvnBagrQKPxGfqY3ayBPlj4Q8JA== X-Received: by 2002:adf:ead1:: with SMTP id o17mr5953980wrn.396.1606230453349; Tue, 24 Nov 2020 07:07:33 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w11sm5734426wmg.36.2020.11.24.07.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 07:07:32 -0800 (PST) Message-Id: <483e490349165223a80a0bdf7716c5189560c977.1606230450.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Nov 2020 15:07:26 +0000 Subject: [PATCH v3 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 Tue Nov 24 15:07:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11929181 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 6E89AC56201 for ; Tue, 24 Nov 2020 15:08:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18817206F9 for ; Tue, 24 Nov 2020 15:08:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m8+5w9YV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389588AbgKXPHg (ORCPT ); Tue, 24 Nov 2020 10:07:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389084AbgKXPHg (ORCPT ); Tue, 24 Nov 2020 10:07:36 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98C7C0613D6 for ; Tue, 24 Nov 2020 07:07:35 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id 23so22629589wrc.8 for ; Tue, 24 Nov 2020 07:07:35 -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=qaLCsUupMWieXeT+MBb9mlGZ7Zq+Czs7uQzFOxGjNMk=; b=m8+5w9YVN8QJ7P2+z0/UKkjcNIL3/FYNhJJW8VBcBwWC+/u+jLghYk8rmUrTh3KPV8 2ofzJVoSpDSU4sWANwdai8Ylf1geohjDL+oIZBy72U2KgmpRFxt9f2oYed+1ovsKnU7k oYWWpfQ8C4LPDcuki2KNHRIfRMy5Y2My5ZkxsgZCca0lu1iLVBF+MpFeuTKGLmO9dY9f XunZR0VO+XH5M2WovxfMQJUb2GYQpxdhZStXRujbbRqIAxDfIzmTHg/f6NFSIEkEGVfI pZ1R4mgiiHyeNs7lsVmLK3qyfk95FhYgQAuR6reXdmTvHPZZXpvHI+BOooMjehIbq8FX zL9A== 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=qaLCsUupMWieXeT+MBb9mlGZ7Zq+Czs7uQzFOxGjNMk=; b=gr/udVcDNuxeLWTcVs23AW6EjXu/tXDr9n+1Z9eZvHx/3Uz0m+ptpZZaHtrGWquyHn mKqEVV3aEySp+nyfwm/XwsTQWrsQ14zbQNLykcM0zX543hviv3by0PYPPh0f1CAErXeB 92opAkJQKGW0wC2/aruZ+faMiCUOqiuY5C0Yc/MobIuYiZQX5waFEAW0nv08egBa11Zu pxYYpkkOGujh+The6ELR+bdVqR8glBg/oAwGCCTRcYVfkekzYBs+u6CWG6r9LTORq/da 818hvaTzM4u1y3zv8hgLes+dW1ZEIaA0aptZ6bAfZ2MtJUtKDNVn+XS/f+CXjo73dBYa Cc9w== X-Gm-Message-State: AOAM5318ane3wXLTSc6hRfziOhYWkQME5WSCWhQTazDGXi8HqTuM3hMI o12nCO3lqMFG8/RKlOMft/H5gJZoGPg= X-Google-Smtp-Source: ABdhPJyJ+Ji2UktVRHEXbGauUAS2Ji2JOYc+bzTLA6Jk/3r2SqO1+qra1Knwqx5CYQv6vhgaO0IXkw== X-Received: by 2002:adf:ea47:: with SMTP id j7mr5727910wrn.126.1606230454279; Tue, 24 Nov 2020 07:07:34 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z189sm6069311wme.23.2020.11.24.07.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 07:07:33 -0800 (PST) Message-Id: <6cbd6692c6a4d0586e3418225029e70b0001ffb1.1606230450.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Nov 2020 15:07:27 +0000 Subject: [PATCH v3 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 | 4 +++- t/t0001-init.sh | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/branch.c b/builtin/branch.c index efb30b8820..200da319f1 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -538,7 +538,9 @@ 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 && + (!head || strcmp(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..bb23e56a16 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -571,4 +571,12 @@ 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 && + git -C rename-initial branch -m renamed && + test renamed = $(git -C rename-initial symbolic-ref --short HEAD) && + git -C rename-initial branch -m renamed again && + test again = $(git -C rename-initial symbolic-ref --short HEAD) +' + test_done From patchwork Tue Nov 24 15:07:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11929179 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 36635C64E7A for ; Tue, 24 Nov 2020 15:08:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE80A20715 for ; Tue, 24 Nov 2020 15:08:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tu+RPTaL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389610AbgKXPHm (ORCPT ); Tue, 24 Nov 2020 10:07:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389084AbgKXPHl (ORCPT ); Tue, 24 Nov 2020 10:07:41 -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 CCC4AC0613D6 for ; Tue, 24 Nov 2020 07:07:40 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id a3so3194397wmb.5 for ; Tue, 24 Nov 2020 07:07:40 -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=Tu+RPTaLvbNR0ohBzho81mT/wT3rDVa4BZEv72NYjnop6KiTE8GlWeL/0KD1K7zG5Z qJ27qMa7iQKwlZBqX8phhmmDV6HFFj6Bqnvqw/bDvwP6dUUptmqlg02uUM4kpJ+B4eZY pSsuLPg+s++badxxk1hfmbtYSnjHbmdbbwg2exOpiUWge1xNmyVdMxF8qC420IX0pRcr hADTkg28xtpAwuODC7Re7jIJ2TZKzCIUSZG33izp62JP+y2QvwRCgjVfNWn4/zgr4A0N 7na0yqlYqCvHL6TfK2FpjRdH0dkuPFCOp45sRMa3ikSxm5dahuPhZ0qaMqnusetMhY5L /29Q== 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=Sbat4WI6snwZTO76xIx50afVTEM0HxHz7ajuOq5q1VYkJP4x63HpD8R7yHW1XDT5Vd YsFPz3ix5yhn09UYZZCDG+eCsIWaKrN1NmE+yv56bBKnb7UCdQCRjqIS5n/ry8vzG5i4 dyYHoWYHClibWiYUmNMvf28C4T1kSCYA/gJldYzLpCFhzReYr2GttQV8IjIQmSYM7P7M pmQ1cOzINjkruavEhBoG2LZ12rFopvgOMQ9YwcQDI4kQrBjy+T1M53qKYz3CCRBHtbtv aZMHaiPu4KlXdQq2MwlQCF1rHpZINzHaBCMEW4zku2T4/ZdO3Cp6tNcHkbExnYymrh7p KERQ== X-Gm-Message-State: AOAM532unNCOMZLP//FV3TR0eGFs0MYzv/s5LchUAO2YAd2rGlB+6g9J Y4LPCukD7fFSO8oju53/heaTiK8nTeA= X-Google-Smtp-Source: ABdhPJxBQ2BDAoMUZiBGd1fQ87FQdYWKeAJowGCOpxb/SbTSaQZPMU/NJqrn8E7LFnoPA5TjOBa0QQ== X-Received: by 2002:a05:600c:d1:: with SMTP id u17mr4843295wmm.38.1606230455385; Tue, 24 Nov 2020 07:07:35 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h15sm27106833wrw.15.2020.11.24.07.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 07:07:34 -0800 (PST) Message-Id: <5fc15f7b9adaf64c2fbfd58f6e96768f5b9d7f8b.1606230450.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Nov 2020 15:07:28 +0000 Subject: [PATCH v3 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 Tue Nov 24 15:07:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11929177 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 915C6C64E75 for ; Tue, 24 Nov 2020 15:08:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 553E020715 for ; Tue, 24 Nov 2020 15:08:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D5nhKZr7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389595AbgKXPHj (ORCPT ); Tue, 24 Nov 2020 10:07:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389084AbgKXPHi (ORCPT ); Tue, 24 Nov 2020 10:07:38 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D32EBC0613D6 for ; Tue, 24 Nov 2020 07:07:37 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id a65so3215819wme.1 for ; Tue, 24 Nov 2020 07:07:37 -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=MkFqOJuWMH4ERXouqLxuQMPLWBPdoS5jNAFLvyF+QxI=; b=D5nhKZr76G3a6J2j06P1HWr+LKpqKLDwnxDaMJmhpNQ79Bn4MruB62oad1V5jqQJsO t/RFXHNQqhqXj//RHMF1cCSC8nmuCuV5gJE9JPHtWjl+FHB7+/Zj2jIbi8Yr2H7wYUGl 4h4PcudUXQdvDA1lQgOXZ0196zXPTGD2B63+PR84CL8th1dwY8iLGcYHCnGJzS/A9C7v x1H1UdQb45g3arpeKj8oBu9W3mUEUXUyH1Z1+GwJ3wkMJ+e2Vsu4Mmfr5h3Fkv7f4nnq uRkyLISOQuHsNC64IS9Z1d9gOZjEFsr77Gliov3o55qxEb1SpttSlRAp3JgoLMxUajkD HIDA== 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=MkFqOJuWMH4ERXouqLxuQMPLWBPdoS5jNAFLvyF+QxI=; b=Gzq/Ns3S1yn+BosxaOorPCU4VESVLWeI+qcUyk2KvjTvQTHyxd5eM6RPj6zmo1R3MP hwpHuEJgq+4EZ2v+K/LAy8poXYmzfdduoprwb/NprTXD39uofmgwTRm32mGBfoUPX+y9 Xf4i9qKUbeXJwvJE6cvv1JAX6paV+xToqesPQAqlJVOZTrvikZXpS3G9pKGIsCPuXN4r 25qi0B9J5yQLYT4u9d2HrHOFcOxca72S3JLJsBOLwywr9qx0u08CIxpTmdjrbMM/wjry iWt82Akj5bVSA4vidpkfegqdGJJmxpJGS6aSEVwpAlwV5MrYKfKwC/785c/edHB68Umy SD8Q== X-Gm-Message-State: AOAM533NjDBBrSAD7Vg1TF1rfP31/TmnsSPCVi6oO+pFqLV7Ic37G/Ew inwTU7LVCV7HI6heN3XeP/8krukisC0= X-Google-Smtp-Source: ABdhPJykrB6K/cSlmlKv7y9jkoWAnaup0pnPpQhj6WT3PMe79Kxep7nyXAia1YzaHj5YzWAiZHvxZw== X-Received: by 2002:a1c:f619:: with SMTP id w25mr4995896wmc.55.1606230456321; Tue, 24 Nov 2020 07:07:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 17sm8196170wma.3.2020.11.24.07.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 07:07:35 -0800 (PST) Message-Id: <87c93068771238a65d0753cc41261c2a97ca4fd9.1606230450.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 24 Nov 2020 15:07:29 +0000 Subject: [PATCH v3 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. It is now necessary to suppress the advice using the newly-added `advice.defaultBranchName` setting. While not strictly necessary, we also set this to `false` in `test_create_repo()`. Signed-off-by: Johannes Schindelin --- advice.c | 1 + advice.h | 1 + refs.c | 23 ++++++++++++++++++++++- t/t0001-init.sh | 9 ++++++++- t/t1510-repo-setup.sh | 2 +- t/test-lib-functions.sh | 3 ++- 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/advice.c b/advice.c index 164742305f..8a14640193 100644 --- a/advice.c +++ b/advice.c @@ -108,6 +108,7 @@ static struct { [ADVICE_AM_WORK_DIR] = { "amWorkDir", 1 }, [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName", 1 }, [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 }, + [ADVICE_DEFAULT_BRANCH_NAME] = { "defaultBranchName", 1 }, [ADVICE_DETACHED_HEAD] = { "detachedHead", 1 }, [ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates", 1 }, [ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 }, diff --git a/advice.h b/advice.h index bc2432980a..1ae99a1b31 100644 --- a/advice.h +++ b/advice.h @@ -46,6 +46,7 @@ extern int advice_add_empty_pathspec; ADVICE_AM_WORK_DIR, ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME, ADVICE_COMMIT_BEFORE_MERGE, + ADVICE_DEFAULT_BRANCH_NAME, ADVICE_DETACHED_HEAD, ADVICE_FETCH_SHOW_FORCED_UPDATES, ADVICE_GRAFT_FILE_DEPRECATED, diff --git a/refs.c b/refs.c index 8df03122d6..c56bc1bcfb 100644 --- a/refs.c +++ b/refs.c @@ -18,6 +18,7 @@ #include "strvec.h" #include "repository.h" #include "sigchain.h" +#include "advice.h" /* * List of all available backends @@ -562,6 +563,23 @@ 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 suppress this warning, run:\n" +"\n" +"\tgit config --global advice.defaultBranchName false\n" +"\n" +"Alternatively, you can configure the initial branch name to use in all\n" +"of your new repositories, which will also suppress this warning:\n" +"\n" +"\tgit config --global init.defaultBranch \n" +"\n" +"Common names are 'main', 'trunk' and 'development'. The initial branch\n" +"that was created 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 +592,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 && advice_enabled(ADVICE_DEFAULT_BRANCH_NAME)) + 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 bb23e56a16..84047ac64e 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 advice.defaultBranchName=false 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..5305566167 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 advice.defaultBranchName=false 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..781d47a4bb 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 advice.defaultBranchName=false 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