From patchwork Fri Dec 11 11:36:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11967941 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 7B1DFC4361B for ; Fri, 11 Dec 2020 11:38:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D89B23ED0 for ; Fri, 11 Dec 2020 11:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390055AbgLKLiS (ORCPT ); Fri, 11 Dec 2020 06:38:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403810AbgLKLhm (ORCPT ); Fri, 11 Dec 2020 06:37:42 -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 95BA9C061793 for ; Fri, 11 Dec 2020 03:37:01 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id d3so7275525wmb.4 for ; Fri, 11 Dec 2020 03:37:01 -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=p0enlMc/568fNOt3yvkxyzEyBOUTnOaQV/xOUwc/+so=; b=bz0U5Fk2jDZliG5Q2QwH9TmtZqjkYJ5xYCep6+AoWk4H6b3ick3ohjdyf2ZdH2kLN6 WHOUqodJqBA+CLDqo628lBftM6ha/gveVo+gNzLBse9hHA13Ue2hUF40YZdtIl0mtj2k ju7CfD4TVoAAxXyESzroeAu3r/E4v3s8cC1Qe6JSdadCl16nU3fPL+T52TMrckEDSchm U6hJT/iRtujTe3g0c7pqUlEYq6veUruSCDtC7ldhSaIdACSsmm3XUrnLHszUBG1H303J 9IMl+djj7bkAcR8+UbmLwYgaZuCFqjjG2MkzaU924XeSKiWf1PdGy09eRnPSFAYv8c5c b8AQ== 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=p0enlMc/568fNOt3yvkxyzEyBOUTnOaQV/xOUwc/+so=; b=Vg1cAxp8DPOETQOOZIbqs12HGx+1+b2BJP6nK+5qm6Em3J70DozPa67pwBhQdywMo6 62Rs7ggabx7kcRX/Gt/LLuPFsMeLKPdMAWlPn5fX6tCJOadKtI9zb9HIRJGl34IQFTD5 6jJNOI/rjUR192pf0NCfNIhEJl8oRrQolzn8jAb1vEWUn3N2Sp2x09T6JDjiQMCOZkrB MHmcDYdFSUlQaRBZf/dPfJn630P0nyEOEc/SAhhQrJ+b1v3vR/NmjbLim0uvmnQQ7gys Lg6OLKsyQQGxTIefGO7m9Ex24AZqC9tzLgYoFcAiWNKL5O92qwJmbWCS5afV5MSFu05r ix8A== X-Gm-Message-State: AOAM530+ZI0EMQPn5B34oIvS7HxwhLDZSowZ6JPcpjGJqXIeTXprbkNl ccZqcylnKZRY57/2jiAWSe/4qivCwzU= X-Google-Smtp-Source: ABdhPJzZRR9KAIBN75l5T2KumyC+sSetT+SVCD5tyvkNMDylASN5caitiI8zacReLAVj4BxAdI5nuw== X-Received: by 2002:a1c:e445:: with SMTP id b66mr13330590wmh.187.1607686620195; Fri, 11 Dec 2020 03:37:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u85sm13454532wmu.43.2020.12.11.03.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 03:36:59 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 11 Dec 2020 11:36:54 +0000 Subject: [PATCH v5 1/4] init: document `init.defaultBranch` better Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Felipe Contreras , 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 59ecda6c17d..b611d80697d 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 this is subject to change 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 Fri Dec 11 11:36:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11967939 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 8E254C433FE for ; Fri, 11 Dec 2020 11:38:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 643CE23EF6 for ; Fri, 11 Dec 2020 11:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391060AbgLKLi2 (ORCPT ); Fri, 11 Dec 2020 06:38:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403930AbgLKLhn (ORCPT ); Fri, 11 Dec 2020 06:37:43 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93D8DC061794 for ; Fri, 11 Dec 2020 03:37:02 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id c198so7285469wmd.0 for ; Fri, 11 Dec 2020 03:37:02 -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=wMOlFeqr3KyQUvif43DnFXMdTbT099ZsyX8APEFwt4M=; b=PIZDGz8RUoE/VE8TmqENZdhqwUSyPgLFuPTeii6C+o29lV88LyYUqZvUHW6uegyDGA jaOWiSGwy036+FFrK8KYEy7mSKFFYngH0H3SCtzcoOLW0znV0uo6m/0FQOFKnNTnNrvN iDos6nh8ir8V6DEY3JpeRK9U0h5/kpV9TYEQmgJaplPPjxD+w2j3hmnFZ9RSrF7AMrAZ qB6BgFvGxbamaL3YhdL1EMDNwC1nknmZDkDNydV0gOvMrkOLeZWcPmBQWEv0OXokD/R+ 8voHbbmugsiVTG1l0jlmNtyZ4l15DTWqwYvpGxINmuAX4JY9Tgem0LccD0sswIIIkq0p 5MeA== 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=wMOlFeqr3KyQUvif43DnFXMdTbT099ZsyX8APEFwt4M=; b=NP3pCE7kkk3zjqxnOkvuE0TNtdD/2uUyKMoDDAMIgpXSZtB/yGf4N/RfDtAq+XlKEL 3OkHwjhqDZxH3H/PXqfROdctHVTBU2aNQto3+CSQeSmi934S067ceYDCxnuoBejtvlkn 3W1OUWjIDVDGuGz0EK5mebqx6VUvHMPrnTP9YvGrFkMdltXbUBZJ9EIK2h6aXpUMbWc/ LzWZ6BU+Sq4m17iK36ubGATalUBxq+wvw5OkG9AO7qPtJS35tsgV1Q1OhzQ2NJeMcvr/ F9+OGY0F3ko6ocec24ELkmZoLstAn5ku1aBsMa3RfJb979j6zSxAbFHEObWFXLnNiXFl S9Qw== X-Gm-Message-State: AOAM530QIfoFxRLPrfBJYXpZKZ1cr1RRIVTOE0xTH0CBWcHCZW2TYGwI Uh2qhBqCKZL6a/28LWDRM7CoVmUJA64= X-Google-Smtp-Source: ABdhPJyV5ExBTfYOQFb2hR9LP3CFKEoYBC/8Cz802EdBPeOra7NmcZs0TlLZaUjDedEvGO0HEMWlxQ== X-Received: by 2002:a1c:2182:: with SMTP id h124mr13089712wmh.25.1607686621158; Fri, 11 Dec 2020 03:37:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r20sm14701399wrg.66.2020.12.11.03.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 03:37:00 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 11 Dec 2020 11:36:55 +0000 Subject: [PATCH v5 2/4] branch -m: allow renaming a yet-unborn branch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Felipe Contreras , 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 efb30b88206..200da319f1d 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 69a320489fc..bb23e56a165 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 Fri Dec 11 11:36:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11967943 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 AD9D2C4361B for ; Fri, 11 Dec 2020 11:39:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D2B823DE3 for ; Fri, 11 Dec 2020 11:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391554AbgLKLin (ORCPT ); Fri, 11 Dec 2020 06:38:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390001AbgLKLiR (ORCPT ); Fri, 11 Dec 2020 06:38:17 -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 7EBEEC06179C for ; Fri, 11 Dec 2020 03:37:03 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id e25so8275711wme.0 for ; Fri, 11 Dec 2020 03:37:03 -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=dDkyjIFzTnF0UfdJyakAAWfV8URHBiRDEGa+zK2AqPY=; b=Xc61p18l8I2DHUyFWj7IsHw+6QQIRj8nwl5veb2weGfwUAuhxIw2MLW+U/HBiA1tDm OiSSKuJ3eeZCgrAcnjGGrfQFBM2Rz6Tq04w9PsEZxB44L8CsQUsXxlQJk3JFvsroWOFr JjQAuCqeLE2dVOBG16IrFJDgAq1DgodAGOPQptq1BK9+n+6F6/4X/MJtH2XRXb7237YU W0k+CSzfpdeD3IAJ1n7CVVR8X0ovuxhOJUwNKLenL37FJ2dVf80g03KFdi2ockPEmYGQ SK5Yvx5HyzW4AyqUK7+9cRIllAYZbftTqf8XbLQGuoNu4IMG/ZACsKDr2umOo84kFqBE jYYw== 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=dDkyjIFzTnF0UfdJyakAAWfV8URHBiRDEGa+zK2AqPY=; b=jKbgEu5sXfJdakcZTbAMCXJDHUqhNuBFdgfqrmDlJFHQb+I68udPJuBBMghbeH650L jjTSrtmP8KKff4cFXxeDB1YcVSIU1lJhD+Vt8hNw9FijRTg731sp+Kwkyb+a77p3jAtr aelhxP4uzc9WiSsr2EA2b+5XbRIY8SXbCbp7+5yPtfUCMwiSSybaf/vbipjdHgHq3Tsv D6i4WcEE2J/BzBFW2cbEoWCpm06bgnmS1kIZUIjsOr8I5Gpmkp2jc6GbtN7N737kcQfh GO89YJ/iu76m8GxT6iaNJ0aFdkePgl3ChiawogSsCGEtvYXRqbe0skFSuq0l0Qa28hpZ IE1A== X-Gm-Message-State: AOAM533MoaOnedsyMhIColOPtMolpYzOVBj8EFNdJCFYSMpSzLXIPBEp tBAgOtfHy7PQ+n/YpC5oUhZHH4x1Zc8= X-Google-Smtp-Source: ABdhPJwmTyryAiMeDcT8XkS4EXlG1oiIVSyZgrL+p+KKUjPqQshiTXyjmA1YonV/8LHkwbGxvdxo2Q== X-Received: by 2002:a1c:9695:: with SMTP id y143mr12718269wmd.70.1607686622049; Fri, 11 Dec 2020 03:37:02 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i7sm1507703wrv.12.2020.12.11.03.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 03:37:01 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 11 Dec 2020 11:36:56 +0000 Subject: [PATCH v5 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 , Felipe Contreras , 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 a0841923cfe..64b17840112 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 01bc648d416..dcc45bef514 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 392f0bbf68b..8df03122d69 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 66955181569..ff05d2e9fe2 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 8a6dbbb9030..bdb88d4b7dd 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 Fri Dec 11 11:36:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11967945 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 C7B02C433FE for ; Fri, 11 Dec 2020 11:39:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 722C823E20 for ; Fri, 11 Dec 2020 11:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390966AbgLKLin (ORCPT ); Fri, 11 Dec 2020 06:38:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389656AbgLKLiR (ORCPT ); Fri, 11 Dec 2020 06:38:17 -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 72B5BC0617A6 for ; Fri, 11 Dec 2020 03:37:04 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id r14so8697236wrn.0 for ; Fri, 11 Dec 2020 03:37:04 -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=1Rn8cyxnpONC0mqxfOOxLsJFwOMCn/nSjYZ04AwALuQ=; b=XECrqD+HMrgxe3bvPzwEKsG5ufV64+Anv+KE5YAXDgcX8l/zYxQ6ZnDP08w8Yvcwbc GjOJ7s43rL0dbZddcz54rfhIi8/kOW4ufz6T6JmQq//3S60q4Y047o7Aer7kUPPsKp19 xeNy0KtwfuZVA4bmYCkkAHOaIae4/q9wjsnrMS6BLhTcHcmnJsckOM002up1C/n9kh9I 3SigNs40qcdAxYNiSxf7QdpOSuFIMMk1bTtYiiLrLKE2Cvt39K0vU0TSzWq6w3+J4m36 XXj7HcJL3aJbOCVVrDxUrYTpUQhIiJZNiSGqeWYXNaguy1m5zCvbxscW6QRl3h/1gKXy AJIw== 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=1Rn8cyxnpONC0mqxfOOxLsJFwOMCn/nSjYZ04AwALuQ=; b=QxOy8fHM2Kn8dVaailzf5CLt0svdeJl0UTG3tXugPXnGXFx3GOf3jzZ7lhm0ztBKwY 5y2c5uLym4IgcgFCuB9sGEjUc/diEfxoCt49w4uEji9UzEAWBI2YX0kKTO7gcjTOh5Y3 DTkRiTW2m3qpR2tDCseE/NlQz3ThV4AaAjrUQ+iYpUgmLODNGk8DynLOFN5YdteIwJ0S ArIJH4E8Xxj8W4hHPLVdo5pj40Es9v/6YAkhFLJVKeEdlBhw5DwaXFZD/LDx2epLr6u7 Avd4EP1V91XXarua3Jq/Z1yWIpS6EfqCjI60EUssTJ75uPvexOlMDafZQLZHJ5wxnSVj rgWw== X-Gm-Message-State: AOAM532Yj0kC8oSEvl1EB8RNKuNJOfx9fcqp5QhZnLTzbHEh2PTvz+xA fyjYlgmKb2tg5yAcqUX2kOw0eZ0SBFo= X-Google-Smtp-Source: ABdhPJxpOEr8sfhdg43wmPmkZCJxO0wiXXM6NKm+utN3zQ1Sntkgm+2E4uo+0Lw4UQu1bzKC9EtuYw== X-Received: by 2002:adf:dc08:: with SMTP id t8mr13429239wri.195.1607686623028; Fri, 11 Dec 2020 03:37:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h2sm14921047wme.45.2020.12.11.03.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Dec 2020 03:37:02 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 11 Dec 2020 11:36:57 +0000 Subject: [PATCH v5 4/4] init: provide useful advice about init.defaultBranch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Felipe Contreras , 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, we now do that via the `init.defaultBranch` setting. While not strictly necessary, we also set this to `false` in `test_create_repo()`. Signed-off-by: Johannes Schindelin --- refs.c | 18 +++++++++++++++++- t/t0001-init.sh | 9 ++++++++- t/t1510-repo-setup.sh | 2 +- t/test-lib-functions.sh | 4 +++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/refs.c b/refs.c index 8df03122d69..13dc2c3291b 100644 --- a/refs.c +++ b/refs.c @@ -562,6 +562,19 @@ 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, which will suppress this warning, call:\n" +"\n" +"\tgit config --global init.defaultBranch \n" +"\n" +"Names commonly chosen instead of 'master' are 'main', 'trunk' and\n" +"'development'. The just-created 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 +587,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 bb23e56a165..0803994874f 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 9974457f561..bbfe05b8e4a 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=initial 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 59bbf75e832..9910102ae1f 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1202,7 +1202,9 @@ 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