From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id D2A191F55B for ; Wed, 10 Jun 2020 22:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726506AbgFJW6q (ORCPT ); Wed, 10 Jun 2020 18:58:46 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:56987 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726374AbgFJW6p (ORCPT ); Wed, 10 Jun 2020 18:58:45 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 9272E61529; Wed, 10 Jun 2020 18:58:41 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=i+d4nh+LBxpfGbh8DDrNhUq2X+Y=; b=AnLdlN A0X1mUZgONM1eKji/7JhjPFNBmJtg062Y/GTrBdyiuBC8tgz9F6LbG2Up/mh5UXX BmwoXxYimG6LQwBk48muVVtE3m/O6JyhrsTLSTracaOAgaewdoMp44Vfa+6XHeKv lsJzdeNcqRo0dGd9wVHkZlh0gEDM2NVsvwsi4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=IUPZygRGao/qFlXtVtjv20fzxyuLD4HK qXomT3OOOvUs43ygBqNBCrkWdgn3k3EQLykTaH2yL4olwerL8szfxZr2geDwyyXa fMCQfgpU+XAcdXrw11LqkMwOL9xLz3kz+OpbGpTNzVN59YhEmM2NiEpjX4v5T9HZ fGKaKPYkDP8= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 8896D61527; Wed, 10 Jun 2020 18:58:41 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [35.196.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 1B1E561526; Wed, 10 Jun 2020 18:58:41 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: "Johannes Schindelin via GitGitGadget" Cc: git@vger.kernel.org, don@goodman-wilson.com, stolee@gmail.com, peff@peff.net, sandals@crustytoothpaste.net, Johannes Schindelin Subject: Re: [PATCH 6/9] clone: learn about the possibly-configured default branch name References: Date: Wed, 10 Jun 2020 15:58:40 -0700 In-Reply-To: (Johannes Schindelin via GitGitGadget's message of "Wed, 10 Jun 2020 21:19:27 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: ED6BBE2E-AB6D-11EA-B19F-D1361DBA3BAF-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "Johannes Schindelin via GitGitGadget" writes: > @@ -1263,9 +1263,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix) > remote_head_points_at = NULL; > remote_head = NULL; > option_no_checkout = 1; > - if (!option_bare) > - install_branch_config(0, "master", option_origin, > - "refs/heads/master"); > + if (!option_bare) { > + char *default_branch = git_default_branch_name(0); > + const char *nick; > + > + if (!skip_prefix(default_branch, "refs/heads/", &nick)) > + BUG("unexpected default branch '%s'", > + default_branch); > + install_branch_config(0, nick, option_origin, > + default_branch); > + free(default_branch); > + } Good catch. Normal clone would follow whatever primary branch the other side uses by pointing at it with its "HEAD" but this codepath to deal with a clone of an empty repository needs to use a default, so this is an appropriate change. > write_refspec_config(src_ref_prefix, our_head_points_at, > diff --git a/t/t5609-clone-branch.sh b/t/t5609-clone-branch.sh > index 6e7a7be0522..66af3ac2669 100755 > --- a/t/t5609-clone-branch.sh > +++ b/t/t5609-clone-branch.sh > @@ -67,4 +67,13 @@ test_expect_success 'clone -b not allowed with empty repos' ' > test_must_fail git clone -b branch empty clone-branch-empty > ' > > +test_expect_success 'chooses correct default branch name' ' > + GIT_TEST_DEFAULT_BRANCH_NAME= \ > + git -c core.defaultBranchName=up clone empty whats-up && > + test_write_lines refs/heads/up refs/heads/up >expect && > + git -C whats-up symbolic-ref HEAD >actual && > + git -C whats-up config branch.up.merge >>actual && > + test_cmp expect actual > +' > + > test_done