1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (test-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))
27 ;; Test the (guix git) tools.
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
36 (commit "first commit")
38 (commit "second commit")
40 (commit "third commit")
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)
55 ;; COMMIT4 is not an ancestor of COMMIT1 so we should get the
57 (null? (commit-difference commit1 commit4)))))))
59 (unless (which (git-command)) (test-skip 1))
60 (test-assert "commit-difference, fork"
61 (with-temporary-git-repository directory
63 (commit "first commit")
66 (add "devel/1.txt" "1")
67 (commit "first devel commit")
68 (add "devel/2.txt" "2")
69 (commit "second devel commit")
72 (commit "second commit")
74 (commit "third commit")
75 (merge "devel" "merge")
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)
88 (lset= eq? (commit-difference master3 master1)
89 (list master3 master2))
90 (lset= eq? (commit-difference devel2 master1)
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)))))))
99 (unless (which (git-command)) (test-skip 1))
100 (test-assert "commit-difference, excluded commits"
101 (with-temporary-git-repository directory
103 (commit "first commit")
105 (commit "second commit")
107 (commit "third commit")
109 (commit "fourth commit")
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))
122 (lset= eq? (commit-difference commit4 commit1 (list commit5))
123 (list commit2 commit3 commit4)))))))