gnu: sbcl-hu.dwim.common: Fix missing description.
[jackhill/guix/guix.git] / tests / git.scm
CommitLineData
873f6f13 1;;; GNU Guix --- Functional package management for GNU
c098c11b 2;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org>
873f6f13
LC
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
19(define-module (test-git)
20 #:use-module (git)
21 #:use-module (guix git)
22 #:use-module (guix tests git)
23 #:use-module (guix build utils)
24 #:use-module (srfi srfi-1)
25 #:use-module (srfi srfi-64))
26
27;; Test the (guix git) tools.
28
29(test-begin "git")
30
31;; 'with-temporary-git-repository' relies on the 'git' command.
32(unless (which (git-command)) (test-skip 1))
33(test-assert "commit-difference, linear history"
34 (with-temporary-git-repository directory
35 '((add "a.txt" "A")
36 (commit "first commit")
37 (add "b.txt" "B")
38 (commit "second commit")
39 (add "c.txt" "C")
40 (commit "third commit")
41 (add "d.txt" "D")
42 (commit "fourth commit"))
43 (with-repository directory repository
44 (let ((commit1 (find-commit repository "first"))
45 (commit2 (find-commit repository "second"))
46 (commit3 (find-commit repository "third"))
47 (commit4 (find-commit repository "fourth")))
48 (and (lset= eq? (commit-difference commit4 commit1)
49 (list commit2 commit3 commit4))
50 (lset= eq? (commit-difference commit4 commit2)
51 (list commit3 commit4))
52 (equal? (commit-difference commit3 commit2)
53 (list commit3))
54
55 ;; COMMIT4 is not an ancestor of COMMIT1 so we should get the
56 ;; empty list.
57 (null? (commit-difference commit1 commit4)))))))
58
59(unless (which (git-command)) (test-skip 1))
60(test-assert "commit-difference, fork"
61 (with-temporary-git-repository directory
62 '((add "a.txt" "A")
63 (commit "first commit")
64 (branch "devel")
65 (checkout "devel")
66 (add "devel/1.txt" "1")
67 (commit "first devel commit")
68 (add "devel/2.txt" "2")
69 (commit "second devel commit")
70 (checkout "master")
71 (add "b.txt" "B")
72 (commit "second commit")
73 (add "c.txt" "C")
74 (commit "third commit")
75 (merge "devel" "merge")
76 (add "d.txt" "D")
77 (commit "fourth commit"))
78 (with-repository directory repository
79 (let ((master1 (find-commit repository "first commit"))
80 (master2 (find-commit repository "second commit"))
81 (master3 (find-commit repository "third commit"))
82 (master4 (find-commit repository "fourth commit"))
83 (devel1 (find-commit repository "first devel"))
84 (devel2 (find-commit repository "second devel"))
85 (merge (find-commit repository "merge")))
86 (and (equal? (commit-difference master4 merge)
87 (list master4))
88 (lset= eq? (commit-difference master3 master1)
89 (list master3 master2))
90 (lset= eq? (commit-difference devel2 master1)
91 (list devel2 devel1))
92
93 ;; The merge occurred between MASTER2 and MASTER4 so here we
94 ;; expect to see all the commits from the "devel" branch in
95 ;; addition to those on "master".
96 (lset= eq? (commit-difference master4 master2)
97 (list master4 merge master3 devel1 devel2)))))))
98
785af04a
LC
99(unless (which (git-command)) (test-skip 1))
100(test-assert "commit-difference, excluded commits"
101 (with-temporary-git-repository directory
102 '((add "a.txt" "A")
103 (commit "first commit")
104 (add "b.txt" "B")
105 (commit "second commit")
106 (add "c.txt" "C")
107 (commit "third commit")
108 (add "d.txt" "D")
109 (commit "fourth commit")
110 (add "e.txt" "E")
111 (commit "fifth commit"))
112 (with-repository directory repository
113 (let ((commit1 (find-commit repository "first"))
114 (commit2 (find-commit repository "second"))
115 (commit3 (find-commit repository "third"))
116 (commit4 (find-commit repository "fourth"))
117 (commit5 (find-commit repository "fifth")))
118 (and (lset= eq? (commit-difference commit4 commit1 (list commit2))
119 (list commit3 commit4))
120 (lset= eq? (commit-difference commit4 commit1 (list commit3))
121 (list commit4))
72357e21 122 (null? (commit-difference commit4 commit1 (list commit5))))))))
785af04a 123
c098c11b
LC
124(unless (which (git-command)) (test-skip 1))
125(test-equal "commit-relation"
126 '(self ;master3 master3
127 ancestor ;master1 master3
128 descendant ;master3 master1
129 unrelated ;master2 branch1
130 unrelated ;branch1 master2
131 ancestor ;branch1 merge
132 descendant ;merge branch1
133 ancestor ;master1 merge
134 descendant) ;merge master1
135 (with-temporary-git-repository directory
136 '((add "a.txt" "A")
137 (commit "first commit")
138 (branch "hack")
139 (checkout "hack")
140 (add "1.txt" "1")
141 (commit "branch commit")
142 (checkout "master")
143 (add "b.txt" "B")
144 (commit "second commit")
145 (add "c.txt" "C")
146 (commit "third commit")
147 (merge "hack" "merge"))
148 (with-repository directory repository
149 (let ((master1 (find-commit repository "first"))
150 (master2 (find-commit repository "second"))
151 (master3 (find-commit repository "third"))
152 (branch1 (find-commit repository "branch"))
153 (merge (find-commit repository "merge")))
154 (list (commit-relation master3 master3)
155 (commit-relation master1 master3)
156 (commit-relation master3 master1)
157 (commit-relation master2 branch1)
158 (commit-relation branch1 master2)
159 (commit-relation branch1 merge)
160 (commit-relation merge branch1)
161 (commit-relation master1 merge)
162 (commit-relation merge master1))))))
163
873f6f13 164(test-end "git")