git.scm 6.7 KB

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