import-git.scm 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-import-git)
  19. #:use-module (git)
  20. #:use-module (guix git)
  21. #:use-module (guix tests)
  22. #:use-module (guix packages)
  23. #:use-module (guix import git)
  24. #:use-module (guix git-download)
  25. #:use-module (guix tests git)
  26. #:use-module (guix build utils)
  27. #:use-module (srfi srfi-1)
  28. #:use-module (srfi srfi-64))
  29. ;; Test the (guix import git) tools.
  30. (test-begin "git")
  31. (define* (make-package directory version #:optional (properties '()))
  32. (dummy-package "test-package"
  33. (version version)
  34. (properties properties)
  35. (source
  36. (origin
  37. (method git-fetch)
  38. (uri (git-reference
  39. (url (string-append "file://" directory))
  40. (commit version)))
  41. (sha256
  42. (base32
  43. "0000000000000000000000000000000000000000000000000000"))))))
  44. (unless (which (git-command)) (test-skip 1))
  45. (test-equal "latest-git-tag-version: no custom prefix, suffix, and delimiter"
  46. "1.0.1"
  47. (with-temporary-git-repository directory
  48. '((add "a.txt" "A")
  49. (commit "First commit")
  50. (tag "1.0.1" "Release 1.0.1"))
  51. (let ((package (make-package directory "1.0.0")))
  52. (latest-git-tag-version package))))
  53. (unless (which (git-command)) (test-skip 1))
  54. (test-equal "latest-git-tag-version: custom prefix, no suffix and delimiter"
  55. "1.0.1"
  56. (with-temporary-git-repository directory
  57. '((add "a.txt" "A")
  58. (commit "First commit")
  59. (tag "prefix-1.0.1" "Release 1.0.1"))
  60. (let ((package (make-package directory "1.0.0"
  61. '((release-tag-prefix . "prefix-")))))
  62. (latest-git-tag-version package))))
  63. (unless (which (git-command)) (test-skip 1))
  64. (test-equal "latest-git-tag-version: custom suffix, no prefix and delimiter"
  65. "1.0.1"
  66. (with-temporary-git-repository directory
  67. '((add "a.txt" "A")
  68. (commit "First commit")
  69. (tag "1.0.1-suffix-123" "Release 1.0.1"))
  70. (let ((package (make-package directory "1.0.0"
  71. '((release-tag-suffix . "-suffix-[0-9]*")))))
  72. (latest-git-tag-version package))))
  73. (unless (which (git-command)) (test-skip 1))
  74. (test-equal "latest-git-tag-version: custom delimiter, no prefix and suffix"
  75. "2021.09.07"
  76. (with-temporary-git-repository directory
  77. '((add "a.txt" "A")
  78. (commit "First commit")
  79. (tag "2021-09-07" "Release 2021-09-07"))
  80. (let ((package (make-package directory "2021-09-06"
  81. '((release-tag-version-delimiter . "-")))))
  82. (latest-git-tag-version package))))
  83. (unless (which (git-command)) (test-skip 1))
  84. (test-equal "latest-git-tag-version: empty delimiter, no prefix and suffix"
  85. "20210907"
  86. (with-temporary-git-repository directory
  87. '((add "a.txt" "A")
  88. (commit "First commit")
  89. (tag "20210907" "Release 20210907"))
  90. (let ((package (make-package directory "20210906"
  91. '((release-tag-version-delimiter . "")))))
  92. (latest-git-tag-version package))))
  93. (unless (which (git-command)) (test-skip 1))
  94. (test-equal "latest-git-tag-version: custom prefix and suffix, no delimiter"
  95. "2.0.0"
  96. (with-temporary-git-repository directory
  97. '((add "a.txt" "A")
  98. (commit "First commit")
  99. (tag "Release-2.0.0suffix-1" "Release 2.0.0"))
  100. (let ((package (make-package directory "1.0.0"
  101. '((release-tag-prefix . "Release-")
  102. (release-tag-suffix . "suffix-[0-9]")))))
  103. (latest-git-tag-version package))))
  104. (unless (which (git-command)) (test-skip 1))
  105. (test-equal "latest-git-tag-version: custom prefix, suffix, and delimiter"
  106. "2.0.0"
  107. (with-temporary-git-repository directory
  108. '((add "a.txt" "A")
  109. (commit "First commit")
  110. (tag "Release-2_0_0suffix-1" "Release 2.0.0"))
  111. (let ((package (make-package directory "1.0.0"
  112. '((release-tag-prefix . "Release-")
  113. (release-tag-suffix . "suffix-[0-9]")
  114. (release-tag-version-delimiter . "_")))))
  115. (latest-git-tag-version package))))
  116. (unless (which (git-command)) (test-skip 1))
  117. (test-equal "latest-git-tag-version: only pre-releases available"
  118. #f
  119. (with-temporary-git-repository directory
  120. '((add "a.txt" "A")
  121. (commit "First commit")
  122. (tag "2.0.0-rc1" "Release candidate for 2.0.0"))
  123. (let ((package (make-package directory "1.0.0")))
  124. (latest-git-tag-version package))))
  125. (unless (which (git-command)) (test-skip 1))
  126. (test-equal "latest-git-tag-version: accept pre-releases"
  127. "2.0.0-rc1"
  128. (with-temporary-git-repository directory
  129. '((add "a.txt" "A")
  130. (commit "First commit")
  131. (tag "2.0.0-rc1" "Release candidate for 2.0.0"))
  132. (let ((package (make-package directory "1.0.0"
  133. '((accept-pre-releases? . #t)))))
  134. (latest-git-tag-version package))))
  135. (unless (which (git-command)) (test-skip 1))
  136. (test-equal "latest-git-tag-version: accept pre-releases, and custom prefix"
  137. "2.0.0-rc1"
  138. (with-temporary-git-repository directory
  139. '((add "a.txt" "A")
  140. (commit "First commit")
  141. (tag "version-2.0.0-rc1" "Release candidate for 2.0.0"))
  142. (let ((package (make-package directory "1.0.0"
  143. '((accept-pre-releases? . #t)
  144. (release-tag-prefix . "version-")))))
  145. (latest-git-tag-version package))))
  146. (unless (which (git-command)) (test-skip 1))
  147. (test-equal "latest-git-tag-version: accept pre-releases, and custom suffix"
  148. "2.0.0-rc1"
  149. (with-temporary-git-repository directory
  150. '((add "a.txt" "A")
  151. (commit "First commit")
  152. (tag "2.0.0-rc1-suffix" "Release candidate for 2.0.0"))
  153. (let ((package (make-package directory "1.0.0"
  154. '((accept-pre-releases? . #t)
  155. (release-tag-suffix . "-suffix")))))
  156. (latest-git-tag-version package))))
  157. (unless (which (git-command)) (test-skip 1))
  158. (test-equal "latest-git-tag-version: accept pre-releases, delimiter conflicts with pre-release part"
  159. "2.0.0_alpha"
  160. (with-temporary-git-repository directory
  161. '((add "a.txt" "A")
  162. (commit "First commit")
  163. (tag "2_0_0_alpha" "Alpha release for 2.0.0"))
  164. (let ((package (make-package directory "1.0.0"
  165. '((accept-pre-releases? . #t)
  166. (release-tag-version-delimiter . "_")))))
  167. (latest-git-tag-version package))))
  168. (unless (which (git-command)) (test-skip 1))
  169. (test-equal "latest-git-tag-version: accept pre-releases, and custom suffix and prefix"
  170. "2.0.0-alpha"
  171. (with-temporary-git-repository directory
  172. '((add "a.txt" "A")
  173. (commit "First commit")
  174. (tag "prefix123-2.0.0-alpha-suffix" "Alpha release for 2.0.0"))
  175. (let ((package (make-package directory "1.0.0"
  176. '((accept-pre-releases? . #t)
  177. (release-tag-prefix . "prefix[0-9]{3}-")
  178. (release-tag-suffix . "-suffix")))))
  179. (latest-git-tag-version package))))
  180. (unless (which (git-command)) (test-skip 1))
  181. (test-equal "latest-git-tag-version: accept pre-releases, and custom suffix, prefix, and delimiter"
  182. "2.0.0-alpha"
  183. (with-temporary-git-repository directory
  184. '((add "a.txt" "A")
  185. (commit "First commit")
  186. (tag "prefix123-2-0-0-alpha-suffix" "Alpha release for 2.0.0"))
  187. (let ((package (make-package directory "1.0.0"
  188. '((accept-pre-releases? . #t)
  189. (release-tag-prefix . "prefix[0-9]{3}-")
  190. (release-tag-suffix . "-suffix")
  191. (release-tag-version-delimiter . "-")))))
  192. (latest-git-tag-version package))))
  193. (unless (which (git-command)) (test-skip 1))
  194. (test-equal "latest-git-tag-version: accept pre-releases, no delimiter, and custom suffix, prefix"
  195. "2alpha"
  196. (with-temporary-git-repository directory
  197. '((add "a.txt" "A")
  198. (commit "First commit")
  199. (tag "prefix123-2alpha-suffix" "Alpha release for version 2"))
  200. (let ((package (make-package directory "1.0.0"
  201. '((accept-pre-releases? . #t)
  202. (release-tag-prefix . "prefix[0-9]{3}-")
  203. (release-tag-suffix . "-suffix")
  204. (release-tag-version-delimiter . "")))))
  205. (latest-git-tag-version package))))
  206. (unless (which (git-command)) (test-skip 1))
  207. (test-equal "latest-git-tag-version: no tags found"
  208. #f
  209. (with-temporary-git-repository directory
  210. '((add "a.txt" "A")
  211. (commit "First commit"))
  212. (let ((package (make-package directory "1.0.0")))
  213. (latest-git-tag-version package))))
  214. (unless (which (git-command)) (test-skip 1))
  215. (test-equal "latest-git-tag-version: no valid tags found"
  216. #f
  217. (with-temporary-git-repository directory
  218. '((add "a.txt" "A")
  219. (commit "First commit")
  220. (tag "Test" "Test tag"))
  221. (let ((package (make-package directory "1.0.0")))
  222. (latest-git-tag-version package))))
  223. (test-end "git")