From patchwork Sun Nov 22 23:23:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11924041 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.8 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 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 72FA8C63798 for ; Sun, 22 Nov 2020 23:23:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BADA20771 for ; Sun, 22 Nov 2020 23:23:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LAlgiDCx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726189AbgKVXXd (ORCPT ); Sun, 22 Nov 2020 18:23:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725782AbgKVXXb (ORCPT ); Sun, 22 Nov 2020 18:23:31 -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 E94B4C0613CF for ; Sun, 22 Nov 2020 15:23:30 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id r17so16947966wrw.1 for ; Sun, 22 Nov 2020 15:23:30 -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=HK8Cga6yqD2xYMQ+t6PPXGVS4VNst4tdBe0uo0y/dxk=; b=LAlgiDCxNMizgkehRd7dK7saRqtd2QkJGdOqekxv3LWLS2JllKDrQX3dl1uqGtReLU Se1s/sfUyusOOiX5kfondEQKWtehSeFRKQoOAkh2jxs7Ju9VwuJNHL8NiHJsmQlPGeN/ 6Q/3ZmfVRMaW8xE4j8Za8Qyv3nP1PQ+gRrZhMMLUXMvIoAhI3PBMr1Q4l2NqZe9AabwZ QiVi9VMLJLHrKeWsCplPHQs+1aQ66oFI2bFa6LJ8XE5by6yJT97kJ/WvFJnEMhg5w3pt p+U5CG7wwGICB+oO36zmgnCMoiX/Dl90kYu6MkytQaZ+hU7gMjmw53CDf1VQVh/d5Zar DEIA== 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=HK8Cga6yqD2xYMQ+t6PPXGVS4VNst4tdBe0uo0y/dxk=; b=O5v+dzI8qYba4k/LYwHJHmXoJGmsvxT47XmYLZU1kPFxh9pFyzFuZhG3nLehBUB3Ma YWGsNOMKPTc3I6U0GYdooZlxMXWVZdm0mb/nuLZtB6zIEjqJw+lP2JuDxmw4y7KiT+GG In7KloW+W+dS3oxieUEMOo4Yc08iSTWQN8J9Wlj/5BxiaFARp7ytMZ+ptVSE1QBKrZdE f144roZ9Cdiwj+Oj7KuDKYxDc5TCZMxRtlqXIMacOqNVshTq3Ai+hkU7rh0kuf3vUZLG 7UAnDhHT/rVvOQwZUxIVjbrcKK2P5pGTO0/duftkKcfMCvI8zwXVA3Lckpy5X/E/uJh6 Tebg== X-Gm-Message-State: AOAM53262oaRhlqlc6QIZocMJFZZvVJ0nl0FoUymriBcRQ2TG79yRviS O5BIS7XL659K7xahfnsgDRsGOcMpQ88= X-Google-Smtp-Source: ABdhPJyc502BBi2AFvhZC33Ropy87s83IrMoq8QxJCWG4GQi5fFke2hl5u/Rb853M40WxEj6vEpKTg== X-Received: by 2002:a5d:5643:: with SMTP id j3mr27122179wrw.43.1606087409273; Sun, 22 Nov 2020 15:23:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u81sm14129816wmb.27.2020.11.22.15.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2020 15:23:28 -0800 (PST) Message-Id: <1518387eaa95098707878459bc74bd5ef2179386.1606087406.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 22 Nov 2020 23:23:24 +0000 Subject: [PATCH 1/3] init: document `init.defaultBranch` better Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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..19f9f16e6b 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 Sun Nov 22 23:23:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11924037 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.8 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 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 27CD1C63777 for ; Sun, 22 Nov 2020 23:23:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE17420773 for ; Sun, 22 Nov 2020 23:23:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RlCA/SfG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726295AbgKVXXd (ORCPT ); Sun, 22 Nov 2020 18:23:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725964AbgKVXXc (ORCPT ); Sun, 22 Nov 2020 18:23:32 -0500 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 DA379C0613D3 for ; Sun, 22 Nov 2020 15:23:31 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id d142so16341358wmd.4 for ; Sun, 22 Nov 2020 15:23:31 -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=RlCA/SfGKrzhES+3w1r7vYoPIrXGwnBa0C6T29bcu0GReDbzDoIlzFAY0Vqvj4GmNz 2GfCzWWHXNHVF1Je8DQFX7brTsz4gO369lGZbFp2KZ1s4lCvcmHzHeenRV35TVnFvRiD ddXRYwRZo86pioFMbkgYZKC4/zNH52e803LvKOJ/cfffYhurptfIEVnqnPSOlcO5Oa1g orrz0id/EyLyHmJdry0hRQ4Yh48z3qTGvXRdHgZXD17PERzIn4HXHN2Cu3Z1B14p8wnj Tw30sQxfRZORJhcijX/2EY1sJSs8wYc3zeJyToSxbr5sdCYputVTrFh7EZUNDxwatfmk fW2Q== 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=KFOptCjWHxMF5k0J7uJZjXP8FoPRqrbaqMsrSDFJGFFF4i9A4EFXBy77fQWXsrzfl4 Fls7poMcmABk232VgXVr59iVLSqMDe9P4TwlgkD9IYpLjWMp7MCc9CXhPqv2B/hICBl9 mHn4t3+dmaBw/mij6ollhENq0WcypU//4KVDsnnHjoSn+kwVRUAuTZc9kCPG+Wfv2Ymp gQW5uCiiWoPd8Z3Bq76S7UCrypMiOL2OQk8pdMToVat8VfLIExtDRTpR0EEtPASRkF04 2eNk/e5QhaU17d9b0hOiJChl9VJLYr/CyDkht+eLH9ech7g2QoCtt3VsoHesTRscsy11 4S6Q== X-Gm-Message-State: AOAM530yDCyGYbeyLEBzsvACuIqDWleLgG4MklTcfEcfVmyceEZk6XPO 50gQM1RoEfnrHg/sylmpFhcbUmrQC54= X-Google-Smtp-Source: ABdhPJxw1b8lIzNQotH8U7rQ5VRFRN5OmkZSPgkJ1FCXzzhcDIPq8/yJt/HzOqgvinbFdt6bGCc5OA== X-Received: by 2002:a1c:7202:: with SMTP id n2mr20126379wmc.38.1606087410361; Sun, 22 Nov 2020 15:23:30 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n128sm13538032wmb.46.2020.11.22.15.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2020 15:23:29 -0800 (PST) Message-Id: <42f694004322361b5495f2ce1a2eba638644f754.1606087406.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 22 Nov 2020 23:23:25 +0000 Subject: [PATCH 2/3] 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 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 Sun Nov 22 23:23: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: 11924043 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.8 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 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 5C06BC56202 for ; Sun, 22 Nov 2020 23:23:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0257E20776 for ; Sun, 22 Nov 2020 23:23:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OOXZ9thY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726309AbgKVXXd (ORCPT ); Sun, 22 Nov 2020 18:23:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726020AbgKVXXd (ORCPT ); Sun, 22 Nov 2020 18:23:33 -0500 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 DCDEAC061A4A for ; Sun, 22 Nov 2020 15:23:32 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id h21so15717262wmb.2 for ; Sun, 22 Nov 2020 15:23:32 -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=HIXWg5NASEJYPPFPRKFNmHdYeJbKX8MR2xWBJPTNR6M=; b=OOXZ9thYGw24XRqv97HPK8odtTd6Uf8FF1RAKn9kogK0h0sz41BTPXGvtQqsok/GHT kj6UDctW+L32PQhv+6h+LSeRKjF7I/TJlbMrWsoEPOSpVu3q4SZeauj4s9nilIl8fjhH ZtTadKLFyoCdD5Ph8g00jTRCCMsnegXMkp7v0BNbSOgsyvmuG0fZxQYyXDT0xYbKRqzH LS4hgOmmci9G9hiDOj+NxKPgKl7GIfoYo+biiRPWjHh9Fc3f3QZAJP5EtiW2/MDeDDIy zJbEw9BiHnIUGGqG64qUnpm1/KhMBephWyhf7hZrBJBZ6Sg/rO5ch4CFzQ0qO5NfF0/d I/yw== 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=HIXWg5NASEJYPPFPRKFNmHdYeJbKX8MR2xWBJPTNR6M=; b=gTiSt+JQj4zFN647sj3KfktPZ+PoZ7Mb+tO4C3ffrmhu286hC5RxFQa9KD0M1+gfyp kMejWhUd/MXvkdWp54wGoEzFl4JBl7kUNGPEWHYo383t4I7VnmcVCRCyOvqrt4jh+bio jJ7/3m33sxbPuzklKzMCtOxEmewqfvovto+rfhiugzVxdvvaTVZt8PR469RZt0fquSDB JPEk4CDVL+jpNFj+wCDiwBTvYKYA/oRSPIm4n9WeJ5p3mDbeJhEeRqEU4x767nXBIs9r 6BkIa+aOWl2isTyGBwJVujHsJM46vrqghAVbiBNKpCcR/OiC3yaTILQ0aQk4wVb9dJI+ 3lCA== X-Gm-Message-State: AOAM532Hyd/+uibuw1MeEM/PcQezr9fZGh3HmHatchucUDNWN0jOcnif it6CcsQWXW0OG9YwJurUhQQZqOczY/E= X-Google-Smtp-Source: ABdhPJzf1jwlFNkuIfP9czEW4733s3sxNpDgZ5yjEJlUT8LM/Sni7WWBqHXazhxeuX4I7JLMxj691g== X-Received: by 2002:a1c:b787:: with SMTP id h129mr18883776wmf.67.1606087411353; Sun, 22 Nov 2020 15:23:31 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l16sm15278811wrx.5.2020.11.22.15.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2020 15:23:30 -0800 (PST) Message-Id: <253d6706e6ab97e71ec012f6de33c75f3e980701.1606087406.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 22 Nov 2020 23:23:26 +0000 Subject: [PATCH 3/3] init: provide useful advice about init.defaultBranch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 in case we decide to change the fall-back for an unconfigured `init.defaultBranch`, let's introduce some advice that is shown upon `git init` when that value is not set. Note: three 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 | 13 ++++++++++++- t/t0001-init.sh | 9 ++++++++- t/t1510-repo-setup.sh | 2 +- t/t7414-submodule-mistakes.sh | 2 +- t/test-lib-functions.sh | 3 ++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/refs.c b/refs.c index 8df03122d6..61d712ca05 100644 --- a/refs.c +++ b/refs.c @@ -562,6 +562,14 @@ 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 name is subject\n" +"to change. To configure the name to use as the initial branch name in\n" +"new repositories, or to silence this warning, run:\n" +"\n" +"\tgit config --global init.defaultBranch \n" +); + char *repo_default_branch_name(struct repository *r, int quiet) { const char *config_key = "init.defaultbranch"; @@ -574,8 +582,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 69a320489f..754dab3bab 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/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh index f2e7df59cf..0ed02938f9 100755 --- a/t/t7414-submodule-mistakes.sh +++ b/t/t7414-submodule-mistakes.sh @@ -30,7 +30,7 @@ test_expect_success 'no warning when updating entry' ' test_expect_success 'submodule add does not warn' ' test_when_finished "git rm -rf submodule .gitmodules" && - git submodule add ./embed submodule 2>stderr && + git -c init.defaultBranch=x submodule add ./embed submodule 2>stderr && test_i18ngrep ! warning stderr ' diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 59bbf75e83..772152320a 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=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