unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob d0dc149ff8517d86963cd0b78b918ef079359707 7933 bytes (raw)
name: tests/import-latest-git.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-import-latest-git)
  #:use-module (git)
  #:use-module (guix git)
  #:use-module (guix tests)
  #:use-module (guix packages)
  #:use-module (guix import latest-git)
  #:use-module (guix upstream)
  #:use-module (guix git-download)
  #:use-module (guix hg-download)
  #:use-module (guix tests git)
  #:use-module (guix build utils)
  #:use-module (srfi srfi-64))

(test-begin "git")

(define latest-git-upstream
  (upstream-updater-latest %latest-git-updater))

(define with-latest-git-commit?
  (upstream-updater-predicate %latest-git-updater))

(define* (make-package directory base-version revision commit
                       #:optional (properties
                                   '((with-latest-git-commit . #true))))
  (dummy-package "test-package"
                 (version (git-version base-version revision commit))
                 (source
                  (origin
                    (method git-fetch)
                    (uri (git-reference
                          (url (string-append "file://" directory))
                          (commit commit)))
                    (sha256 #f)))
                 (properties properties)))

(define (find-commit-as-string repository query)
  (oid->string (commit-id (find-commit repository query))))

(unless (which (git-command)) (test-skip 1))
(test-equal "latest-git: an update"
  '(#true #true #true)
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "First commit")
        (add "b.txt" "B")
        (commit "Second commit"))
    (with-repository directory repository
      (let* ((old-commit
              (find-commit-as-string repository "First commit"))
             (new-commit
              (find-commit-as-string repository "Second commit"))
             (package (make-package directory "1.0" "0" old-commit))
             (update (latest-git-upstream package)))
        (list (with-latest-git-commit? package)
              (string=? (upstream-source-version update)
                        (git-version "1.0" "1" new-commit))
              ;; See 'oid->commit in (guix git) for why not string=?.
              (string-prefix?
               (git-reference-commit (upstream-source-urls update))
               new-commit))))))

(unless (which (git-command)) (test-skip 1))
(test-equal "latest-git: no new commit, no new revision"
  '(#true #true #true)
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "First commit"))
    (with-repository directory repository
      (let* ((commit
              (find-commit-as-string repository "First commit"))
             (package (make-package directory "1.0" "0" commit))
             (update (latest-git-upstream package)))
        ;; 'update' being #false would work as well.
        (list (with-latest-git-commit? package)
              (string=? (upstream-source-version update)
                        (package-version package))
              (string-prefix?
               (git-reference-commit (upstream-source-urls update))
               commit))))))

(unless (which (git-command)) (test-skip 1))
(test-equal "latest-git: non-HEAD commits ignored"
  '(#true #true #true)
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "First commit")
        (tag "let-me-be-head")
        (branch "dev")
        (checkout "dev")
        (add "b.txt" "B")
        (commit "Not ready for distribution!")
        (checkout "let-me-be-head"))
    (with-repository directory repository
      (let* ((commit
              (find-commit-as-string repository "First commit"))
             (package (make-package directory "1.0" "0" commit))
             (update (latest-git-upstream package)))
        (list (with-latest-git-commit? package)
              (string=? (upstream-source-version update)
                        (package-version package))
              (string-prefix?
               (git-reference-commit (upstream-source-urls update))
               commit))))))

(unless (which (git-command)) (test-skip 1))
(test-equal "latest-git: non-HEAD branches can be chosen"
  '(#true #true #true)
  (with-temporary-git-repository directory
      '((checkout "stable-for-distros" orphan)
        (add "a.txt" "A")
        (commit "First commit")
        (add "b.txt" "B")
        (commit "Here's a bugfix.")
        (branch "unstable")
        (checkout "unstable")
        (add "c.txt" "C")
        ;; This commit may not be chosen.
        (commit "New feature, needs more work before distributing."))
    (with-repository directory repository
      (let* ((old-commit
              (find-commit-as-string repository "First commit"))
             (new-commit
              (find-commit-as-string repository "Here's a bugfix"))
             (properties
              '((with-latest-git-commit . "refs/heads/stable-for-distros")))
             (package (make-package directory "1.0" "0" old-commit properties))
             (update (latest-git-upstream package)))
        (list (with-latest-git-commit? package)
              (string=? (upstream-source-version update)
                        (git-version "1.0" "1" new-commit))
              (string-prefix?
               (git-reference-commit (upstream-source-urls update))
               new-commit))))))

(unless (which (git-command)) (test-skip 1))
(test-equal "latest-git: deleted references handled gracefully"
  #false
  (with-temporary-git-repository directory
      '((add "a.txt" "A")
        (commit "First commit"))
    (with-repository directory repository
      (let* ((properties
              '((with-latest-git-commit . "refs/heads/I-do-not-exist")))
             (package (make-package directory "1.0" "0" "cabba9e" properties)))
        (latest-git-upstream package)))))

(test-equal "with-latest-git-commit?"
  '(#true #false #true #true #false #false)
  (map (lambda (properties)
         (with-latest-git-commit?
          (make-package "/dev/null" "1.0" "0" "cabba9e" properties)))
       (list '((with-latest-git-commit . #true)) ; defaults to HEAD
             '() ; packages have to opt-in, so #false
             '((with-latest-git-commit . "HEAD")) ; explicit HEAD is ok
             '((with-latest-git-commit . "refs/heads/main")) ; another branch
             '((with-latest-git-commit . #xf00ba3)) ; bogus
             '((irrelevant . #true)))))

(test-equal "with-latest-git-commit?: not for other VCS"
  #false
  (with-latest-git-commit?
   (package
     (inherit (make-package "/dev/null" "1.0.0" "0" "cabba9e"))
     (source
      (origin
        (method hg-fetch)
        (uri (hg-reference
              (url "https://foo")
              (changeset "foo")))
        (sha256 #false))))))

(test-equal "with-latest-git-commit?: only if there's source code"
  #false
  (with-latest-git-commit?
   (package
     (inherit (make-package "/dev/null" "1.0.0" "0" "cabba9e"))
     (source #false))))

(test-equal "with-latest-git-commit?: only for git-version"
  #false
  (with-latest-git-commit?
   (package
     (inherit (make-package "/dev/null" "1.0.0" "0" "cabba9e"))
     (version "1.0.0"))))

(test-end "git")

debug log:

solving d0dc149ff8 ...
found d0dc149ff8 in https://yhetil.org/guix-patches/20220109191015.33058-12-maximedevos@telenet.be/

applying [1/1] https://yhetil.org/guix-patches/20220109191015.33058-12-maximedevos@telenet.be/
diff --git a/tests/import-latest-git.scm b/tests/import-latest-git.scm
new file mode 100644
index 0000000000..d0dc149ff8

Checking patch tests/import-latest-git.scm...
Applied patch tests/import-latest-git.scm cleanly.

index at:
100644 d0dc149ff8517d86963cd0b78b918ef079359707	tests/import-latest-git.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).