🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #1053

Re: [PATCH] sequencer: refuse to revert shallow boundary commits by default

#1053
From: Phillip Wood
Date: Wed, 21 Oct 2026 15:20
120 lines
15643 bytes
Hi Nakul

On 21/10/2026 11:09, Nakul V S via GitGitGadget wrote:
> From: Nakul V S <vsnakul@gmail.com>
> 
> When a repository is cloned with --depth=1, Git records the boundary
> commit in .git/shallow and rewrites its parent links via the graft
> mechanism, making it appear as a root commit. Reverting such a commit
> will therefore delete all tracked files, which is almost always
> unintended by the user.
> 
> Add a check in do_pick_commit() that detects when the target commit is
> a shallow boundary (nr_parent < 0 in the commit graft) and refuses the
> operation by default. A new --allow-shallow-boundary flag is provided
> for the rare cases where the user genuinely intends this behavior.

Thanks for working on this, it is a useful and timely improvement as 
there was some discussion about improving the behavior of git with 
regard to shallow boundaries at the recent git merge conference. I 
wonder if it would be better to refuse to cherry-pick and rebase a 
shallow boundary commit as well. Do you know of a sensible use for 
reverting a shallow boundary or is the new option added out of caution 
in case someone wants it?

> diff --git a/builtin/revert.c b/builtin/revert.c
> index 52100a20cb..f27397fdec 100644
> --- a/builtin/revert.c
> +++ b/builtin/revert.c
> @@ -24,7 +24,7 @@
>    */
>   
>   static const char * const revert_usage[] = {
> -	N_("git revert [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] <commit>..."),
> +	N_("git revert [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] [--allow-shallow-boundary] <commit>..."),

For such a rarely used option I don't think we need to add it to the 
synopsis (we already omit some other options like --rerere-autoupdate)

> diff --git a/sequencer.c b/sequencer.c
> index efbfd1315b..6de59bf6aa 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2366,6 +2367,19 @@ static enum pick_result do_pick_commit(struct repository *r,
>   	}
>   	discard_index(r->index);
>   
> +	if (is_repository_shallow(r)) {
> +		struct commit_graft *graft = lookup_commit_graft(r, &commit->object.oid);
> +		if (graft && graft->nr_parent < 0 && !opts->allow_shallow_boundary) {

It would be good to extract this into a helper function so that we don't 
have to copy the code to detect a shallow boundary each time we need to 
detect one.

Thanks

Phillip

> +			return error(_("%s: commit %s is a shallow boundary commit.\n"
> +				       "Reverting it will remove all tracked files because its\n"
> +				       "true parent history is not present in this clone.\n"
> +				       "Use --allow-shallow-boundary to override, or\n"
> +				       "'git fetch --unshallow' to restore full history first."),
> +				     command_to_string(command),
> +				     oid_to_hex(&commit->object.oid));
> +		}
> +	}
> +
>   	if (!commit->parents)
>   		parent = NULL;
>   	else if (commit->parents->next) {
> diff --git a/sequencer.h b/sequencer.h
> index a5d12a1070..f334bc5357 100644
> --- a/sequencer.h
> +++ b/sequencer.h
> @@ -57,6 +57,7 @@ struct replay_opts {
>   	int committer_date_is_author_date;
>   	int ignore_date;
>   	int commit_use_reference;
> +	int allow_shallow_boundary;
>   
>   	struct strvec trailer_args;
>   
> diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
> index 939e7a16a6..508464004f 100755
> --- a/t/t3501-revert-cherry-pick.sh
> +++ b/t/t3501-revert-cherry-pick.sh
> @@ -256,4 +256,29 @@ test_expect_success 'cherry-pick is unaware of --reference (for now)' '
>   	test_grep "^usage: git cherry-pick" actual
>   '
>   
> +# Tests for shallow boundary safeguard
> +
> +test_expect_success 'setup shallow boundary tests' '
> +	git init src &&
> +	test_commit -C src A &&
> +	test_commit -C src B &&
> +	git clone --no-local --depth=1 src shallow-repo
> +'
> +
> +test_expect_success 'revert of shallow boundary commit is refused by default' '
> +	test_must_fail git -C shallow-repo revert --no-edit HEAD 2>err &&
> +	test_grep "shallow boundary commit" err
> +'
> +
> +test_expect_success 'revert of shallow boundary succeeds with --allow-shallow-boundary' '
> +	git -C shallow-repo revert --no-edit --allow-shallow-boundary HEAD
> +'
> +
> +test_expect_success 'revert in non-shallow repo is unaffected' '
> +	git init non-shallow &&
> +	test_commit -C non-shallow A &&
> +	test_commit -C non-shallow B &&
> +	git -C non-shallow revert --no-edit HEAD
> +'
> +
>   test_done
> 
> base-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926
Technical Details
Message-ID: <7179f371-a709-476f-8e94-807d7b62ce6e@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72736-linux-kernel-git=dewy.ru
References: <pull.2273.git.1792577381142.gitgitgadget@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72736-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH] sequencer: refuse to revert shallow boundary commits by
 default
Date: Wed, 21 Oct 2026 16:20:42 +0100
Organization: Usenet Network
Message-ID: <7179f371-a709-476f-8e94-807d7b62ce6e@gmail.com>
References: <pull.2273.git.1792577381142.gitgitgadget@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="4183334"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:BaUFtHBDEapbwlLN5a837pkCQ6Y= sha256:7SNPqrNTjS6ESsyhYpsVT0pfwyURkzs0H8u90KTO8yY=
	sha1:eEh96+7rVA2sgYRh5DrpO2Icx6U= sha256:HkC6iX7FaJ1FDE1S8S1ozFjdfF8fCO0F1mjRY7pobP8=
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 4410F111057; Wed, 21 Oct 2026 18:35:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 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.25,
	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 gr0c3mqmZx4N;
	Wed, 21 Oct 2026 18:35:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-72736-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id A53BA11102D; Wed, 21 Oct 2026 18:35:34 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 91CAE342C1; Wed, 21 Oct 2026 15:20:53 +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=1792596047;
	b=5a5MFyFGCUpX1Xj1UNLOrU6Rr8kEdQw3okXUAUDdftLb34lEtcNjCCiAiyhZ5lPn444+
	 NtFD1/OYH5IE/o01BsiLixeaOZX+pkQA7rmecQrVEr2VusFq5kqHbGdjxEJkApblwF71u
	 kudgu0vQFJyWFzhuBw5pwyVv6opqLenuKlDiflXfcQulmm8nadpTvg62OecXJyFq3dM+A
	 NEshKquJn73MMl+74dFAnh19QxAf1QMQr64ht29xZHjpZ4Z0il68Hfp6AibIBkH24IdoP
	 JlW8cPS5u4qJuB2rF1MEUihDwhOehIMI/wETrJ8u7MlYCMawnlgCu7v0aehlDJYHA9A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792596047;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted: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:Reply-To:Subject:To:Cc:References:
	 Content-Language:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=QgcWO6RVZtOBLwr9SFHBf/xBjNn4Y8uBfpLoN+O1EZI=;
	b=W+T1fhysKUGKLPYEIwrOMj9Rnm8/b3GoXazqIuMKHH0l6pEMGFekgR642bTC6kMFIVNd
	 fQ15xPFK5/ZFRiQW1KEUh1rokapdgrGKY5R7z9sE2EBiF1s3LLNz4JT72qCgr1lM8jTYW
	 ciHKFP1gZjqjK1NGfw1KIUkEfm0x9oP0XDPS8CuqWFpeoDI70OCBITgzq0lieU2KS4iDI
	 NadZR+GVhqnoWDFdlp4IGDiQVm8vDm5mJpPTM3hn40vhntb3/7WH3CJDSZw/by1jw7vML
	 8LpXz5Gq9QzoXkZRBXBH2j7aTViDjCgaJL3T+VRmXcbT+GpIh0VecJ3KPO0tRlzQEXQ==
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=20251104 header.b=GJoVgaxN;
	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 3EF74606A32E;
	Wed, 21 Oct 2026 15:20:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=GJoVgaxN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792596046;
	b=K1jlmu++Z/R/eyiKJW5JcICQQNfKDQsjjxinolGVLxxCSxhji/2rjiavAbjHrAQqYSmP
	 X/DZnuX4r8fBkHQKUtrQoC3BNEjuO4VGRV19AZMp6OYkK+BZGUbb9+vVIv8Ovc9u6XmH5
	 370mXmfuQt1wMFIV4fPK8ov1mo1kxd1VcYx47IcZV4v/vsUoOYZZDSdo+Xn5qCSxi/7So
	 t9KP2Rar+iG1q8HJ6jDJTtgOUywaEAcnV3kjmX9L4XXzKzoyLVynPtIt0SxVmeSgjyZDD
	 yhWZ1lhn1XC4bNmHGwRkYl56I5IkSAIwOPnzwmzGhfLJ7Yr6odkM3ksX1ouz0Cn41Yw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792596046;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 Message-ID:Date:MIME-Version:User-Agent:Reply-To:Subject:To:Cc:
	 References:Content-Language:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=QgcWO6RVZtOBLwr9SFHBf/xBjNn4Y8uBfpLoN+O1EZI=;
	b=0cebYVJJ4EOY6eDVpUUBRcs4bU/3eB7HKfURiEIuUo/eczpEMmTAsqdn/iP2EcXvxZls
	 DZkUknR50WNGPHf3cuRuxipSDpsR8vYcBPgpIizPDp7NkBs7BPaRBMmaDW8zkwTFCCiHz
	 oUU4ctBAT86la/9ku3JQhRyrcXXomhYfFwq4NXOVVi8QgQqVkCrw9wrlyll0P/8GfVsnn
	 G6H25+9UDAvATPs402ZeS1xxn4QsnZyuU4kXqV+eagusggkSs4YvzauikDu1GE1azjBz3
	 ASVo3sK2UoanEHNsojGH/VLHs/Pu4sVuXdaFytAVCFChateZkzlRIrjPcYFVeuK6Wig==
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=20251104 header.b=GJoVgaxN;
	arc=none smtp.remote-ip=209.85.221.48
X-Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48])
	(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 02B32606A333
	for <git@vger.kernel.org>; Wed, 21 Oct 2026 15:20:45 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 02B32606A333
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-f48.google.com with SMTP id ffacd0b85a97d-48afbd2c386so652871f8f.3
        for <git@vger.kernel.org>; Wed, 21 Oct 2026 08:20:45 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20251104; t=1792596044; x=1793200844; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:in-reply-to:from
         :content-language:references:cc:to:subject:reply-to:user-agent
         :mime-version:date:message-id:from:to:cc:subject:date:message-id
         :reply-to:content-type;
        bh=QgcWO6RVZtOBLwr9SFHBf/xBjNn4Y8uBfpLoN+O1EZI=;
        b=GJoVgaxNTPnomQuvnPZzvd1eF8fjLzpiCOGgTjsI/Xh5nkMyy5eZbfmLCarwGg6FZt
         mhQaAZvraPY/Tw/L7RkC64iIrmXee60zIbBnzWeMptz6Hz2GOjnDj+uiLUJ5fKiizr3q
         6jx6/z7EtC/BcvIq8cw3Uhtp1oTgIKK2zrKFsTR/Jn9XVcjP1UkJePC1JG6rz1PVQPOe
         9fO17OBSZ47prC2fPjvyhIYsB+864tndjNwZ1RxF+xmdjXML82d/ZM7hJrDmpITdWtww
         1ZDmfrR+UNUHok2pMnon1HB6lSE9tBtWSXjCL6uaCHG1rnGio3EHsw8ecR3Jx6pi9rgf
         vTPg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1792596044; x=1793200844;
        h=content-transfer-encoding:content-type:in-reply-to:from
         :content-language:references:cc:to:subject:reply-to: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=QgcWO6RVZtOBLwr9SFHBf/xBjNn4Y8uBfpLoN+O1EZI=;
        b=OGtu/MbuRkSMiS67MuCzPEp8RLw5uFaVyE3P+9XLgLDQlccT5qAro+9UZmaEvjwIPv
         8Bx9qKAoXnrRXNw46wOF4yXQRMmJLoyoCgAEJapEO8sjh12Iqka1rHn5UbbeuUGi6YxF
         wKSpeh8bujTqJZit1Y8kvMxsHJguPRCbr86VQYwClNXITwfOqmvpwXRSnzMcW/6A2Eu9
         LlHUp8rBn8jIHr+/asCcABn2/97BVm/g8BYBHLw9a13iR0STqntMaacx4QIfh5NcSsrD
         fJsrjW7VZ+RlUSpKmQ6nsCAOamfBG4lJytnBym9QCWT2HS+y4LRvPdx37KYQJG3/7it3
         xrzA==
X-Forwarded-Encrypted: i=1; AKwUvBzer1jE6XnYi0C2Y6UfXMb20dFacf2lvaydyFN+mV3GCKNz6Ulljd85cXxSbuGZ3kVdkEw=@vger.kernel.org
X-Gm-Message-State: AFq9FYJZdoT72XNOmyFRULVelDrjEAu7XvM7rSH+2bB730lSCDhoy9q+
	R2/IkyITxxZomgbipAPC4suNP+YzYOIk8VwGob4AqGjWwRU5vk9hZedH
X-Gm-Gg: AYBFou2BvkxK+MF56mkAwLdVWZqMyWdUKdwvATtTNci48RgjakSoOx9B9LfcBr4WhYK
	dJOSl6s6K4N3PGcQK+92agHbCU4z0NJuFVDob88Uq6XEeSFVhiClACQb+miKdWUn2go+j1J+fct
	AGgP7dGkX1wd9oYXJqIMFwCMIrIKboZAKYr637wXQG/KgfBCYZ1VVTvIwmSxWquRA09Hqwu5HrT
	hjax4HXHlyYJ0KSk9SK08VuWdSEeBYO8x+zWep5lW8eA5F7xh/nWxDTSmeqUWCbaK3ZjxcEEfoa
	HJJoEDlg3/mtYqLq/7HXBAaDmvi4KdhaDiW7zUFHwFYI23WNbFjW/4o5zfolDwc9vUk1rVTRld8
	ce/u74YcZOrBsAAe/UdTdDXTxNPeL8AWmhjP4gTgU2umP2Awi8P0ekwAigaGQ6k19yoarEgr7IX
	wrOb9SdGYpAOxCeXMC1K94FjuJaIrfsBHe6urQkAEIbCJ81gPrKZB1G/vCTth/011OO564TvuPz
	oRZm+Wcn0vjvifFytbPP2FHL+4B/ed61g/Zzv4xg74y4T2MJ5188RCxZ1cC/GuLLmH3v0G8F/Uk
	V1uszOSGEqJjuoS6EimoCpFOCu5YAWarJA==
X-Received: by 2002:a05:600c:630e:b0:4a1:9078:911 with SMTP id 5b1f17b1804b1-4a1fdd5d9bbmr49956575e9.31.1792596044007;
        Wed, 21 Oct 2026 08:20:44 -0700 (PDT)
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-4a20230ca3esm24441385e9.15.2026.10.21.08.20.42
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Wed, 21 Oct 2026 08:20:43 -0700 (PDT)
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: Patrick Steinhardt <ps@pks.im>, Junio C Hamano <gitster@pobox.com>,
 Nakul V S <vsnakul@gmail.com>
X-In-Reply-To: <pull.2273.git.1792577381142.gitgitgadget@gmail.com>