Article View: linux.kernel.git
Article #4205Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees
From: Phillip Wood
Date: Tue, 01 Dec 2026 16:37
Date: Tue, 01 Dec 2026 16:37
59 lines
13690 bytes
13690 bytes
Hi Patrick On 01/12/2026 13:18, Patrick Steinhardt wrote: > > I'm probably missing something, but the way we handle `head_target` > seems weird to me. It is getting resolved to whatever we have checked > out in the current worktree. But do we even care about whether the > currently checked out branch is used anywhere else? It's confusing if HEAD gets updated in one worktree because a branch was rewritten in a different worktree. That's why we have checks in "git rebase" to avoid rewriting branches that are checked out in other worktrees. > What I would have expected us to do is that we take the list of pending > ref updates that we compute in `handle_reference_updates()` and verify > that none of those refs that we're updating is checked out or being > rebased/bisected. But as far as I can see, this check here comes before > we have even computed those ref updates in the first place. We need to do the check before rewriting so that a user running "git history reword" does not spend time editing the commit message, only for us to refuse to update any refs. > So we're verifying the pre-rewrite state, not the state after already > having performed the history rewrite where the ref updates are now > pending. And consequently, I think we don't reject some updates that may > happen in worktrees. Ideally we'd find all the branches that we want to rewrite, write those to "$GIT_DIR/history/ref-updates", then walk all the other worktrees checking which branch is checked out, being rebased etc. and read each worktree's "$GIT_DIR/history/ref-updates" to see if there is an active "git history" command rewriting the same branch. If a branch that we want to rewrite is being rewritten by a command running in another worktree we'd remove "$GIT_DIR/history/ref-updates" and error out. "git checkout", "git rebase" etc. would also check "$GIT_DIR/history/ref-updates" as well. By writing the list of refs we want to update before checking if any other worktree is updating them and removing the file after we've rewritten them, I think we avoid races where two commands started at the same time try and update the same branch. I don't think we necessarily need to implement that all at once though, the checks added in this patch are a good first step. Thanks Phillip > But even if we detected all of them, we would now be racy as we should > perform the validation at the point in time where we have already > gathered expected old and new commit IDs for the ref updates, shouldn't > we? > > I may be missing something very obvious, but I think as-is these checks > are somewhat broken? > > Thanks! > > Patrick
Technical Details
Message-ID:
<3d2e9653-87ce-48f4-a154-2b5a1a31a84c@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76801-linux-kernel-git=dewy.ruReferences:
<20261123103911.98860-1-aniketgupta3001@gmail.com> <20261127173252.7794-1-aniketgupta3001@gmail.com> <aw7I-t56lb5S1Z49@pks.im>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76801-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2] history: refuse to rewrite branches used by other
worktrees
Date: Tue, 1 Dec 2026 16:37:37 +0000
Organization: Usenet Network
Message-ID: <3d2e9653-87ce-48f4-a154-2b5a1a31a84c@gmail.com>
References: <20261123103911.98860-1-aniketgupta3001@gmail.com>
<20261127173252.7794-1-aniketgupta3001@gmail.com> <aw7I-t56lb5S1Z49@pks.im>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="1766582"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:F4Jzo4VvM5NkeAfUMiUuAhNmAI8= sha256:RF68WBpgJ+bbbU2c9OukhYPje1Oru5R7gkK2kG3p6Pc=
sha1:d9/hClP+F4AKcOUc3YnaA9cISDg= sha256:fV00WX9r8Z4dVo0aDpUyA+OwHjoL7Qzf2Kqq8RxGE8o=
Content-Language: en-US
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 9E0E1117416; Tue, 1 Dec 2026 19:37:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id Lf3zghT9Deaq;
Tue, 1 Dec 2026 19:37:54 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76801-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 7677D117413; Tue, 1 Dec 2026 19:37:46 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 9127228F2C; Tue, 1 Dec 2026 16:37:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796143062;
b=nQrl/hhnvDdhrghjqNbwIaxD5NgSgdHp2hOUJpgsF1IRrP5lo6bIiRN1SE6jigNFrgRX
7O8Lk5ryglOX+9/RzfiwOuFXullKDxh8CBQwFH7N04iLAKWrb+j0/BX4odf0yroSa8jjD
AhD4/fpzwI3xT4dMG/iqoLenEUU3HF97eOXxdVOnwJsI+cZ+xwjKyw0F6NevHDyI+bnD/
CwrcQYdwLhq3JaSwqFkaA79hKkiAoQJW3Nnk6wPtGFqyrI3E10bwbsjitEqrdOqConA0c
k3P6K+5Ris/3N96x8zLOCFWVr+Hwn4xmQPBo9Trfl7YGpKBRr48mhV6fJbnIkmrwafA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796143062;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:Message-ID:Date:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
User-Agent:From:Reply-To:Subject:To:Cc:References:Content-Language:
In-Reply-To:Content-Type:Content-Transfer-Encoding;
bh=XAoMeRl62ZhJR1Q1n2YdjuK4i/U4c0fFm587kkVLhlY=;
b=eS82lDvsRs7JDcSQj2nIqa3srZ5nYOk0e3JYICrVCRqIXy6HSiygL1M5Ve+G9DQEAfKP
zF8wBkrxn5bHBJJWKECSFK4179lb1tAFhGXPpL2yfHiP46eD+bAhxX8LIKOfJbVEL2sIa
KiWdJUrbpCTXIUoTHFId1DliB0nI5RlXSsJjdJg1pezGmghZ0LOp40XBbz8aTZoaNIh/h
iq+pMD8mgILAIMrjCGLuiZJwAJQWFBV95qVpslsmd7t6LaZSzEs9MJokeCfat0UxTgsy2
mW9qRUgALCz3qGtJHciHljJXbZw3i7qxquwoYpx5+LoWb6x4iXmiv6h2RVtuyKxPkVA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TIoIZGoR;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id E8FE3606A325;
Tue, 1 Dec 2026 16:37:41 +0000 (UTC)
X-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=TIoIZGoR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.46
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796143061;
b=iekx5JmmCoogXNUqgpAA+qK0WuLf5cV/tHHMAYlC4dt2nmT7+DDNT1sr8Jev/rrpzvMf
uDvSPneRtFoGsvTztandQ6eO56EbTgRIYDewzi7u+wN0lkFEcKuoAhX58vSgv315918Dz
QjmTzXgSLJcdwlbao+zLW1WyJS7M3mYHeFeMuK7qOyy9vrbzy0CNaG4GyqgshgiXPs1Fa
RV1uJ4amGAc578V/Cnq/V3RJ5CaPF89QHvO+20hRcACiLs2sefqpLwch0NT5FNPcZBH1C
owHvRcyexwwNLnbYGvWdpAFgGi8Q8qoEWb5acjSf/Kj3lOcYI2BIGVV9q3BIr9B0WYg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796143061;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-ID:Date:
MIME-Version:User-Agent:From:Reply-To:Subject:To:Cc:References:
Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding;
bh=XAoMeRl62ZhJR1Q1n2YdjuK4i/U4c0fFm587kkVLhlY=;
b=xK1qj2bo0fl2VYKmyqEH48hpL3HLahiqj+Mb5Ox+6gRJT9UUyESkscIlbQ+VL5kSk67l
U/TLTTc1AUUjD49S2NXkSICHVzHooVtYMOiM8f3lEnVtbiry5dJ1VwI34hSmyEkJ0j2QT
3ZrC2ngD4m4oJI6sIC2EDs5shvcD2V0ZyK6+L5CMZgyf1LX88XfHPZ8uA+CkUv6rdml0t
LJPBv1850dMLWaRMKorunb30eFaIchrwdsAsL4Aal9VD1JUxfCfwbCZW5d4HBP4E9kMJz
838IyIlaFAylLlfNMQ++9YkkCiOc/xmi7jPAyFoq5jqArz9lBSgEwoHArmEq0LiccSA==
X-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=TIoIZGoR;
arc=none smtp.remote-ip=209.85.221.46
X-Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46])
(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 BA4C7606A322
for <git@vger.kernel.org>; Tue, 1 Dec 2026 16:37:40 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA4C7606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-48dee593f18so11465591f8f.3
for <git@vger.kernel.org>; Tue, 01 Dec 2026 08:37:40 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796143059; x=1796747859; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:in-reply-to:content-language
:references:cc:to:subject:reply-to:from:user-agent:mime-version:date
:message-id:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=XAoMeRl62ZhJR1Q1n2YdjuK4i/U4c0fFm587kkVLhlY=;
b=TIoIZGoRkzgKXvZWF8a1EvyIcME1LIfTzRUyDbaVK4VB/bhOsdBwUBcNFcbrFwm/TF
a/ueTayg3+rdpy6OHKRGbtyY9NUfqQpgAK4kHSCm8JhT4KRvWxT9u2+6TQ1tBb7lFuHa
X8a4fa21AWUXsc9eD4/ruPIueBq2Gw8MZXA2ZC1oRxxgufpb3aVa1v1JI3JCWIVgu6Pw
nFTf4jNHklq3OOvbh6ijupkObOJgHiMih55Gj1TEBn8QmW3b/W6M+rM/qnHSci3Lsfh4
3Ck9iSoUpNeRmFb24amuCdYWlFsUD7VPnjoJoFJt1bdQyGf2mSmmkcSoko5tGsMHUrhx
/MNg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796143059; x=1796747859;
h=content-transfer-encoding:content-type:in-reply-to:content-language
:references:cc:to:subject:reply-to:from:user-agent:mime-version:date
:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=XAoMeRl62ZhJR1Q1n2YdjuK4i/U4c0fFm587kkVLhlY=;
b=0/qk0VX2OVXn1DlAC//Irwdw/NtO9ZLlpWCr6nrlurcjc1bZLS1BgfEX5PGT7MMhvF
EvbGhdbvPKu34NFQrxNg6kgnE1qBQzzFYCmNOnGEmVIhtVF8/Jnukb4bglmHwGF/3RJb
LVSqIhAzBFm5+9J+XtF0bizkDAOmxcVMO4D9KpC4my7qwfu4VTgfu2GaLctYVH9mWQWN
77B/fdU5sutVI8U6rz/kWYTTV0koYY96x0L4KGg20uKLZ+QS9p3MgzP7NCI20k5yBLmY
WwGZnsuogq+3OBzwwKPmN/+qSh/f7gbBzg6ApuH/8Cb4xapXaKTIQwJmKgHWPsHBD1s9
674Q==
X-Gm-Message-State: APuU4Z+Vk3aTx7FsB00xb5SkqweabYiY1TqZND70wv5XWnFUi5LlG2U9
ViWg8Mqjo7+YLsnSWio6ISxwbnNU7aDtsfQcEg2/jWDaGfNiElTg1Wpk
X-Gm-Gg: AZFdTZco7HXheWU0M+Fdm6DlTudWeyiBwOKCvABLGEM1ssQMFqSZPUsLukKMT7W8/xv
Rh5WttXcNkCpW53gcTlBhstuH37FhhC8NITHkF1JZjXZ4lSAF6Z0aqsr130X4RQUVVV7udfcG8V
3fid/Vn7iPuKb46NPeYzczkdL0yv39sdIx1eHdmFDgP0JCXstJlQd4rhPwpwXNnAQtQgaoVOCYz
41K69u4crFdDhgl3KvT9Ri1GEfrplseFNqyepFVcCMHtBkahyEpiD5grhEWOH37UjUBOLKHAxMs
oHOzvha7k1UQyWNGH4k2nxdVM2xhRqynMy4zp7dEklaRbE2X8bxVtijn7OMBA4pCbGuXdrSRIza
PUVRWsMf92UEQuduUQzObsmcStOl8Ft3Gsx0/QCxrnRJs1U0hXKFbkxBn42ts/ZqGxH0dc12Ze0
TViW38UJZamJoWv15vQPOUKNXSIBxNyElrQ2/eGYfWOhsfLKSru3Bl/FIkA4oOp5Latj+1TQKeR
KmD54FS84VPYuMjUQT2yjXMbol/JUwDwH1a9xALnSRz92aPjrOF/0D/GrW6k9cKSbAHerkcn3N3
aLRToPs83UrZgENSTB012bpPL8RzMC0OTaLlM46G8fTZ54BY6PeB8iyiDxiX2lX7kTmdkKk/CXt
zJI3PnIg=
X-Received: by 2002:a05:600c:64c8:b0:4bb:6848:d433 with SMTP id 5b1f17b1804b1-4bb8881d141mr711852815e9.26.1796143058841;
Tue, 01 Dec 2026 08:37:38 -0800 (PST)
X-Received: from ?IPV6:2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f? ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f])
by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb906d6a13sm624617125e9.3.2026.12.01.08.37.37
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Tue, 01 Dec 2026 08:37:38 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Reply-To: phillip.wood@dunelm.org.uk
X-Cc: git@vger.kernel.org, Toon Claes <toon@iotcl.com>,
Junio C Hamano <gitster@pobox.com>, Nikita Bobko <nikita@nbobko.com>
X-In-Reply-To: <aw7I-t56lb5S1Z49@pks.im>