From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id gC/yIc76g2ZKOgEAe85BDQ:P1 (envelope-from ) for ; Tue, 02 Jul 2024 13:04:14 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id gC/yIc76g2ZKOgEAe85BDQ (envelope-from ) for ; Tue, 02 Jul 2024 15:04:14 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Moci8Lby; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1719925454; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=asBIEPM1WkK9EnTybPnb9gIHHtfSt3VzVNi/HNljn/o=; b=rzLMQSZNIWINKdz8KbL20fdLkB1Dl9cd4hEl88ZxjgtJIIeW5lUZARXBmXcid/Rj0hYyVe PFjYXi3swU5rceuqaD1hFGZj/pOg9EG2IQfZb/6te7rPt+0hex7zDole89uUKKX0YlghTm 5TXQWJfiwXe2uR7gYDhQuCby1/yERdfYTcWQbEv1oDxyEexs1swVKh/UutBbDqQXn4UMiv +cUlw/8j+UKgb4TlwxQ1G6YM9Pu99HgX/QXjDq//2MSPnX3PJFyWQnmquGJjbyIwmX6zrI ttkVIEk6uM7DIX0SECd3ASZZS12jU4hykkiZwFC5dPoI1ki3Dl/+84nJ+NbA7Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1719925454; a=rsa-sha256; cv=none; b=gKzS+W7jHLjQl8NOeDUXYYyXYpYoFf5NtB8LU1ax+3SVJiHljvqfVTjFzI59XA5SCX/hwI 4u081T20EdL9WHEsQ3Q+1WiplKdi1iRQUeYGOk8/o2cA8w2w0pB3CrM66erCs8IdHrKWyJ SdxkA1fmGKmpyQyWDExh3XPtKy67c7aRwLC4sLRjEjIfzc2uvLNz6oOJwccQAhuHxWiN1O aY2lsYckd/2KXU5a185Nk3Kgaa/C8CCKpkpeFw/mxBqFwR694amJlR688NV2aCQVX79S50 rqbvnpEEMf851W56LaAzK/Gy0IunNDKKWrulcY8qZao9ooC9qovtZbmZqhJyjg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Moci8Lby; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2FF0C60FAA for ; Tue, 02 Jul 2024 15:04:14 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOdB0-0000Nt-0B; Tue, 02 Jul 2024 09:04:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOdAy-0000NJ-Ph for guix-patches@gnu.org; Tue, 02 Jul 2024 09:04:04 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOdAy-00074H-94; Tue, 02 Jul 2024 09:04:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sOdAw-0008Lo-40; Tue, 02 Jul 2024 09:04:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71900] [PATCH] git: Remove untracked files from cached checkouts. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 02 Jul 2024 13:04:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71900@debbugs.gnu.org Cc: Ricardo Wurmus , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.171992540232042 (code B ref -1); Tue, 02 Jul 2024 13:04:01 +0000 Received: (at submit) by debbugs.gnu.org; 2 Jul 2024 13:03:22 +0000 Received: from localhost ([127.0.0.1]:36237 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sOdAH-0008Kj-T1 for submit@debbugs.gnu.org; Tue, 02 Jul 2024 09:03:22 -0400 Received: from lists.gnu.org ([209.51.188.17]:40664) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sOdAF-0008Kb-Vo for submit@debbugs.gnu.org; Tue, 02 Jul 2024 09:03:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOdAE-0000Dl-5B for guix-patches@gnu.org; Tue, 02 Jul 2024 09:03:18 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOdAC-0006yL-Je; Tue, 02 Jul 2024 09:03:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=asBIEPM1WkK9EnTybPnb9gIHHtfSt3VzVNi/HNljn/o=; b=Moci8LbyZYsAnb XBRqevkMBPMFLOQk3xwBT9OhU6Uskp/YySu/4/nbI0ZnuBZvk1fP0OooVdpI8YMoHtFqHEz7YeEr1 xTIJvZNDcjkNAhfKvUI/tYZnheRiGLdIDb3fZDqL1FWqtH6fJhJ3YsedawyUQLi2lKuTsjcngUdry OfIKM8+JLjc0f8KXYiKQsr0V1HYE0+/WLyHsNNHnEG+DkJ2FLX27C+6iuDA043MyCcrQlGR5EugG6 WubYU4f2Am4E5CYACKeUIOl8s5EcaIeFB3T6VIHCFGilJyMv0MEeiX2thLkBed9oyYOEwHw+tCf3W d4Sc38ENqwLBGql8ceUA==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 2 Jul 2024 15:03:01 +0200 Message-ID: <384ad3938ada52672969a2d8563d132c34e9dd01.1719925366.git.ludo@gnu.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -1.78 X-Spam-Score: -1.78 X-Migadu-Queue-Id: 2FF0C60FAA X-Migadu-Scanner: mx11.migadu.com X-TUID: qzVexw3S4yIu Cached checkouts could end up with stale untracked files, for example because the checkout was interrupted. As a result, when this happens for the Guix checkout, users would not get substitutes for ‘guix pull’. * guix/git.scm (delete-untracked-files): New procedure. (switch-to-ref): Use it. * tests/git.scm ("update-cached-checkout, untracked files removed"): New test. Co-authored-by: Ricardo Wurmus Change-Id: Iccbe644ade396ad27a037db7e0ef1c2a68ef91ce --- guix/git.scm | 24 ++++++++++++++++++++++++ tests/git.scm | 22 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/guix/git.scm b/guix/git.scm index d75a301f98b..48a962089de 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -298,6 +298,25 @@ (define (resolve-reference repository ref) (('tag . tag) (tag->commit repository tag))))) +(define (delete-untracked-files repository) + "Delete untracked files from the work directory of REPOSITORY." + (let ((workdir (repository-working-directory repository)) + (status (status-list-new repository + (make-status-options + STATUS-SHOW-WORKDIR-ONLY + (logior + STATUS-FLAG-INCLUDE-UNTRACKED + STATUS-FLAG-INCLUDE-IGNORED))))) + (for-each (lambda (entry) + (let ((status (status-entry-status entry))) + (when (or (memq 'wt-new status) + (memq 'ignored status)) + (let* ((diff (status-entry-index-to-workdir entry)) + (new (diff-delta-new-file diff))) + (delete-file-recursively + (in-vicinity workdir (diff-file-path new))))))) + (status-list->status-entries status)))) + (define (switch-to-ref repository ref) "Switch to REPOSITORY's branch, commit or tag specified by REF. Return the OID (roughly the commit hash) corresponding to REF." @@ -305,6 +324,11 @@ (define (switch-to-ref repository ref) (resolve-reference repository ref)) (reset repository obj RESET_HARD) + + ;; There might still be untracked files in REPOSITORY due to an interrupted + ;; checkout for example; delete them. + (delete-untracked-files repository) + (object-id obj)) (define (call-with-repository directory proc) diff --git a/tests/git.scm b/tests/git.scm index ad43435b674..9ccd04f0cdf 100644 --- a/tests/git.scm +++ b/tests/git.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2019, 2020, 2022 Ludovic Courtès +;;; Copyright © 2019-2020, 2022, 2024 Ludovic Courtès ;;; Copyright © 2021 Xinglu Chen