From patchwork Sat Feb 4 23:25:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13128893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B9EAC61DA4 for ; Sat, 4 Feb 2023 23:25:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbjBDXZs (ORCPT ); Sat, 4 Feb 2023 18:25:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjBDXZr (ORCPT ); Sat, 4 Feb 2023 18:25:47 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84CAE21A3C for ; Sat, 4 Feb 2023 15:25:46 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id m16-20020a05600c3b1000b003dc4050c94aso6325974wms.4 for ; Sat, 04 Feb 2023 15:25:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=XYtFSzEGfzzrCxiWW05PuL5+G1crhD/FYztyx3bFnms=; b=pDpIZLVfTcmmy/xH/xqKXFqnW7ASjM6FKmY4azqvN2ku9cY6+y0duXklwzdjVXVZgI mTVdPnN5Y4JaZMpO1aF1p22zv/ONlF+jVUyWZlbkx9IBsO2tqjmeX+Am8dBDrU56rHQ6 lMz+iSc6xQUm4djR9oq0bPovWDD/3HnyQ/LDZwRqa0WLiqWVKe72zDhjBWbUy0xquZwU 9lrb6Odl0uIGiap4Iw5lx5URWbkOUy4GpIr9ijcoV8Q048b1m2wLxgxlThE+FcMTzHMn vOEIq+OTGaBVINjXeBGGUjkMS2bhEe19M3KQwdlZ8jGHgH+G6LPTJPbAaalREWBj+30F cOmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XYtFSzEGfzzrCxiWW05PuL5+G1crhD/FYztyx3bFnms=; b=3A/UXpAzKqIDegouwwdSA0gl49LMJR3KsmqV3lE+7pR9ruwSYMrBQcBizOU+Oy7Kt2 5SpfVxioTqPqq3EqNQwc08wLxgdWMozI/6+X1oyc/3HjFZgsJtre6TJEKiTQsh1W7Csk tJvTAi6KTbA3kNkP7ccT7xT5iG2MX0V3X3SWsj22Cg7mwCWlplTMTI5f0LZI46hYe9F+ jqMDjycvOKH90LR6KTo63rkinSFgNhmB+E+xtYdL4NLE2bTISzTNcA5ZzJD8/IVUOP8a fW/WzipQnQy8GL8TJGSubC37DC/LjzblJIq43C6TWnQInWtoiWFHFra/HpuhcmQPNcFd /u3g== X-Gm-Message-State: AO0yUKVn8RWlkURsKYngklxcLii8mScFQMK8Z57IWRunh+w7rLtVmrXA A8JhYoSIJZ3xTrwUsK0cgS8= X-Google-Smtp-Source: AK7set+blkXu1LCABflO5jwQ9PL1fw7OSCxR+iJ4tP86uRPaQLnLmiFoiUe5iQRmN3dwbdmQfEQktg== X-Received: by 2002:a05:600c:1ca0:b0:3dc:4042:5c30 with SMTP id k32-20020a05600c1ca000b003dc40425c30mr13776871wms.10.1675553145004; Sat, 04 Feb 2023 15:25:45 -0800 (PST) Received: from [192.168.2.52] (85.red-88-14-56.dynamicip.rima-tde.net. [88.14.56.85]) by smtp.gmail.com with ESMTPSA id q14-20020a05600c46ce00b003dc47d458cdsm7023705wmo.15.2023.02.04.15.25.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 04 Feb 2023 15:25:44 -0800 (PST) Subject: [PATCH v3 1/4] worktree: introduce is_shared_symref() From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Message-ID: Date: Sun, 5 Feb 2023 00:25:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a new function, is_shared_symref(), which contains the heart of find_shared_symref(). Refactor find_shared_symref() to use the new function is_shared_symref(). Soon, we will use is_shared_symref() to search for symref beyond the first worktree that matches. Signed-off-by: Rubén Justo --- worktree.c | 62 +++++++++++++++++++++++++++--------------------------- worktree.h | 6 ++++++ 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/worktree.c b/worktree.c index aa43c64119..40cb9874b7 100644 --- a/worktree.c +++ b/worktree.c @@ -403,44 +403,44 @@ int is_worktree_being_bisected(const struct worktree *wt, * bisect). New commands that do similar things should update this * function as well. */ -const struct worktree *find_shared_symref(struct worktree **worktrees, - const char *symref, - const char *target) +int is_shared_symref(const struct worktree *wt, const char *symref, + const char *target) { - const struct worktree *existing = NULL; - int i = 0; + const char *symref_target; + struct ref_store *refs; + int flags; - for (i = 0; worktrees[i]; i++) { - struct worktree *wt = worktrees[i]; - const char *symref_target; - struct ref_store *refs; - int flags; + if (wt->is_bare) + return 0; - if (wt->is_bare) - continue; + if (wt->is_detached && !strcmp(symref, "HEAD")) { + if (is_worktree_being_rebased(wt, target)) + return 1; + if (is_worktree_being_bisected(wt, target)) + return 1; + } - if (wt->is_detached && !strcmp(symref, "HEAD")) { - if (is_worktree_being_rebased(wt, target)) { - existing = wt; - break; - } - if (is_worktree_being_bisected(wt, target)) { - existing = wt; - break; - } - } + refs = get_worktree_ref_store(wt); + symref_target = refs_resolve_ref_unsafe(refs, symref, 0, + NULL, &flags); + if ((flags & REF_ISSYMREF) && + symref_target && !strcmp(symref_target, target)) + return 1; - refs = get_worktree_ref_store(wt); - symref_target = refs_resolve_ref_unsafe(refs, symref, 0, - NULL, &flags); - if ((flags & REF_ISSYMREF) && - symref_target && !strcmp(symref_target, target)) { - existing = wt; - break; - } + return 0; +} + +const struct worktree *find_shared_symref(struct worktree **worktrees, + const char *symref, + const char *target) +{ + + for (int i = 0; worktrees[i]; i++) { + if (is_shared_symref(worktrees[i], symref, target)) + return worktrees[i]; } - return existing; + return NULL; } int submodule_uses_worktrees(const char *path) diff --git a/worktree.h b/worktree.h index 9dcea6fc8c..7889c4761d 100644 --- a/worktree.h +++ b/worktree.h @@ -149,6 +149,12 @@ const struct worktree *find_shared_symref(struct worktree **worktrees, const char *symref, const char *target); +/* + * Returns true if a symref points to a ref in a worktree. + */ +int is_shared_symref(const struct worktree *wt, + const char *symref, const char *target); + /* * Similar to head_ref() for all HEADs _except_ one from the current * worktree, which is covered by head_ref(). From patchwork Sat Feb 4 23:25:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13128894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DF8FC636CC for ; Sat, 4 Feb 2023 23:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231230AbjBDX0A (ORCPT ); Sat, 4 Feb 2023 18:26:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjBDXZ7 (ORCPT ); Sat, 4 Feb 2023 18:25:59 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0536421A3C for ; Sat, 4 Feb 2023 15:25:58 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id k8-20020a05600c1c8800b003dc57ea0dfeso8425997wms.0 for ; Sat, 04 Feb 2023 15:25:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=hZwMB0zbtjYOBsSvcOXNi3OcQ9VOj53le2baoggMEDQ=; b=JUKHUaqxNWguBu0oSDkIf70HdY8hH+lgDLFButlsxLznwtt+H7uk7TrQrTN5CdOI0m NZdfdQWW0GPalHa3GZiPaGTOlRzps5Vk/pF8KUiEnH8BvmZ+CtsSthVvXoyiSpKCOe85 AZY3ufxSwaSCAnylWukhbmSHxMC2MRrYc5RtE7ac6Qzd9Wzqx+d+TiXgPO6Vll/kuEVz kV7OXZf9zRQdMNSI7/Fe/k9WFuZF7LTVXKcYnRJKSr04Gcd14kyDKweosxbr/m5qb30D 3e8Lm3iJegSVBT9ggA9MgEwi2e4n2DZVxP9J/reED6TqNwDmPRKIiBFEVfK+K7Fe4rTf XX8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hZwMB0zbtjYOBsSvcOXNi3OcQ9VOj53le2baoggMEDQ=; b=RUv60bevTCIQDA0d3BqsfPDFU0T/z35VM/t5uRLxIZeTulrHQ7yzVFzabzkkRkDGfQ KlmgsUoWR937JKQHvpoq3+JdVY+qSvneimqry3RdrjLmdBRmUFfRBYn6ByI2yCXO/Omn ol4IyaQa5jo78gPwWyTjnP4CIw8wk1tegaQMUyJJCuT1qKKQAaIQp5lov/h8H/rKdYkq 1K3JcrTr//siWwcRXCPhOPACbMWqWXvApcbVvlvmG9WWtJfQxmD1WAMJ2crQeYj+Gi6U uxturxq1tefku+4O817nF5zZNIMI83QdBCsv7IYqL3fIH7C7K8c/SNblk3PsY7BQtVPL 5o4w== X-Gm-Message-State: AO0yUKVDJe0CCcpFivcvN9TNTD04pT2I/LS8DRgW4V/OxSpq3+jMS7v3 phY125zNI68XJiLmsMmJsbo= X-Google-Smtp-Source: AK7set9y/hMZdjWV4DNl7Vfue/Ny4V8aFY+zGviVGsh3rQBAfvt0gQtaimTipaylLeNVQwH68PfzJw== X-Received: by 2002:a05:600c:354e:b0:3df:ea09:fcc9 with SMTP id i14-20020a05600c354e00b003dfea09fcc9mr4152140wmq.7.1675553156448; Sat, 04 Feb 2023 15:25:56 -0800 (PST) Received: from [192.168.2.52] (85.red-88-14-56.dynamicip.rima-tde.net. [88.14.56.85]) by smtp.gmail.com with ESMTPSA id r13-20020a05600c35cd00b003dc5b59ed7asm7174748wmq.11.2023.02.04.15.25.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 04 Feb 2023 15:25:56 -0800 (PST) Subject: [PATCH v3 2/4] branch: fix die_if_checked_out() when ignore_current_worktree From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Message-ID: <8670d6c6-b5cd-a1e3-8fbf-b948cb687388@gmail.com> Date: Sun, 5 Feb 2023 00:25:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 8d9fdd7 (worktree.c: check whether branch is rebased in another worktree, 2016-04-22) die_if_checked_out() learned a new option ignore_current_worktree, to modify the operation from "die() if the branch is checked out in any worktree" to "die() if the branch is checked out in any worktree other than the current one". Unfortunately we implemented it by checking the flag is_current in the worktree that find_shared_symref() returns. When the same branch is checked out in several worktrees simultaneously, find_shared_symref() will return the first matching worktree in the list composed by get_worktrees(). If one of the worktrees with the checked out branch is the current worktree, find_shared_symref() may or may not return it, depending on the order in the list. Instead of find_shared_symref(), let's do the search using use the recently introduced API is_shared_symref(), and consider ignore_current_worktree when necessary. Signed-off-by: Rubén Justo --- branch.c | 14 +++++++++----- worktree.c | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/branch.c b/branch.c index e5614b53b3..64b7dbfd17 100644 --- a/branch.c +++ b/branch.c @@ -820,12 +820,16 @@ void remove_branch_state(struct repository *r, int verbose) void die_if_checked_out(const char *branch, int ignore_current_worktree) { struct worktree **worktrees = get_worktrees(); - const struct worktree *wt; - wt = find_shared_symref(worktrees, "HEAD", branch); - if (wt && (!ignore_current_worktree || !wt->is_current)) { - skip_prefix(branch, "refs/heads/", &branch); - die(_("'%s' is already checked out at '%s'"), branch, wt->path); + for (int i = 0; worktrees[i]; i++) { + if (worktrees[i]->is_current && ignore_current_worktree) + continue; + + if (is_shared_symref(worktrees[i], "HEAD", branch)) { + skip_prefix(branch, "refs/heads/", &branch); + die(_("'%s' is already checked out at '%s'"), + branch, worktrees[i]->path); + } } free_worktrees(worktrees); diff --git a/worktree.c b/worktree.c index 40cb9874b7..34043d8fe0 100644 --- a/worktree.c +++ b/worktree.c @@ -435,10 +435,9 @@ const struct worktree *find_shared_symref(struct worktree **worktrees, const char *target) { - for (int i = 0; worktrees[i]; i++) { + for (int i = 0; worktrees[i]; i++) if (is_shared_symref(worktrees[i], symref, target)) return worktrees[i]; - } return NULL; } From patchwork Sat Feb 4 23:26:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13128895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CA08C61DA4 for ; Sat, 4 Feb 2023 23:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231866AbjBDX0O (ORCPT ); Sat, 4 Feb 2023 18:26:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbjBDX0M (ORCPT ); Sat, 4 Feb 2023 18:26:12 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D836B22026 for ; Sat, 4 Feb 2023 15:26:11 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id l37-20020a05600c1d2500b003dfe46a9801so4852094wms.0 for ; Sat, 04 Feb 2023 15:26:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=ZjHBNeqLSs/pYqIMWgX8unSi3QbAzvP0xO/zdCMIkHo=; b=BFyCVwiY+is7U6njp4BztrSXblbmy7v9/bgKbPkvQzs7yWkJYPQ8lUMImKC4GEeiKX UCTBEzLTJFyKvyRfTG1b8pJqRL3vqFKaXZECwPip6BnwpC4NEg79FFF0bvsfKPa4mWL1 PDVzLG0MKHwcrKh5KWUWnQnuSGFdun/AMTrIvZsAu5fqcfEXbYlMLnO9ocAj/mjCTrDH wmybEH77A/IZ+Pkr05UbxQPX6Lg6atPQ17knDrinqNRWcodtGSgQ7MvVDLZx3zNikjEI 9tIHf9LlD5kOsS/wxV3mnfn62HPc9qyH8ybpiUh3Iu+Le8nLBftkwRnorCNcsOl0Tt4Y ueBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZjHBNeqLSs/pYqIMWgX8unSi3QbAzvP0xO/zdCMIkHo=; b=8Ks2SYE43OTYNpImxn7rKediQIj2iKFTEFNA0FwFBhw7CEGvUuAUp9jRPLbwd4WQx6 8KdW06UnGG2rWd6s3bHb1CVoRLwDU05IpDCUHo9n2GxUSHI4Gii2/7VhZgEFHYgKlzaC klcOm3JP0RUag85oJNon0UzOIP+OOc9uqA5n+CavxRBDZLTtd9cE2OCLXjJ7GohlskcC ZaEPAE0F0VIqbGwjfsENpjyoyyRNWu8gV/AUqO3psSm4c72KPwLiJBxlFzasx6DRbW/N czBArZjJq8eYjkYEHoKYnxAWkW34WWQRI4jCK+NUVvAeKpDBcsIBEHGNf+OvvN4rA97D pYCw== X-Gm-Message-State: AO0yUKUxofcoAQ/qoT8YtNcK3scLnW1y62mIQ9e0arLsvzmxeYlePIXN FTkiClHz7+d3Rzz9LbYYPVFTo3NhImc= X-Google-Smtp-Source: AK7set+ilTtdUFnpv6DE82aZsaaqPSW0hzj4TG0Za8lo6d5ClVEYLr+Q8nLjlU5hPGtngWEJK3FPQA== X-Received: by 2002:a05:600c:1e19:b0:3dc:52fc:7f06 with SMTP id ay25-20020a05600c1e1900b003dc52fc7f06mr13651146wmb.41.1675553170397; Sat, 04 Feb 2023 15:26:10 -0800 (PST) Received: from [192.168.2.52] (85.red-88-14-56.dynamicip.rima-tde.net. [88.14.56.85]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c469000b003a84375d0d1sm12636080wmo.44.2023.02.04.15.26.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 04 Feb 2023 15:26:10 -0800 (PST) Subject: [PATCH v3 3/4] rebase: refuse to switch to a branch already checked out elsewhere (test) From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Message-ID: <5b0d5b6e-5055-6323-1b6c-fe98137e81f6@gmail.com> Date: Sun, 5 Feb 2023 00:26:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In b5cabb4a9 (rebase: refuse to switch to branch already checked out elsewhere, 2020-02-23) we add a condition to prevent a rebase operation involving a switch to a branch that is already checked out in another worktree. A bug has recently been fixed that caused this to not work as expected. Let's add a test to notice if this changes in the future. Signed-off-by: Rubén Justo --- t/t3400-rebase.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index d5a8ee39fc..3ce918fdb8 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -388,6 +388,20 @@ test_expect_success 'switch to branch checked out here' ' git rebase main main ' +test_expect_success 'switch to branch checked out elsewhere fails' ' + test_when_finished " + git worktree remove wt1 && + git worktree remove wt2 && + git branch -d shared + " && + git worktree add wt1 -b shared && + git worktree add wt2 -f shared && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_must_fail git -C wt1 rebase shared shared && + test_must_fail git -C wt2 rebase shared shared +' + test_expect_success 'switch to branch not checked out' ' git checkout main && git branch other && From patchwork Sat Feb 4 23:26:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13128896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CB22C636CC for ; Sat, 4 Feb 2023 23:26:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232124AbjBDX01 (ORCPT ); Sat, 4 Feb 2023 18:26:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjBDX00 (ORCPT ); Sat, 4 Feb 2023 18:26:26 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE63422026 for ; Sat, 4 Feb 2023 15:26:23 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so8414351wmb.2 for ; Sat, 04 Feb 2023 15:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=BOdibKdMGHDB1zNbm5hBI+eesv7GEKskhjDC1YrlgfY=; b=Y/iLk5jhG/dIxufB/HA1Yo1pPXvgLnd0li02JbYKLN9R46ODWF2kB5DVlirHj5br8Q X99+4lpn0p1AgG0LJQbTc1iwDALGvagIZrRr5xDqJFnzq2xjKWgNgtsVQzLYNsJUL6PB owZIzT3GYOdao4unWCBEzJxcsBPk91cv34+0TH1KkXdkJkyLHbKjfGggMjNieVb8gy7R ZOeP89/zgBJbFJ3lt/NXQtiEfnIFs9adlP0/4M2xM28nsWlin9cGRaimZ3HbU8eD7nrJ ukuIhvOfFHUZ3zwZlOBZR5yy3L9zozx7L4rZXxYEXDev2Ch36yPiKF5ndBZ1h8hrjkoZ EzBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BOdibKdMGHDB1zNbm5hBI+eesv7GEKskhjDC1YrlgfY=; b=ksgu9cSRsWza5peJav+1zzcMgxUq7kUR++ipCiL3Wsn87k4n5ixHHrZ6ciLmNZl2jx EmzTi8dXmuXDLBgn+9LGAY/QwM9lPfpEBs8SA4KZoN+QKfjmJka6N6MuvlPWH0VeOneA wqLwb/cAXTwPAppFF8TUnHVDDvCLEcOwzj1Qjl8r3JBpHuAyuIOhuEr1734FFgVKpB6Y uINRDJG8fay6UVbv/gCguifla415bsKxqXmQdlaogfiDWysW1EfCYLOaHxDiyf3Pwc3j /q4gVQocG8aXtt78DTl3artUhIDtEECxJ5WGU4BY6JxXiC4S4djFLixK0rlrPkNUFaWs exiQ== X-Gm-Message-State: AO0yUKXcsb78pTqoXVGXC62iZw1tPHp80YzJdEil8WpuJPtmhS2RhjYe prQrcXx5GthUVvIZXBov1As= X-Google-Smtp-Source: AK7set+H3kbJmTCsM92WO5ZyCd5n8cagN/hS/s6Z/zzC9VfqGVCxh7cng9ShKflM4wLeqhuBGxwnXA== X-Received: by 2002:a05:600c:a07:b0:3df:db2f:66a with SMTP id z7-20020a05600c0a0700b003dfdb2f066amr10483821wmp.31.1675553182455; Sat, 04 Feb 2023 15:26:22 -0800 (PST) Received: from [192.168.2.52] (85.red-88-14-56.dynamicip.rima-tde.net. [88.14.56.85]) by smtp.gmail.com with ESMTPSA id n9-20020a05600c3b8900b003d9aa76dc6asm12715341wms.0.2023.02.04.15.26.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 04 Feb 2023 15:26:22 -0800 (PST) Subject: [PATCH v3 4/4] switch: reject if the branch is already checked out elsewhere (test) From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Message-ID: Date: Sun, 5 Feb 2023 00:26:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <02a15ebb-b927-1048-db2e-576abef9538b@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since 5883034 (checkout: reject if the branch is already checked out elsewhere) in normal use, we do not allow multiple worktrees having the same checked out branch. A bug has recently been fixed that caused this to not work as expected. Let's add a test to notice if this changes in the future. Signed-off-by: Rubén Justo --- t/t2060-switch.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh index 5a7caf958c..7bea95dba2 100755 --- a/t/t2060-switch.sh +++ b/t/t2060-switch.sh @@ -146,4 +146,33 @@ test_expect_success 'tracking info copied with autoSetupMerge=inherit' ' test_cmp_config "" --default "" branch.main2.merge ' +test_expect_success 'switch back when temporarily detached and checked out elsewhere ' ' + test_when_finished " + git worktree remove wt1 && + git worktree remove wt2 && + git branch -d shared + git checkout - + " && + git checkout -b shared && + test_commit shared-first && + HASH1=$(git rev-parse --verify HEAD) && + test_commit shared-second && + test_commit shared-third && + HASH2=$(git rev-parse --verify HEAD) && + git worktree add wt1 -f shared && + git -C wt1 bisect start && + git -C wt1 bisect good $HASH1 && + git -C wt1 bisect bad $HASH2 && + git worktree add wt2 -f shared && + git -C wt2 bisect start && + git -C wt2 bisect good $HASH1 && + git -C wt2 bisect bad $HASH2 && + # we test in both worktrees to ensure that works + # as expected with "first" and "next" worktrees + test_must_fail git -C wt1 switch shared && + git -C wt1 switch --ignore-other-worktrees shared && + test_must_fail git -C wt2 switch shared && + git -C wt2 switch --ignore-other-worktrees shared +' + test_done