guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

05/08: channels: 'channel-news-entry-commit' correctly resolves annotate


From: guix-commits
Subject: 05/08: channels: 'channel-news-entry-commit' correctly resolves annotated tags.
Date: Sat, 18 Sep 2021 13:43:27 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 778c1fb4eabbb48c05f6c7555c89466d5249ebce
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sat Sep 18 19:32:37 2021 +0200

    channels: 'channel-news-entry-commit' correctly resolves annotated tags.
    
    Previously, 'channel-news-entry-commit' would return the tag ID rather
    than the commit ID when the news entry was referred to via an annotated
    tag.
    
    Reported by Xinglu Chen <public@yoctocell.xyz>.
    
    * guix/channels.scm (resolve-channel-news-entry-tag): Check whether the
    reference points to annotated tag; resolve it if it does.
    * tests/channels.scm ("channel-news, annotated tag"): New test.
---
 guix/channels.scm  |  9 +++++++--
 tests/channels.scm | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/guix/channels.scm b/guix/channels.scm
index 476d62e..e4e0428 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -1089,8 +1089,13 @@ cannot be found."
   (if (channel-news-entry-commit entry)
       entry
       (let* ((tag       (channel-news-entry-tag entry))
-             (reference (string-append "refs/tags/" tag))
-             (oid       (reference-name->oid repository reference)))
+             (reference (reference-lookup repository
+                                          (string-append "refs/tags/" tag)))
+             (target    (reference-target reference))
+             (oid       (let ((obj (object-lookup repository target)))
+                          (if (= OBJ-TAG (object-type obj)) ;annotated tag?
+                              (tag-target-id (tag-lookup repository target))
+                              target))))
         (channel-news-entry (oid->string oid) tag
                             (channel-news-entry-title entry)
                             (channel-news-entry-body entry)))))
diff --git a/tests/channels.scm b/tests/channels.scm
index 0264369..3e82315 100644
--- a/tests/channels.scm
+++ b/tests/channels.scm
@@ -408,6 +408,53 @@
                     '(#f "tag-for-first-news-entry")))))))
 
 (unless (which (git-command)) (test-skip 1))
+(test-assert "channel-news, annotated tag"
+  (with-temporary-git-repository directory
+      `((add ".guix-channel"
+             ,(object->string
+               '(channel (version 0)
+                         (news-file "news.scm"))))
+        (add "src/a.txt" "A")
+        (commit "first commit")
+        (tag "tag-for-first-news-entry"
+             "This is an annotated tag.")
+        (add "news.scm"
+             ,(lambda (repository)
+                (let ((previous
+                       (reference-name->oid repository "HEAD")))
+                  (object->string
+                   `(channel-news
+                     (version 0)
+                     (entry (tag "tag-for-first-news-entry")
+                            (title (en "New file!"))
+                            (body (en "Yeah, a.txt."))))))))
+        (commit "second commit"))
+    (with-repository directory repository
+      (define (find-commit* message)
+        (oid->string (commit-id (find-commit repository message))))
+
+      (let ((channel (channel (url (string-append "file://" directory))
+                              (name 'foo)))
+            (commit1 (find-commit* "first commit"))
+            (commit2 (find-commit* "second commit")))
+        (and (null? (channel-news-for-commit channel commit1))
+             (lset= equal?
+                    (map channel-news-entry-title
+                         (channel-news-for-commit channel commit2))
+                    '((("en" . "New file!"))))
+             (lset= string=?
+                    (map channel-news-entry-tag
+                         (channel-news-for-commit channel commit2))
+                    (list "tag-for-first-news-entry"))
+             ;; This is an annotated tag, but 'channel-news-entry-commit'
+             ;; should give us the commit ID, not the ID of the annotated tag
+             ;; object.
+             (lset= string=?
+                    (map channel-news-entry-commit
+                         (channel-news-for-commit channel commit2))
+                    (list commit1)))))))
+
+(unless (which (git-command)) (test-skip 1))
 (test-assert "latest-channel-instances, missing introduction for 'guix'"
   (with-temporary-git-repository directory
       '((add "a.txt" "A")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]