From unknown Sat Aug 16 18:37:59 2025 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-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) 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 Subject: bug#71900: closed (Re: [bug#71900] [PATCH] git: Remove untracked files from cached checkouts.) Message-ID: References: <875xt2vgsc.fsf@gnu.org> <384ad3938ada52672969a2d8563d132c34e9dd01.1719925366.git.ludo@gnu.org> X-Gnu-PR-Message: they-closed 71900 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 71900@debbugs.gnu.org Date: Thu, 18 Jul 2024 15:53:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1721317982-24753-1" This is a multi-part message in MIME format... ------------=_1721317982-24753-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #71900: [PATCH] git: Remove untracked files from cached checkouts. which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 71900@debbugs.gnu.org. --=20 71900: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D71900 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1721317982-24753-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 71900-done) by debbugs.gnu.org; 18 Jul 2024 15:52:56 +0000 Received: from localhost ([127.0.0.1]:37936 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sUTR9-0006Qu-Hm for submit@debbugs.gnu.org; Thu, 18 Jul 2024 11:52:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sUTR5-0006Qc-0W for 71900-done@debbugs.gnu.org; Thu, 18 Jul 2024 11:52:53 -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 1sUTQs-00086u-Vg; Thu, 18 Jul 2024 11:52:38 -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:References:In-Reply-To:Subject:To: From; bh=R9fcxDtEJJjJ9JoBReUuiLUbOUu7HcBtU+EQg6RGdjs=; b=npDe2FseFfryuueqQVid BqPW4r2Dv+vNUCm/rOdO2ctlNP6Zsy3xzkgYCZwPgcPmaOxk6iR6rvGR7R/lJt5vxQtwSl5lDRFYl Nt24Yz53WvVXynK3wUhPsGMyRNJ0S9SXcSa/ETX/rq2xCZSxYejtTYx+r1QBr3LzvHMEUcoF/4MmP 4ezwrCN7NOSHWLkMJdtlwKYcWK/t8TEdhlpH+Fh7zwWwOpb5b00uCmRUQxp9blZJqFblZNseXv7TT /LTKwW++C2roH5ORcy3kyHgOdenzTBIVWlRVLTkItft/xFqn9ePUhQCnM+dpd1tN1vLyuGxXxybug IivZn7PDpkCpiA==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: 71900-done@debbugs.gnu.org Subject: Re: [bug#71900] [PATCH] git: Remove untracked files from cached checkouts. In-Reply-To: <384ad3938ada52672969a2d8563d132c34e9dd01.1719925366.git.ludo@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22's?= message of "Tue, 2 Jul 2024 15:03:01 +0200") References: <384ad3938ada52672969a2d8563d132c34e9dd01.1719925366.git.ludo@gnu.org> Date: Thu, 18 Jul 2024 17:52:35 +0200 Message-ID: <875xt2vgsc.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 71900-done Cc: Josselin Poiret , Simon Tournier , Mathieu Othacehe , Tobias Geerinckx-Rice , Ricardo Wurmus , Christopher Baines X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Ludovic Court=C3=A8s skribis: > 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 =E2=80=98guix = pull=E2=80=99. > > * 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 Pushed as 58e268c2e30567f415fa4e02086e49299c31406a. ------------=_1721317982-24753-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit 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: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: guix-patches@gnu.org Subject: [PATCH] git: Remove untracked files from cached checkouts. 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 X-Debbugs-Cc: Christopher Baines , Josselin Poiret , Ludovic Courtès , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit Cc: Ricardo Wurmus , =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) 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