From patchwork Fri Apr 26 19:21:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10919617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C018F15E9 for ; Fri, 26 Apr 2019 19:21:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE9D528DF9 for ; Fri, 26 Apr 2019 19:21:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2AB828DFD; Fri, 26 Apr 2019 19:21:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96FE428DFC for ; Fri, 26 Apr 2019 19:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbfDZTVL (ORCPT ); Fri, 26 Apr 2019 15:21:11 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36477 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725875AbfDZTVK (ORCPT ); Fri, 26 Apr 2019 15:21:10 -0400 Received: by mail-pf1-f194.google.com with SMTP id z5so2182079pfn.3 for ; Fri, 26 Apr 2019 12:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/xGT0FjoZi7gwZeqWbL/jpoR+5N+lbz2j9gE6+Momo8=; b=gvPGghqtUS7iCXgEoXUktxB1lL1jFHOl4EBf7FNOAZ/rCAc08omQ7q6z9rs2OOXzPt 96WHlpO4kH+RWeS0t+2QMCEcZ1p/su0xC3XxJ8slrFWVJg7PTOdHYKmtD1u1aaq2Nwno Rx90Sv4I6X/yaerAevoZtBR1n9IqhsExNFZa9k0YsdcIz9NN/iKA45phBZcC6mJDWHwM oi+gHlcYSb+cGl2RVQPgXJH0WqRcVGzifaAeUMmnbv1EwNGa3VPQWh8gBp3Q01heNEuF uSepPG9tk7lHyGPzMTqt7fwtHM6rr0JXUhcDoJeagdNPGWz/rOQ43MuDr1+F3gMncJkf hkog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/xGT0FjoZi7gwZeqWbL/jpoR+5N+lbz2j9gE6+Momo8=; b=B1DlGF3g80/pUOFir9mdb3XJyG/j/GRoXH1M6pJwQxlpqPunclYUvTr6zJIMJ1Pwhc 50KoJVM+rL1HM4HyL5KQ9qexocoKRGAF87FXevUlyUVE7gdH2vMnLgDkg8riciiZNhC7 DpEAy/qmC77pcMmjORe10QwR5sQseynAVvbXJ0+ULXk0s7I1ugOzFOEmSyt3t3wbd4h2 9kV1oPkHVWktj213LvoPDYIKToRwMvlVodIZNtmKfnU6xF02kc1RmwwV9KiIOKUUqKwe tsJ4SnND3zPZyGq1w4K5vUVPgnDB1Mh0+6hnYNKPR56QRinWH/pRF3A+uV1tcvLQp+Cz 6mMg== X-Gm-Message-State: APjAAAVLUdepErVekDn24SIZ/ynbKAJeVhxsZFq8mp2NWj1TxYR24HmP RQE66hNiqqmhG/bdHDH6ttQfqRd5XyE= X-Google-Smtp-Source: APXvYqxqP8TKx7SX70b12TlE2v2oqMr5W42E3CowdY0/Lxh7PdOa4op4zUMneKwpNBkaUSZk64N49Q== X-Received: by 2002:a65:64da:: with SMTP id t26mr8828532pgv.322.1556306469697; Fri, 26 Apr 2019 12:21:09 -0700 (PDT) Received: from dev-l ([149.28.199.249]) by smtp.gmail.com with ESMTPSA id h19sm43047012pfd.130.2019.04.26.12.21.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 12:21:08 -0700 (PDT) Date: Fri, 26 Apr 2019 12:21:08 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano Subject: [PATCH v2 1/3] t2018: cleanup in current test Message-ID: <9d04faf29dd61eb04ea292786d72eda0a3832e51.1556305561.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before, in t2018, if do_checkout failed to create `branch2`, the next test-case would run `git branch -D branch2` but then fail because it was expecting `branch2` to exist, even though it doesn't. As a result, an early failure could cause a cascading failure of tests. Make test-case responsible for cleaning up their own branches so that future tests can start with a sane environment. Signed-off-by: Denton Liu --- t/t2018-checkout-branch.sh | 43 +++++++++++++++----------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index c5014ad9a6..f1c7023e1a 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -60,38 +60,40 @@ test_expect_success 'setup' ' ' test_expect_success 'checkout -b to a new branch, set to HEAD' ' + test_when_finished " + git checkout branch1 && + test_might_fail git branch -D branch2" && do_checkout branch2 ' test_expect_success 'checkout -b to a new branch, set to an explicit ref' ' - git checkout branch1 && - git branch -D branch2 && - + test_when_finished " + git checkout branch1 && + test_might_fail git branch -D branch2" && do_checkout branch2 $HEAD1 ' test_expect_success 'checkout -b to a new branch with unmergeable changes fails' ' - git checkout branch1 && - - # clean up from previous test - git branch -D branch2 && - setup_dirty_unmergeable && test_must_fail do_checkout branch2 $HEAD1 && test_dirty_unmergeable ' test_expect_success 'checkout -f -b to a new branch with unmergeable changes discards changes' ' + test_when_finished " + git checkout branch1 && + test_might_fail git branch -D branch2" && + # still dirty and on branch1 do_checkout branch2 $HEAD1 "-f -b" && test_must_fail test_dirty_unmergeable ' test_expect_success 'checkout -b to a new branch preserves mergeable changes' ' - git checkout branch1 && - - # clean up from previous test - git branch -D branch2 && + test_when_finished " + git reset --hard && + git checkout branch1 && + test_might_fail git branch -D branch2" && setup_dirty_mergeable && do_checkout branch2 $HEAD1 && @@ -99,27 +101,18 @@ test_expect_success 'checkout -b to a new branch preserves mergeable changes' ' ' test_expect_success 'checkout -f -b to a new branch with mergeable changes discards changes' ' - # clean up from previous test - git reset --hard && - - git checkout branch1 && - - # clean up from previous test - git branch -D branch2 && - + test_when_finished git reset --hard HEAD && setup_dirty_mergeable && do_checkout branch2 $HEAD1 "-f -b" && test_must_fail test_dirty_mergeable ' test_expect_success 'checkout -b to an existing branch fails' ' - git reset --hard HEAD && - + test_when_finished git reset --hard HEAD && test_must_fail do_checkout branch2 $HEAD2 ' test_expect_success 'checkout -b to @{-1} fails with the right branch name' ' - git reset --hard HEAD && git checkout branch1 && git checkout branch2 && echo >expect "fatal: A branch named '\''branch1'\'' already exists." && @@ -160,6 +153,7 @@ test_expect_success 'checkout -f -B to an existing branch with unmergeable chang ' test_expect_success 'checkout -B to an existing branch preserves mergeable changes' ' + test_when_finished git reset --hard && git checkout branch1 && setup_dirty_mergeable && @@ -168,9 +162,6 @@ test_expect_success 'checkout -B to an existing branch preserves mergeable chang ' test_expect_success 'checkout -f -B to an existing branch with mergeable changes discards changes' ' - # clean up from previous test - git reset --hard && - git checkout branch1 && setup_dirty_mergeable && From patchwork Fri Apr 26 19:21:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10919621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 146271575 for ; Fri, 26 Apr 2019 19:21:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 026D828DF9 for ; Fri, 26 Apr 2019 19:21:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB25E28E00; Fri, 26 Apr 2019 19:21:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5E3B28DF9 for ; Fri, 26 Apr 2019 19:21:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbfDZTVN (ORCPT ); Fri, 26 Apr 2019 15:21:13 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44732 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725875AbfDZTVM (ORCPT ); Fri, 26 Apr 2019 15:21:12 -0400 Received: by mail-pl1-f193.google.com with SMTP id y12so1995286plk.11 for ; Fri, 26 Apr 2019 12:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+H8POLCQdoLlAi1a7Fm8nOAQ7YE8GMb4TmGGZ6DpMMY=; b=Lq+pobLd8V3dtv9tD6wKSOd/oPwGIHWUk2nEcsiCTt39bZJy/9OqfkEFE1NzZNJ9rI 479UBIUx7xuphkubQCRFec2iXRS1fpJhHnAwgSwCcvaxPkNWYX2LuZwpWoPuzgETdgmF oyVNdeknwfy4A7OFInvQdvGKTh7YGbq0JWFcdohQM4ld/I/GjEdg7k5YtU5v3j811iBV JkpGxHLa6zT+QZqLp4jt/CRXgOFU0yDhqWiGLJpcKlwfajU1nIa5dAXQQuSCmL6MsvSC 0zKSzHOuQ3aHp995iOBHnASl8yzhBTlT7osRr+3Wqj57vUFWH7quNlXL8LwNAo+F89HG LAQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+H8POLCQdoLlAi1a7Fm8nOAQ7YE8GMb4TmGGZ6DpMMY=; b=lNxwc8au6DvUDGlpcsmyYlkqXWdoRQXrUuins23js+dxCcmWm2+MyLVKStBJtTn+Ol 37YUmrDFkWilcdO8LcJRHIRkuydN7lHLCdmAI7Ud0RU9BBp66DVfwu/Lt91UEx9+wKqu Q9Xtc6xIscBeUAW6qE2V31ZkB46NF4iRHjZ7Q5Eb5ryRP2DB6iPmEn+ztKjCX71CIgM6 2ZHXZXr2bM99/Ry3YxspXbrqgnjPW4bGv6lXM5xwnH+8nd3N3IcFQv6C1bXJZmihBfpA pDyjgf6XGZE718KN+PMdT+INJzk1r1bWA7GeJ7rWdEeMai0S3XKPpVCp4pD53GRb0Oed dHsw== X-Gm-Message-State: APjAAAXpUhjCCCLN9PhZiDjX9w0qVVLOI/UAZ60hljP2WbDhYampcS9b S2ytpi2VuAesqc7tOfygZkGZ28JXnaU= X-Google-Smtp-Source: APXvYqzbZsVZqWmzzKQ50EzFpS7jTDtJb/cC2Fa8HPiA6DAKLYVtR1O1SofgmHSSmcO6V6UEb0TL7g== X-Received: by 2002:a17:902:b089:: with SMTP id p9mr47705769plr.185.1556306471077; Fri, 26 Apr 2019 12:21:11 -0700 (PDT) Received: from dev-l ([149.28.199.249]) by smtp.gmail.com with ESMTPSA id a10sm34088586pfc.21.2019.04.26.12.21.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 12:21:10 -0700 (PDT) Date: Fri, 26 Apr 2019 12:21:09 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano Subject: [PATCH v2 2/3] t2018: demonstrate checkout -b merge base bug Message-ID: <5e8320cd80415f50a79815b9fcd55c051e45e38b.1556305561.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In git-checkout.txt, it states As a special case, you may use `"A...B"` as a shortcut for the merge base of `A` and `B` if there is exactly one merge base. You can leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. However, there exists a bug where performing $ git checkout -b test master... fails with the message fatal: Not a valid object name: 'master...'. Demonstrate this failure so that it can be corrected later. Signed-off-by: Denton Liu --- t/t2018-checkout-branch.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index f1c7023e1a..3cd142657a 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -66,6 +66,13 @@ test_expect_success 'checkout -b to a new branch, set to HEAD' ' do_checkout branch2 ' +test_expect_failure 'checkout -b to a merge base' ' + test_when_finished " + git checkout branch1 && + test_might_fail git branch -D branch2" && + git checkout -b branch2 branch1... +' + test_expect_success 'checkout -b to a new branch, set to an explicit ref' ' test_when_finished " git checkout branch1 && @@ -126,6 +133,12 @@ test_expect_success 'checkout -B to an existing branch resets branch to HEAD' ' do_checkout branch2 "" -B ' +test_expect_failure 'checkout -B to a merge base' ' + git checkout branch1 && + + git checkout -B branch2 branch1... +' + test_expect_success 'checkout -B to an existing branch from detached HEAD resets branch to HEAD' ' git checkout $(git rev-parse --verify HEAD) && From patchwork Fri Apr 26 19:21:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10919623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B87841575 for ; Fri, 26 Apr 2019 19:21:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5BD828DF9 for ; Fri, 26 Apr 2019 19:21:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A65228DFD; Fri, 26 Apr 2019 19:21:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5ACF528DFC for ; Fri, 26 Apr 2019 19:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbfDZTVO (ORCPT ); Fri, 26 Apr 2019 15:21:14 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35516 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726679AbfDZTVN (ORCPT ); Fri, 26 Apr 2019 15:21:13 -0400 Received: by mail-pg1-f195.google.com with SMTP id h1so2070005pgs.2 for ; Fri, 26 Apr 2019 12:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=VTnscqqTxCdKttZknuiVR4oea6vxDOrjzR7p2ihiUD0=; b=dS5JN2dbX6l4YOVmhgJ+0Yg0MpANr3b8SlEdlj2lGqhZFCQyodQNJ7RBXHUjH7PUcg M9fEgeNmyGb9qTQdpvxPbv3rokPEjeKXHTLhkR0ef8f1oP9V/DCL/TZndh5m7so8SNpS EgT2bCTSyLGKahxFPGr8IBUFlVvvD8T5GhsGru7nDh79BtayleBotfJfzj0Tf0RZACkW PZoSCOwsP1h9jlRUWi58ETShOJz4UsHAU5QtoC8spFUxqNCsxwT557s5C8KpYn/jt2xw qj1OaevAHEJcxXGQbiR8OmxVlWxYPqMmWtthnakYvlomE0F00Zl1mkihYPyBr+VijXpU nlNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=VTnscqqTxCdKttZknuiVR4oea6vxDOrjzR7p2ihiUD0=; b=UQN7SQJWtyfeK7LJmILqi34MbDVNlEy/oDP84a2HrByk3joTda5xXiKQuj1mF7vXkY p53kKdTeoy7SRZZ1H71dU60M6Vq8NR7M+64IImH4LRz0ZFTaio5mMPolMOvq2501bWMv VaDO4GuJ+/rnyCofIsuOoSonQ/qCu3gIGwazrc01Hvfj0VcZCuQ77BMou5MXx6x+ynVm pdmOs83bgRaBn5g9E40rdJhXrVNyneZbduJrDlPvqUzCKZQMlagz7bSBUQoC8Ufbvb/A NklKPKODcaOk1Bs+jw1q3EWHxhjkCHWhBYq691kv0qETJSu2crN49XYfYbxYKonpJ2/B azSg== X-Gm-Message-State: APjAAAW50kMt5pn86outI90MUM7VYxS6KcguN8JYTqFAW0zxfWT0vj4o ggOXx+3s1k9OXJaxMO0g8mQnz2hgJYg= X-Google-Smtp-Source: APXvYqw/gtU8dhCUm6MQP0UpUt+PlKkjpyO0geGyvQWAOVXy/YbCuJYjaRKPNzN0Tk11aEj2cXKaWw== X-Received: by 2002:a65:638f:: with SMTP id h15mr45342955pgv.147.1556306472233; Fri, 26 Apr 2019 12:21:12 -0700 (PDT) Received: from dev-l ([149.28.199.249]) by smtp.gmail.com with ESMTPSA id x128sm47686132pfx.103.2019.04.26.12.21.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 12:21:11 -0700 (PDT) Date: Fri, 26 Apr 2019 12:21:11 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano Subject: [PATCH v2 3/3] branch: make create_branch accept a merge base rev Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we ran something like $ git checkout -b test master... it would fail with the message fatal: Not a valid object name: 'master...'. This was caused by the call to `create_branch` where `start_name` is expected to be a valid rev. However, git-checkout allows the branch to be a valid _merge base_ rev (i.e. with a "...") so it was possible for an invalid rev to be passed in. Make `create_branch` accept a merge base rev so that this case does not error out. As a side-effect, teach git-branch how to handle merge base revs as well. Helped-by: Junio C Hamano Signed-off-by: Denton Liu --- Documentation/git-branch.txt | 6 +++++- branch.c | 2 +- t/t2018-checkout-branch.sh | 4 ++-- t/t3200-branch.sh | 14 ++++++++++---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index 0cd87ddeff..6ebd512b4f 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -45,7 +45,11 @@ argument is missing it defaults to `HEAD` (i.e. the tip of the current branch). The command's second form creates a new branch head named -which points to the current `HEAD`, or if given. +which points to the current `HEAD`, or if given. As a +special case, for , you may use `"A...B"` as a shortcut for +the merge base of `A` and `B` if there is exactly one merge base. You +can leave out at most one of `A` and `B`, in which case it defaults to +`HEAD`. Note that this will create the new branch, but it will not switch the working tree to it; use "git checkout " to switch to the diff --git a/branch.c b/branch.c index 28b81a7e02..a84c8aaca2 100644 --- a/branch.c +++ b/branch.c @@ -268,7 +268,7 @@ void create_branch(struct repository *r, } real_ref = NULL; - if (get_oid(start_name, &oid)) { + if (get_oid_mb(start_name, &oid)) { if (explicit_tracking) { if (advice_set_upstream_failure) { error(_(upstream_missing), start_name); diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index 3cd142657a..822381dd9d 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -66,7 +66,7 @@ test_expect_success 'checkout -b to a new branch, set to HEAD' ' do_checkout branch2 ' -test_expect_failure 'checkout -b to a merge base' ' +test_expect_success 'checkout -b to a merge base' ' test_when_finished " git checkout branch1 && test_might_fail git branch -D branch2" && @@ -133,7 +133,7 @@ test_expect_success 'checkout -B to an existing branch resets branch to HEAD' ' do_checkout branch2 "" -B ' -test_expect_failure 'checkout -B to a merge base' ' +test_expect_success 'checkout -B to a merge base' ' git checkout branch1 && git checkout -B branch2 branch1... diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 478b82cf9b..acb16b62dd 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -42,6 +42,10 @@ test_expect_success 'git branch a/b/c should create a branch' ' git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c ' +test_expect_success 'git branch mb master... should create a branch' ' + git branch mb master... && test_path_is_file .git/refs/heads/mb +' + test_expect_success 'git branch HEAD should fail' ' test_must_fail git branch HEAD ' @@ -292,8 +296,8 @@ test_expect_success 'git branch --list -v with --abbrev' ' test_expect_success 'git branch --column' ' COLUMNS=81 git branch --column=column >actual && cat >expected <<\EOF && - a/b/c bam foo l * master n o/p r - abc bar j/k m/m master2 o/o q + a/b/c bam foo l * master mb o/o q + abc bar j/k m/m master2 n o/p r EOF test_cmp expected actual ' @@ -315,6 +319,7 @@ test_expect_success 'git branch --column with an extremely long branch name' ' m/m * master master2 + mb n o/o o/p @@ -332,8 +337,8 @@ test_expect_success 'git branch with column.*' ' git config --unset column.branch && git config --unset column.ui && cat >expected <<\EOF && - a/b/c bam foo l * master n o/p r - abc bar j/k m/m master2 o/o q + a/b/c bam foo l * master mb o/o q + abc bar j/k m/m master2 n o/p r EOF test_cmp expected actual ' @@ -357,6 +362,7 @@ test_expect_success 'git branch -v with column.ui ignored' ' m/m * master master2 + mb n o/o o/p