From patchwork Sun Feb 23 10:14:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11398755 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCD14930 for ; Sun, 23 Feb 2020 10:15:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC496208C4 for ; Sun, 23 Feb 2020 10:15:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Aa5cev1/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726661AbgBWKPG (ORCPT ); Sun, 23 Feb 2020 05:15:06 -0500 Received: from mail-yw1-f44.google.com ([209.85.161.44]:37125 "EHLO mail-yw1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725980AbgBWKPG (ORCPT ); Sun, 23 Feb 2020 05:15:06 -0500 Received: by mail-yw1-f44.google.com with SMTP id l5so3852253ywd.4 for ; Sun, 23 Feb 2020 02:15:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U/WDZK+zVSB2YGwKLpDvMxT/bEyjh7Bx4tnDu44Nsps=; b=Aa5cev1/LKorZ/h+s3QqgWVFCpNbX1qn3q9/GbSuhL/GZhC03bGoI06vL6BofJsWrJ fvZoXot2Zq6rudkJmbYSU2n9MFi2fc4soRuIQ1WZluSqjcCtJ+PDGOj2SUA4t7FQ2SWo kbr/CdruwoBcqoKOXnzFT1pcPlavDzyMiKtHuUD43EQ4HKTOqCIEZQHcpbNqydYd3feU iugDkVP9+LdHfT3Dsjn+9TCqNxu+VHfaZJva/JjhndzIt3Reskocvz2lZ6TiqQPXmKOG t4XVJEIZbbPkkbIBlo0ZbKZIRxtpc6+f+UuTuKxMs2FBRpsy1sgz9KXtRKmFmHu+ND0Q lbrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=U/WDZK+zVSB2YGwKLpDvMxT/bEyjh7Bx4tnDu44Nsps=; b=blSN8FP73xVCfgsxmNVXrZo1t+PAxJqAK8dgHmPlHjjesKR+XkiCy1WSDNR9jwIU1W TLbv7pizZ8U6RBQgxrekFasV+SVymVV2Mdr+D3464joSAyDYDWKwxavIaOi2EH6ilE6A wDLrAcJO8x317WdqcCVTkJouMx9ejgt2CRRvQ/uIRq7zB7vwIMIc8rm+vKG7GLiqQDky 1VP72vMDAKdL0+67Z3g75tgyyUa/wurgFLu3q3PBntD09a7vtQhCIcGLPGOMgVrdCccd JjbAMj7dWxv9mLbWMqYrS3tfXOnAWkcWHXFMimoQKctHKbdRTHt8yD4ZNKx1mPEv45RJ MDWQ== X-Gm-Message-State: APjAAAUPYOEsO8HBdlPXtN1LrvOsLkZbea3ZRFbG/L4JEfUZdPcfwQAz Mk5n72LrRs48ulMgWI2VC4ZOXp3o X-Google-Smtp-Source: APXvYqyZBm5CKl6scULov29lptPSwM5NvGBHLHZ7oXDwkSk/FsOfRAmW9ic0YWXRHeukks/sEOmPjg== X-Received: by 2002:a0d:c245:: with SMTP id e66mr21805549ywd.32.1582452904870; Sun, 23 Feb 2020 02:15:04 -0800 (PST) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id j11sm3621767ywg.37.2020.02.23.02.15.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Feb 2020 02:15:04 -0800 (PST) From: Eric Sunshine To: git@vger.kernel.org Cc: Mike Hommey , Eric Sunshine Subject: [PATCH 1/2] t3400: make test clean up after itself Date: Sun, 23 Feb 2020 05:14:06 -0500 Message-Id: <20200223101407.77036-2-sunshine@sunshineco.com> X-Mailer: git-send-email 2.25.1.526.gf05a752211 In-Reply-To: <20200223101407.77036-1-sunshine@sunshineco.com> References: <20200220002932.5jws6qpnivlvxckw@glandium.org> <20200223101407.77036-1-sunshine@sunshineco.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This test intentionally creates a file which causes rebase to fail, thus it is important that this file be deleted before subsequent tests are run which are not expecting such a failure. In the past, the common way to ensure cleanup (regardless of whether the test succeeded or failed) was either for the next test to perform the previous test's cleanup as its first step or to do the cleanup at global scope outside of any tests. With the introduction of 'test_when_finished', however, tests can be responsible for their own cleanup. Therefore, update this test to clean up after itself. A bit of history: This 'rm' invocation was moved from within the body of the following test to global scope by bffd750adf (rebase: improve error message when upstream argument is missing, 2010-05-31), which postdates, by about a month, introduction of 'test_when_finished' in 3bf7886705 (test-lib: Let tests specify commands to be run at end of test, 2010-05-02). Signed-off-by: Eric Sunshine --- t/t3400-rebase.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 221b35f2df..6e746dca00 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -143,11 +143,11 @@ test_expect_success 'setup: recover' ' test_expect_success 'Show verbose error when HEAD could not be detached' ' >B && + test_when_finished "rm -f B" && test_must_fail git rebase topic 2>output.err >output.out && test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" output.err && test_i18ngrep B output.err ' -rm -f B test_expect_success 'fail when upstream arg is missing and not on branch' ' git checkout topic && From patchwork Sun Feb 23 10:14:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 11398757 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0214F17E0 for ; Sun, 23 Feb 2020 10:15:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6380208C3 for ; Sun, 23 Feb 2020 10:15:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Lk/6ANJF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726822AbgBWKPI (ORCPT ); Sun, 23 Feb 2020 05:15:08 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:38532 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725980AbgBWKPH (ORCPT ); Sun, 23 Feb 2020 05:15:07 -0500 Received: by mail-yw1-f68.google.com with SMTP id 10so3852522ywv.5 for ; Sun, 23 Feb 2020 02:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OT/T5yCIWZOcuyJFRVOF1MSij16ttYqNK1TDhGSGqY0=; b=Lk/6ANJF0uroyoV8kcqtSj4yAzPBxBMIXf4QMxAk1+AH8XuvKfR5nYdFhArYBPDmXS L68kYCyRaWZrDs4GX85A8Ba6kIkDJ97wp9eN5XPDf/6gu2DZmSiX9fD/nRQ42RMjG0Fb K8wzKuEEeREWBG7U3mPczseDM8HxLNxbMScsIF5KTgc+ydp3G8ErD98zPdK3Jc9ySp3e +kpIkse1DAixAgFvqSUjh9PjA+D27HGToLhtJXsj3vGCUiRhWKEGgI0pnE+5PwVevOB3 vvMx1EivkvGfFYSimIPF9kQdKeE6elwtHQ3cstE+NnBVrcygeT+5ynxrbCLnKTzg+wYw 1Oyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=OT/T5yCIWZOcuyJFRVOF1MSij16ttYqNK1TDhGSGqY0=; b=b+wYTYV99pNIDGLYyfJrnVejyraUkb2YY0aDAFmfJR8BbExdJYm3WXcwhCg6fDXZec N+GFn90FIl7wc+WYKvHNyBPxolafLdK2EM5Zv8HrN1eZs3v2nXPpvK7l1nlkJMe20qRV 5CUHAQZMLZcS5An8s/caMfbzbuOgBt/nQsYUChRCFonZyP7uxnn10KSzGUYprEvfyN6q ASJwx4hsDllOXLENT8uZPAESGsEV8faZA8A+pHBkCgEQ/7vPg3Cb0FMWjygpbU2xbHvC l4tUucpqabPx8X5kq2JjwFC9cok6XpTzrAMLkVDFQSfwkbt2IZisin6RJqFQjzH0M6XH TijA== X-Gm-Message-State: APjAAAWRNrtG80tO3r8lD92lW/qcFdk5MaR88Oiq5Qdq2T94RYiEayvm IRKaQ/MbLscRS4I+m5xt/3JokNu3 X-Google-Smtp-Source: APXvYqxyekm4zZ3L8FGiVWgz3OubSpBirL+jlLMXX9uOxxHkil/4H7UpZKPqGip9nMNyTaNm7K1MSA== X-Received: by 2002:a0d:d8cb:: with SMTP id a194mr35033263ywe.472.1582452906169; Sun, 23 Feb 2020 02:15:06 -0800 (PST) Received: from localhost.localdomain (user-12l2dpj.cable.mindspring.com. [69.81.55.51]) by smtp.gmail.com with ESMTPSA id j11sm3621767ywg.37.2020.02.23.02.15.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Feb 2020 02:15:05 -0800 (PST) From: Eric Sunshine To: git@vger.kernel.org Cc: Mike Hommey , Eric Sunshine Subject: [PATCH 2/2] rebase: refuse to switch to branch already checked out elsewhere Date: Sun, 23 Feb 2020 05:14:07 -0500 Message-Id: <20200223101407.77036-3-sunshine@sunshineco.com> X-Mailer: git-send-email 2.25.1.526.gf05a752211 In-Reply-To: <20200223101407.77036-1-sunshine@sunshineco.com> References: <20200220002932.5jws6qpnivlvxckw@glandium.org> <20200223101407.77036-1-sunshine@sunshineco.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The invocation "git rebase " switches to before performing the rebase operation. However, unlike git-switch, git-checkout, and git-worktree which all refuse to switch to a branch that is already checked out in some other worktree, git-rebase switches to unconditionally. Curb this careless behavior by making git-rebase also refuse to switch to a branch checked out elsewhere. Reported-by: Mike Hommey Signed-off-by: Eric Sunshine --- builtin/rebase.c | 5 +++-- t/t3400-rebase.sh | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 6154ad8fa5..41b9372c0b 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1945,10 +1945,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) /* Is it a local branch? */ strbuf_reset(&buf); strbuf_addf(&buf, "refs/heads/%s", branch_name); - if (!read_ref(buf.buf, &options.orig_head)) + if (!read_ref(buf.buf, &options.orig_head)) { + die_if_checked_out(buf.buf, 1); options.head_name = xstrdup(buf.buf); /* If not is it a valid ref (branch or commit)? */ - else if (!get_oid(branch_name, &options.orig_head)) + } else if (!get_oid(branch_name, &options.orig_head)) options.head_name = NULL; else die(_("fatal: no such branch/commit '%s'"), diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 6e746dca00..9aa5268a06 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -377,4 +377,22 @@ test_expect_success 'rebase -c rebase.useBuiltin=false warning' ' test_must_be_empty err ' +test_expect_success 'switch to branch checked out here' ' + git checkout master && + git rebase master master +' + +test_expect_success 'switch to branch not checked out' ' + git checkout master && + git branch other && + git rebase master other +' + +test_expect_success 'refuse to switch to branch checked out elsewhere' ' + git checkout master && + git worktree add wt && + test_must_fail git -C wt rebase master master 2>err && + test_i18ngrep "already checked out" err +' + test_done