From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id ODLyAkE9RWPWRQAAbAwnHQ (envelope-from ) for ; Tue, 11 Oct 2022 11:54:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id kJr6AkE9RWPOdgAAauVa8A (envelope-from ) for ; Tue, 11 Oct 2022 11:54:09 +0200 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 1E45A2ED1A for ; Tue, 11 Oct 2022 11:54:08 +0200 (CEST) Received: from localhost ([::1]:58950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiBxd-0000G2-Ip for larch@yhetil.org; Tue, 11 Oct 2022 05:54:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiBwc-0000ED-PN for guix-patches@gnu.org; Tue, 11 Oct 2022 05:53:09 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiBwc-0004Pk-F5 for guix-patches@gnu.org; Tue, 11 Oct 2022 05:53:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oiBwc-0003B5-AB for guix-patches@gnu.org; Tue, 11 Oct 2022 05:53:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58433] [PATCH 1/2] git: 'update-cached-checkout' returns the commit ID when given a tag. References: <20221011095117.31182-1-ludo@gnu.org> In-Reply-To: <20221011095117.31182-1-ludo@gnu.org> Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 11 Oct 2022 09:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58433 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58433@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 58433-submit@debbugs.gnu.org id=B58433.166548196612187 (code B ref 58433); Tue, 11 Oct 2022 09:53:02 +0000 Received: (at 58433) by debbugs.gnu.org; 11 Oct 2022 09:52:46 +0000 Received: from localhost ([127.0.0.1]:50938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiBwL-0003AU-SQ for submit@debbugs.gnu.org; Tue, 11 Oct 2022 05:52:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55950) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oiBwJ-0003AA-Np for 58433@debbugs.gnu.org; Tue, 11 Oct 2022 05:52:44 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:38638) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiBwE-0004OG-Go; Tue, 11 Oct 2022 05: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:Subject:To:From:in-reply-to: references; bh=TOCdwkx4K3JXDMR3tV9x85hP8HO21P6DQXpx5VQjtlY=; b=Jb+ujAUgV+kPAI tV02JlHZxagLahkN6eVB4JL/jqcHoKfjgVkW+ZOJsvmRxN5rkKaCKuyvwPxPfIwEYpsetDwmIPWld iW6mj0njpyeuYz2Q4/jWZRwMjciN8bsrM54mWOHIE2WjSFWQKTI9rnATJnsvU2KoK6q4Ltap0uwEZ oHpKlJTEn+4RrM8hfDhda8+zx5pkY3sLj568b5BOu4qfpgTH58VxWH4+wj3jwjYb0ci8YHhY3A+8s 32AjawgcTrwngdys51epXhTKaa5U3PAXEoQYLAPqQY1po++oXaMJZhuhMFqVIQRnAKbBvGVhlS1IW z5xT2W16TvvB96in31wQ==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=59686 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oiBwD-0002Tv-O7; Tue, 11 Oct 2022 05:52:38 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 11 Oct 2022 11:52:28 +0200 Message-Id: <20221011095229.31244-1-ludo@gnu.org> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 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" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1665482048; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=TOCdwkx4K3JXDMR3tV9x85hP8HO21P6DQXpx5VQjtlY=; b=stpdFIRLNreUTRXG15r4C8sSF8W2eihduW2vdPOk2NvMRG5MFoX2CBCd/qPo/d6K8gCNRs rdWdmT2LfNPR1Z//1mpM5xlOFsct4C/8Znx0PovvWuqE5/KgRuFqYgAvJmZapEjEauPXWD U9kN1T+c3tFD+RSXB8EV9AYrzV3widx4lZ6zu0n5GavHkmbwPjdgCdr0cvd9R5bcs/GoUG 1M+y/8rZc95e4lfJYithBuo/ekyfmfREOIORzbeGI3LkIOWO/Ynm0NaJwsXIlr35cVgd+z oSBUa+b3T99xOD9gmoDRfvgzGIxEEx/mzUEpbUdJ6oUkbZbuPh9ilsJs6z6o/Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665482048; a=rsa-sha256; cv=none; b=Hzvdw5hD7fxKTifopT/dCK8NXToXd0rEgyIzOpov4KDIRd4yTXFkezweJaKsncoI5z8toP mQJFYoX8dYWpmX9OgLGFIisLXqOaNXDbmJsKzf0j6mtVpiosIUfFvxlXLdX/ziMd8HZhwl rfWwZhz2JrtCAS+JXp1nNb93hkCae1mM0Xq7TQp+VyCdQ1Uxeqr705polAis+YGqfHkjmh XuwZUl0VuwZlD8P8OGbbMTrrl4hFNrhlkEUpEcQzOMp9wZutIGMyRuXlYlPuKFIwkGTbTT tpbOHyhDLmR8mL+zAv90jNBuHoI0wwE4Y5mVLs8X+cV9WOCyelKyR63O4b44tg== 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=Jb+ujAUg; 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" X-Migadu-Spam-Score: -0.80 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Jb+ujAUg; 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" X-Migadu-Queue-Id: 1E45A2ED1A X-Spam-Score: -0.80 X-Migadu-Scanner: scn1.migadu.com X-TUID: o8lZI46i5Bqi Previously, starting with commit efa578ecaece67366b4b0e2266de7c2faaa4ae54, 'update-cached-checkout' would return the OID of the annotated tag the tag points to. With this change it returns the OID of the commit object in all cases. * guix/git.scm (resolve-reference): In the 'tag' case, call 'tag-target-id' and 'tag-lookup' when OID designates an annotated tag. * tests/git.scm ("update-cached-checkout, tag"): New test. --- guix/git.scm | 15 +++++++++------ tests/git.scm | 32 +++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/guix/git.scm b/guix/git.scm index d7fd320f50..0220fe1068 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -271,12 +271,15 @@ (define (resolve-reference repository ref) ;; There's no such tag, so it must be a commit ID. (resolve `(commit . ,str))))))) (('tag . tag) - (let ((oid (reference-name->oid repository - (string-append "refs/tags/" tag)))) - ;; OID may point to a "tag" object, but it can also point directly - ;; to a "commit" object, as surprising as it may seem. Return that - ;; object, whatever that is. - (object-lookup repository oid)))))) + (let* ((oid (reference-name->oid repository + (string-append "refs/tags/" tag))) + (obj (object-lookup repository oid))) + ;; OID may designate an "annotated tag" object or a "commit" object. + ;; Return the commit object in both cases. + (if (= OBJ-TAG (object-type obj)) + (object-lookup repository + (tag-target-id (tag-lookup repository oid))) + obj)))))) (define (switch-to-ref repository ref) "Switch to REPOSITORY's branch, commit or tag specified by REF. Return the diff --git a/tests/git.scm b/tests/git.scm index ca59d2a33e..9c944d65b1 100644 --- a/tests/git.scm +++ b/tests/git.scm @@ -22,8 +22,12 @@ (define-module (test-git) #:use-module (guix git) #:use-module (guix tests git) #:use-module (guix build utils) + #:use-module ((guix utils) #:select (call-with-temporary-directory)) #:use-module (srfi srfi-1) - #:use-module (srfi srfi-64)) + #:use-module (srfi srfi-64) + #:use-module (srfi srfi-71) + #:use-module (ice-9 popen) + #:use-module (ice-9 textual-ports)) ;; Test the (guix git) tools. @@ -239,4 +243,30 @@ (define-module (test-git) (tag "v1.1" "Release 1.1")) (remote-refs directory #:tags? #t))) +(unless (which (git-command)) (test-skip 1)) +(test-assert "update-cached-checkout, tag" + (call-with-temporary-directory + (lambda (cache) + (with-temporary-git-repository directory + '((add "a.txt" "A") + (commit "First commit") + (tag "v1.0" "release-1.0") + (branch "develop") + (checkout "develop") + (add "b.txt" "B") + (commit "Second commit") + (tag "v1.1" "release-1.1")) + (let ((directory commit relation + (update-cached-checkout directory + #:ref '(tag . "v1.1") + #:cache-directory cache)) + (head (let* ((pipe (open-pipe* OPEN_READ (git-command) + "-C" directory + "rev-parse" "HEAD")) + (str (get-string-all pipe))) + (close-pipe pipe) + (string-trim-right str)))) + ;; COMMIT should be the ID of the commit object, not that of the tag. + (string=? commit head)))))) + (test-end "git") -- 2.38.0