From patchwork Tue Oct 11 09:52:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 43319 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 0CB0927BBEA; Tue, 11 Oct 2022 10:54:01 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6F13E27BBE9 for ; Tue, 11 Oct 2022 10:54:00 +0100 (BST) Received: from localhost ([::1]:58950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiBxX-0000G2-Fn for patchwork@mira.cbaines.net; Tue, 11 Oct 2022 05:53:59 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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")