Mirror of GNU Guix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.4 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 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 (guix build git)
  19. #:use-module (guix build utils)
  20. #:export (git-fetch))
  21. ;;; Commentary:
  22. ;;;
  23. ;;; This is the build-side support code of (guix git-download). It allows a
  24. ;;; Git repository to be cloned and checked out at a specific commit.
  25. ;;;
  26. ;;; Code:
  27. (define* (git-fetch url commit directory
  28. #:key (git-command "git") recursive?)
  29. "Fetch COMMIT from URL into DIRECTORY. COMMIT must be a valid Git commit
  30. identifier. When RECURSIVE? is true, all the sub-modules of URL are fetched,
  31. recursively. Return #t on success, #f otherwise."
  32. ;; Disable TLS certificate verification. The hash of the checkout is known
  33. ;; in advance anyway.
  34. (setenv "GIT_SSL_NO_VERIFY" "true")
  35. (let ((args `("clone" ,@(if recursive? '("--recursive") '())
  36. ,url ,directory)))
  37. (and (zero? (apply system* git-command args))
  38. (with-directory-excursion directory
  39. (system* git-command "tag" "-l")
  40. (and (zero? (system* git-command "checkout" commit))
  41. (begin
  42. ;; The contents of '.git' vary as a function of the current
  43. ;; status of the Git repo. Since we want a fixed output, this
  44. ;; directory needs to be taken out.
  45. (delete-file-recursively ".git")
  46. (when recursive?
  47. ;; In sub-modules, '.git' is a flat file, not a directory,
  48. ;; so we can use 'find-files' here.
  49. (for-each delete-file-recursively
  50. (find-files directory "^\\.git$")))
  51. #t))))))
  52. ;;; git.scm ends here