File: describe.scm

package info (click to toggle)
guile-git 0.9.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 892 kB
  • sloc: lisp: 6,231; makefile: 132; sh: 8
file content (156 lines) | stat: -rw-r--r-- 6,136 bytes parent folder | download
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
;;; Guile-Git --- GNU Guile bindings of libgit2
;;; Copyright © 2019, 2021 Marius Bakke <marius@gnu.org>
;;;
;;; This file is part of Guile-Git.
;;;
;;; Guile-Git 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.
;;;
;;; Guile-Git 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 Guile-Git.  If not, see <http://www.gnu.org/licenses/>.

(define-module (tests describe)
  #:use-module (srfi srfi-64)
  #:use-module (srfi srfi-71))

(use-modules (tests helpers))
(use-modules (git))

(test-begin "describe")

(libgit2-init!)

(with-repository "simple" directory

  ;; Create an annotated tag for the second commit.
  (test-assert "create annotated tag"
    (let* ((repository (repository-open directory))
           (name "0.1")
           (target (revparse-single repository "HEAD^"))
           (tagger (signature-now "Test Describe" "test@localhost"))
           (message "This tag is annotated!"))
      (oid->string (tag-create repository name
                               target tagger message))))

  (test-equal "describe HEAD with default options"
    "0.1-1-g3f848a1"
    (let* ((repository (repository-open directory))
           (oid (reference-target (repository-head repository)))
           (commit (commit-lookup repository oid)))
      (describe-format (describe-commit commit))))

  (test-equal "describe workdir with default options"
    "0.1-1-g3f848a1"
    (let* ((repository (repository-open directory)))
      (describe-format (describe-workdir repository))))

  ;; Create an un-annotated tag for the last commit.
  (test-equal "create lightweight tag"
    "3f848a1a52416ac99a5c5bf2e6bd55eb7b99d55b"
    (let* ((repository (repository-open directory))
           (name "0.2-rc1")
           (target (revparse-single repository "HEAD")))
      (oid->string (tag-create-lightweight repository name target))))

  (test-equal "describe HEAD, strategy tags"
    "0.2-rc1"
    (let* ((repository (repository-open directory))
           (oid (reference-target (repository-head repository)))
           (commit (commit-lookup repository oid))
           (options (make-describe-options #:strategy 'tags)))
      (describe-format (describe-commit commit options))))

  (test-equal "describe workdir, strategy and pattern"
    "0.1-1-g3f848a1"
    (let ((repository (repository-open directory))
          (options (make-describe-options #:strategy 'all
                                          #:pattern "0.1")))
    (describe-format (describe-workdir repository options))))

  (test-equal "describe workdir, invalid strategy"
    #f
    (let* ((repository (repository-open directory))
           (oid (reference-target (repository-head repository)))
           (commit (commit-lookup repository oid))
           (options (make-describe-options
                     #:strategy 'foo)))
      (describe-format (describe-commit commit options))))

  (test-equal "describe HEAD^, default options"
    "0.1"
    (let* ((repository (repository-open directory))
           (oid (reference-target (repository-head repository)))
           (head (commit-lookup repository oid))
           (head^ (commit-parent head)))
      (describe-format (describe-commit head^))))

  (test-equal "describe HEAD^, long format"
    "0.1-0-gb70d891"
    (let* ((repository (repository-open directory))
           (oid (reference-target (repository-head repository)))
           (head (commit-lookup repository oid))
           (head^ (commit-parent head))
           (format-options (make-describe-format-options
                            #:always-use-long-format? #t)))
      (describe-format (describe-commit head^) format-options)))

  (test-equal "describe HEAD, max-candidates"
    (list GIT_ENOTFOUND GITERR_DESCRIBE)
    (let* ((repository (repository-open directory))
           (oid (reference-target (repository-head repository)))
           (commit (commit-lookup repository oid))
           (options (make-describe-options
                     #:max-candidates 0)))
      (catch 'git-error
        (lambda ()
          (clear-git-error!)
          (describe-format (describe-commit commit options)))
        (lambda (key err)
          (list (git-error-code err) (git-error-class err))))))

  (test-equal "describe the root commit, fallback and size"
    "354bc"
    (let* ((repository (repository-open directory))
           (oid (reference-target (repository-head repository)))
           (head (commit-lookup repository oid))
           (head^ (commit-parent head))
           (root (commit-parent head^))
           (options (make-describe-options #:fallback-to-oid? #t))
           (format-options (make-describe-format-options
                            #:abbreviated-size 5)))
      (describe-format (describe-commit root options) format-options)))

  ;; ;; Modify a tracked file.
  (call-with-output-file (string-append directory "/" "README")
    (lambda (port)
      (format port "Hello, World?\n")))

  (test-equal "describe workdir, dirty suffix"
    "0.1-1-g3f848a1-dirty"
    (let* ((repository (repository-open directory))
           (format-options (make-describe-format-options
                            #:dirty-suffix "-dirty")))
      (describe-format (describe-workdir repository) format-options)))

  (test-equal "describe-checkout"
    '("3f848a1a52416ac99a5c5bf2e6bd55eb7b99d55b" "0.2-rc1")
    (let ((commit pretty (describe-checkout directory)))
      (list commit pretty)))

  (test-equal "describe-checkout, default options"
    '("3f848a1a52416ac99a5c5bf2e6bd55eb7b99d55b" "0.1-1-g3f848a1")
    (let ((commit pretty (describe-checkout directory (make-describe-options))))
      (list commit pretty)))

  )

(libgit2-shutdown!)

(test-end)