From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796455149; b=2YbwmW1AikOs8mypmUv3rw93LhVjn2jt8K4uJmIAzAx6B0YckLGc9vcO8gYFPKzJ0EJ/ h0CqcquXpmTfEeEk1iWiICFP3vc9S6E8206M7Q89P8FeeRDhlpO3pH7RO2h+LcxsPGE/J AdYUmiSS2p/dn2MJGIOMcNOQHUmlO2n+gHPg71rWzhKB4J/aJZoc3MIqraTru3F0GWZgQ B9N3OmzNnHCa23HDS2cz9HwZEqJMvUNukg3bQJncE7r5GistKrQzI4XnZR8zGyXeasDFe yZI2aWM0KegIV53bpu2MeFAa5sb6siJipqp2w8txtTLcG11G4jjmviFXSLgfaKUzQ2g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796455149; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=Q0W9C5f5PKBnUwAx2bklwKpzu/arAD6AY0cS9v/lFz8=; b=aT6iKmG35Fy5G5MuJKgDNaOrHDXmEzShEkStSNq4dDlFSqq8Xcb7iSCUHt17R789pPpm AwR7Q9ePnLNhFyb+KdB2J7ywoTXDbhaIPDrvjyCY/AeJsnrhMXt/SRvoDCLghl2n3I6Up Uw4LEu9g/KiXcsalWRx0yHEHjU1FHIDzVA6R6kbGD/F0E3JeIbZ2CndbV6TZ4iICSEdDZ oUXOnY5E1eO1sk0xzQsRS7jSt5LkNvmFeAMB8Fik8+B2OtoVzFk1e2ddsZcXw7UzseTxQ kZqzv2CQzku3OCkG1srkU97jOccQPpYrndVWalxg0D0lLhvhx7XAs4Ggrh7tMCNS2Pg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=uWQkWfzl; arc=none smtp.remote-ip=209.85.222.174 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 148B6606A681 for ; Sat, 5 Dec 2026 07:19:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 148B6606A681 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=uWQkWfzl Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-9495f083657so196801385a.0 for ; Fri, 04 Dec 2026 23:19:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796455148; x=1797059948; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=Q0W9C5f5PKBnUwAx2bklwKpzu/arAD6AY0cS9v/lFz8=; b=uWQkWfzl+tzDfR+Ud6RGdjA17RP11HCoz10aBlyDvWFFZyZ8d0BdeRDW5gTvMzmfZU g1PLNNazitya2Pqz6PqQD6UxDlgFmgr5tXBNK1n+r+3+Z6kedz33XbunIU/wHZuLg/bb WFrwlV9uiR95HTghKXFF8Sm/JuiEwol68ucx9GFo5oiqUsbfOmIK3k5nAhhhhzDiYh80 lNHm8st7+THoL+y0xp1f0TEjRsj55HRWay8ualNNuAgy2gJl6XFIkeCt5nFmOLaC3B4N 0uvyhTDzIgCbwn9GCWw2/UiNC6XJ80Tydzy2NHbjMq4Pll8W0eO1QwsiTi8Pogot4hQ8 yLNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796455148; x=1797059948; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Q0W9C5f5PKBnUwAx2bklwKpzu/arAD6AY0cS9v/lFz8=; b=MrH2wp/w1z/rWwWK0m2JW/OkUVRZssP7Hl9TgBtPWakEmrFXdnbZmB2UpbHoaCkjhl 2ky0KQHITfYAyRCr/cKM8a0tJd1VG05t3ZUjdvvnMjdZYlrdIiuHP5Op/yPh2BqP4DvH qkHgZdPmDCy+/xoeMZgRZWM3B0b61uVGKFUrFqxhpOPxuteQcgFaSwDsZARDOQk23Gb8 CLwgzCFqn6E6eBsFHyAUlsbK7O+RsKqz94+RlkO+dX5m42l2RluI4LVjToWxA/q83Y3L SwepwkqZ04WFLdnQ1RGSIBZvWu2EVLV/Pa80sc+7ZFCVRtlV+s5ovemoU6Lm3aN2Hny9 jK9A== X-Gm-Message-State: APuU4Z9/pjITwg5j6tx3zrwIGd/ZhZviNO9S5Oy8OYlyQ4Usi4L7dhnu Ic+m7Ge8wgOx+3r4HEHoEC1aL0eLlbArDeJN+HEHr5Y/8s+5+huwgrwlzxGBOJkc X-Gm-Gg: AZFdTZdgf7riazR4m7nIxahflJaYkVKAk++l52UbLIdUiKrZHhzM+ZZndIGMHqCpgUr m7mE3/scNo0IYywalm4/ZV2NxepcTtq2rBz9JgLADCNbvV2EkiWMYWwO6omild6uu62CvrgLTJd C88m+GhIq0tmlbE4vFxUYM6Sfynvkczu4XqGHYIuAIvn9am1btf31ChhQGl93+M+/ojCJtXsYlq 86+R1WljVpg1BWbk1aI8bKH4qSiWP99+pTqD9UOKaqXrPnNn1KI8FWGdRqMQh0Em3eG7kaJlqA8 FXgmA9nvlxFJcyzda/Dypzz+ACn48G9vwPxliP4Nc4elCM3nt5mzBKlftRScxxYjaGG9HqP6f4J W66qs8DqyhWPyP3J+ePtLUc/WQnaQR4cRxZCuaUVXbFOMOJq6wQRE8e2BzfwLsceP1lXrFbCI7x 0oL9LMR8sSC47ztsTdyYuNWDCmrUtcC0a172ZL4ArUb0udb7sr7fgcYLo3C1/NbWHdcucNammkw I30M8AhFnjj/fbQHRZTUTgAZECH+wRQHvAl54ioo1RWlqGLy4QWsCQS0Kz1SDDOimK49iH02trb wYP7hqRij1fuCP8HZXzzB3Lh24HnKCtbFiNiNR0dtCT7DkEA+DXJ6g== X-Received: by 2002:a05:620a:4625:b0:949:a71d:82e0 with SMTP id af79cd13be357-94a8279b772mr696862185a.13.1796455147664; Fri, 04 Dec 2026 23:19:07 -0800 (PST) Received: from [127.0.0.1] ([20.81.230.132]) by smtp.gmail.com with ESMTPSA id af79cd13be357-94a7f4dba49sm424225685a.27.2026.12.04.23.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 23:19:07 -0800 (PST) Message-Id: <9fdb6498df0ae57035bd336695fcaf4bc1cdbf7a.1796455144.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "adam torres encarnacion via GitGitGadget" Date: Sat, 05 Dec 2026 07:19:04 +0000 Subject: [PATCH 2/2] rm: relax --worktree-only restrictions Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?= Duy , Adam T , adam torres encarnacion From: adam torres encarnacion `git rm` refuses to delete paths from the working tree and index if information will be lost. This guard is too restrictive when `--worktree` is used without `--staged` (since the changes will remain in the index & therefore won't be lost). Add a new branch in `check_local_mod` to handle `--worktree` only behavior. Block only if the file differs from the index. Signed-off-by: adam torres encarnacion --- builtin/rm.c | 28 +++++++++++++++++----------- t/t3600-rm.sh | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/builtin/rm.c b/builtin/rm.c index 4160bdefe4..1f0bfbec8a 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -98,7 +98,7 @@ static void submodules_absorb_gitdir_if_needed(void) } } -static int check_local_mod(struct object_id *head, int index_only) +static int check_local_mod(struct object_id *head, int worktree, int staged) { /* * Items in list are already sorted in the cache order, @@ -197,16 +197,21 @@ static int check_local_mod(struct object_id *head, int index_only) /* * If the index does not match the file in the work * tree and if it does not match the HEAD commit - * either, (1) "git rm" without --staged definitely - * will lose information; (2) "git rm --staged" will - * lose information unless it is about removing an - * "intent to add" entry. + * either, (1) "git rm" definitely will lose information; + * (2) "git rm --staged" will lose information unless it + * is about removing an "intent to add" entry. + * "git rm --worktree" keeps the index entry, so only + * local changes are at risk. */ - if (local_changes && staged_changes) { - if (!index_only || !ce_intent_to_add(ce)) + if (worktree && !staged) { + if (local_changes) + string_list_append(&files_local, name); + } + else if (local_changes && staged_changes) { + if (worktree || !ce_intent_to_add(ce)) string_list_append(&files_staged, name); } - else if (!index_only) { + else if (worktree) { if (staged_changes) string_list_append(&files_cached, name); if (local_changes) @@ -236,8 +241,9 @@ static int check_local_mod(struct object_id *head, int index_only) Q_("the following file has local modifications:", "the following files have local modifications:", files_local.nr), - _("\n(use --staged to keep the file," - " or -f to force removal)"), + staged ? _("\n(use --staged to keep the file," + " or -f to force removal)") + : _("\n(use -f to force removal)"), &errs); string_list_clear(&files_local, 0); @@ -403,7 +409,7 @@ int cmd_rm(int argc, struct object_id oid; if (repo_get_oid(the_repository, "HEAD", &oid)) oidclr(&oid, the_repository->hash_algo); - if (check_local_mod(&oid, !worktree)) + if (check_local_mod(&oid, worktree, staged)) exit(1); } diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index d12c3448d4..a1bc8cca22 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -203,6 +203,31 @@ test_expect_success 'rm --worktree deletes the file and keeps it in the index' ' git ls-files --error-unmatch worktree-only ' +test_expect_success 'rm --worktree allows changes staged in the index' ' + echo content >worktree-staged && + git add worktree-staged && + git rm --worktree worktree-staged && + test_path_is_missing worktree-staged && + git ls-files --error-unmatch worktree-staged +' + +test_expect_success 'rm --worktree refuses to drop local modifications' ' + cat >expect <<-\EOF && + error: the following file has local modifications: + worktree-local + (use -f to force removal) + EOF + echo content >worktree-local && + git add worktree-local && + echo changed >worktree-local && + test_must_fail git rm --worktree worktree-local 2>actual && + test_cmp expect actual && + test_path_is_file worktree-local && + git rm -f --worktree worktree-local && + test_path_is_missing worktree-local && + git ls-files --error-unmatch worktree-local +' + test_expect_success 'rm --staged --worktree removes the file from both' ' echo content >staged-and-worktree && git add staged-and-worktree && -- gitgitgadget