From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id A5D7C1FA02 for ; Thu, 6 Aug 2020 06:02:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728118AbgHFGBz (ORCPT ); Thu, 6 Aug 2020 02:01:55 -0400 Received: from out0.migadu.com ([94.23.1.103]:34842 "EHLO out0.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728079AbgHFGBx (ORCPT ); Thu, 6 Aug 2020 02:01:53 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ameretat.dev; s=default; t=1596693712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nukpke5y28ILOWZ5GLqVB9hTaMKKcPJO23ZATCLcsYU=; b=MsrbKUtBQey0hpPP7XynRB5AMxLMbV9gUoOcTEDsGKRQ4+UK18z70F43faLgeR56jPP0nK 0n7XA2tI58fQ6wQT010HH0DiDF9VjutaAxG70KZl05O1T+LefUrD08E6uGO+D3kO8C1Pvj xV9AIqul7wUYElyvEeya/sV+JRVWSE8= From: "Raymond E. Pasco" To: git@vger.kernel.org Cc: Junio C Hamano , "Raymond E. Pasco" Subject: [PATCH v4 2/3] apply: make i-t-a entries never match worktree Date: Thu, 6 Aug 2020 02:01:18 -0400 Message-Id: <20200806060119.74587-3-ray@ameretat.dev> In-Reply-To: <20200806060119.74587-1-ray@ameretat.dev> References: <20200806060119.74587-1-ray@ameretat.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org By definition, an intent-to-add index entry can never match the worktree, because worktrees have no concept of intent-to-add entries. Therefore, "apply --index" should always fail on intent-to-add paths. Because check_preimage() calls verify_index_match(), it already fails for patches other than creation patches, which check_preimage() ignores. This patch adds a check to check_preimage()'s rough equivalent for creation patches, check_to_create(). Helped-by: Junio C Hamano Signed-off-by: Raymond E. Pasco --- apply.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apply.c b/apply.c index 4cba4ce71a..6328591489 100644 --- a/apply.c +++ b/apply.c @@ -3754,6 +3754,21 @@ static int check_to_create(struct apply_state *state, return EXISTS_IN_INDEX; } + /* If the new path to be added has an intent-to-add entry, then + * by definition it does not match what is in the work tree. So + * "apply --index" should always fail in this case. Patches other + * than creation patches are already held to this standard by + * check_preimage() calling verify_index_match(). + */ + if (state->check_index && !state->cached) { + int pos = index_name_pos(state->repo->index, new_name, + strlen(new_name)); + if (pos >= 0 && + state->repo->index->cache[pos]->ce_flags & CE_INTENT_TO_ADD) + return error(_("%s: does not match index"), new_name); + } + + if (state->cached) return 0; -- 2.28.0.2.g72bf77540a.dirty