git.scm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2021 Kyle Meyer <kyle@kyleam.com>
  5. ;;; Copyright © 2021 Marius Bakke <marius@gnu.org>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (guix git)
  22. #:use-module (git)
  23. #:use-module (git object)
  24. #:use-module (git submodule)
  25. #:use-module (guix i18n)
  26. #:use-module (guix base32)
  27. #:use-module (guix cache)
  28. #:use-module (gcrypt hash)
  29. #:use-module ((guix build utils)
  30. #:select (mkdir-p delete-file-recursively))
  31. #:use-module (guix store)
  32. #:use-module (guix utils)
  33. #:use-module (guix records)
  34. #:use-module (guix gexp)
  35. #:use-module (guix sets)
  36. #:use-module ((guix diagnostics) #:select (leave))
  37. #:use-module (guix progress)
  38. #:use-module (rnrs bytevectors)
  39. #:use-module (ice-9 format)
  40. #:use-module (ice-9 match)
  41. #:use-module (ice-9 ftw)
  42. #:use-module (srfi srfi-1)
  43. #:use-module (srfi srfi-11)
  44. #:use-module (srfi srfi-34)
  45. #:use-module (srfi srfi-35)
  46. #:export (%repository-cache-directory
  47. honor-system-x509-certificates!
  48. url-cache-directory
  49. with-repository
  50. with-git-error-handling
  51. false-if-git-not-found
  52. update-cached-checkout
  53. url+commit->name
  54. latest-repository-commit
  55. commit-difference
  56. commit-relation
  57. git-checkout
  58. git-checkout?
  59. git-checkout-url
  60. git-checkout-branch
  61. git-checkout-commit
  62. git-checkout-recursive?))
  63. (define %repository-cache-directory
  64. (make-parameter (string-append (cache-directory #:ensure? #f)
  65. "/checkouts")))
  66. (define (honor-system-x509-certificates!)
  67. "Use the system's X.509 certificates for Git checkouts over HTTPS. Honor
  68. the 'SSL_CERT_FILE' and 'SSL_CERT_DIR' environment variables."
  69. ;; On distros such as CentOS 7, /etc/ssl/certs contains only a couple of
  70. ;; files (instead of all the certificates) among which "ca-bundle.crt". On
  71. ;; other distros /etc/ssl/certs usually contains the whole set of
  72. ;; certificates along with "ca-certificates.crt". Try to choose the right
  73. ;; one.
  74. (let ((file (letrec-syntax ((choose
  75. (syntax-rules ()
  76. ((_ file rest ...)
  77. (let ((f file))
  78. (if (and f (file-exists? f))
  79. f
  80. (choose rest ...))))
  81. ((_)
  82. #f))))
  83. (choose (getenv "SSL_CERT_FILE")
  84. "/etc/ssl/certs/ca-certificates.crt"
  85. "/etc/ssl/certs/ca-bundle.crt")))
  86. (directory (or (getenv "SSL_CERT_DIR") "/etc/ssl/certs")))
  87. (and (or file
  88. (and=> (stat directory #f)
  89. (lambda (st)
  90. (> (stat:nlink st) 2))))
  91. (begin
  92. (set-tls-certificate-locations! directory file)
  93. #t))))
  94. (define %certificates-initialized?
  95. ;; Whether 'honor-system-x509-certificates!' has already been called.
  96. #f)
  97. (define-syntax-rule (with-libgit2 thunk ...)
  98. (begin
  99. ;; XXX: The right thing to do would be to call (libgit2-shutdown) here,
  100. ;; but pointer finalizers used in guile-git may be called after shutdown,
  101. ;; resulting in a segfault. Hence, let's skip shutdown call for now.
  102. (libgit2-init!)
  103. (unless %certificates-initialized?
  104. (honor-system-x509-certificates!)
  105. (set! %certificates-initialized? #t))
  106. thunk ...))
  107. (define* (url-cache-directory url
  108. #:optional (cache-directory
  109. (%repository-cache-directory))
  110. #:key recursive?)
  111. "Return the directory associated to URL in %repository-cache-directory."
  112. (string-append
  113. cache-directory "/"
  114. (bytevector->base32-string
  115. (sha256 (string->utf8 (if recursive?
  116. (string-append "R:" url)
  117. url))))))
  118. (define (show-progress progress)
  119. "Display a progress bar as we fetch Git code. PROGRESS is an
  120. <indexer-progress> record from (git)."
  121. (define total
  122. (indexer-progress-total-objects progress))
  123. (define hundredth
  124. (match (quotient (indexer-progress-total-objects progress) 100)
  125. (0 1)
  126. (x x)))
  127. (define-values (done label)
  128. (if (< (indexer-progress-received-objects progress) total)
  129. (values (indexer-progress-received-objects progress)
  130. (G_ "receiving objects"))
  131. (values (indexer-progress-indexed-objects progress)
  132. (G_ "indexing objects"))))
  133. (define %
  134. (* 100. (/ done total)))
  135. (when (and (< % 100) (zero? (modulo done hundredth)))
  136. (erase-current-line (current-error-port))
  137. (let ((width (max (- (current-terminal-columns)
  138. (string-length label) 7)
  139. 3)))
  140. (format (current-error-port) "~a ~3,d% ~a"
  141. label (inexact->exact (round %))
  142. (progress-bar % width)))
  143. (force-output (current-error-port)))
  144. (when (= % 100.)
  145. ;; We're done, erase the line.
  146. (erase-current-line (current-error-port))
  147. (force-output (current-error-port)))
  148. ;; Return true to indicate that we should go on.
  149. #t)
  150. (define (make-default-fetch-options)
  151. "Return the default fetch options."
  152. (let ((auth-method (%make-auth-ssh-agent)))
  153. ;; The #:transfer-progress and #:proxy-url options appeared in Guile-Git
  154. ;; 0.4.0. Omit them when using an older version.
  155. (catch 'wrong-number-of-args
  156. (lambda ()
  157. (make-fetch-options auth-method
  158. ;; Guile-Git doesn't distinguish between these.
  159. #:proxy-url (or (getenv "http_proxy")
  160. (getenv "https_proxy"))
  161. #:transfer-progress
  162. (and (isatty? (current-error-port))
  163. show-progress)))
  164. (lambda args
  165. (make-fetch-options auth-method)))))
  166. (define (clone* url directory)
  167. "Clone git repository at URL into DIRECTORY. Upon failure,
  168. make sure no empty directory is left behind."
  169. (with-throw-handler #t
  170. (lambda ()
  171. (mkdir-p directory)
  172. (clone url directory
  173. (make-clone-options
  174. #:fetch-options (make-default-fetch-options))))
  175. (lambda _
  176. (false-if-exception (rmdir directory)))))
  177. (define (url+commit->name url sha1)
  178. "Return the string \"<REPO-NAME>-<SHA1:7>\" where REPO-NAME is the name of
  179. the git repository, extracted from URL and SHA1:7 the seven first digits
  180. of SHA1 string."
  181. (string-append
  182. (string-replace-substring
  183. (last (string-split url #\/)) ".git" "")
  184. "-" (string-take sha1 7)))
  185. (define (resolve-reference repository ref)
  186. "Resolve the branch, commit or tag specified by REF, and return the
  187. corresponding Git object."
  188. (let resolve ((ref ref))
  189. (match ref
  190. (('branch . branch)
  191. (let ((oid (reference-target
  192. (branch-lookup repository branch BRANCH-REMOTE))))
  193. (object-lookup repository oid)))
  194. (('symref . symref)
  195. (let ((oid (reference-name->oid repository symref)))
  196. (object-lookup repository oid)))
  197. (('commit . commit)
  198. (let ((len (string-length commit)))
  199. ;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, so we
  200. ;; can't be sure it's available. Furthermore, 'string->oid' used to
  201. ;; read out-of-bounds when passed a string shorter than 40 chars,
  202. ;; which is why we delay calls to it below.
  203. (if (< len 40)
  204. (object-lookup-prefix repository (string->oid commit) len)
  205. (object-lookup repository (string->oid commit)))))
  206. (('tag-or-commit . str)
  207. (cond ((and (string-contains str "-g")
  208. (match (string-split str #\-)
  209. ((version ... revision g+commit)
  210. (if (and (> (string-length g+commit) 4)
  211. (string-every char-set:digit revision)
  212. (string-every char-set:hex-digit
  213. (string-drop g+commit 1)))
  214. ;; Looks like a 'git describe' style ID, like
  215. ;; v1.3.0-7-gaa34d4d28d.
  216. (string-drop g+commit 1)
  217. #f))
  218. (_ #f)))
  219. => (lambda (commit) (resolve `(commit . ,commit))))
  220. ((or (> (string-length str) 40)
  221. (not (string-every char-set:hex-digit str)))
  222. (resolve `(tag . ,str))) ;definitely a tag
  223. (else
  224. (catch 'git-error
  225. (lambda ()
  226. (resolve `(tag . ,str)))
  227. (lambda _
  228. ;; There's no such tag, so it must be a commit ID.
  229. (resolve `(commit . ,str)))))))
  230. (('tag . tag)
  231. (let ((oid (reference-name->oid repository
  232. (string-append "refs/tags/" tag))))
  233. ;; OID may point to a "tag" object, but it can also point directly
  234. ;; to a "commit" object, as surprising as it may seem. Return that
  235. ;; object, whatever that is.
  236. (object-lookup repository oid))))))
  237. (define (switch-to-ref repository ref)
  238. "Switch to REPOSITORY's branch, commit or tag specified by REF. Return the
  239. OID (roughly the commit hash) corresponding to REF."
  240. (define obj
  241. (resolve-reference repository ref))
  242. (reset repository obj RESET_HARD)
  243. (object-id obj))
  244. (define (call-with-repository directory proc)
  245. (let ((repository #f))
  246. (dynamic-wind
  247. (lambda ()
  248. (set! repository (repository-open directory)))
  249. (lambda ()
  250. (proc repository))
  251. (lambda ()
  252. (repository-close! repository)))))
  253. (define-syntax-rule (with-repository directory repository exp ...)
  254. "Open the repository at DIRECTORY and bind REPOSITORY to it within the
  255. dynamic extent of EXP."
  256. (call-with-repository directory
  257. (lambda (repository) exp ...)))
  258. (define (report-git-error error)
  259. "Report the given Guile-Git error."
  260. ;; Prior to Guile-Git commit b6b2760c2fd6dfaa5c0fedb43eeaff06166b3134,
  261. ;; errors would be represented by integers.
  262. (match error
  263. ((? integer? error) ;old Guile-Git
  264. (leave (G_ "Git error ~a~%") error))
  265. ((? git-error? error) ;new Guile-Git
  266. (leave (G_ "Git error: ~a~%") (git-error-message error)))))
  267. (define-syntax-rule (with-git-error-handling body ...)
  268. (catch 'git-error
  269. (lambda ()
  270. body ...)
  271. (lambda (key err)
  272. (report-git-error err))))
  273. (define* (update-submodules repository
  274. #:key (log-port (current-error-port))
  275. (fetch-options #f))
  276. "Update the submodules of REPOSITORY, a Git repository object."
  277. (for-each (lambda (name)
  278. (let ((submodule (submodule-lookup repository name)))
  279. (format log-port (G_ "updating submodule '~a'...~%")
  280. name)
  281. (submodule-update submodule
  282. #:fetch-options fetch-options)
  283. ;; Recurse in SUBMODULE.
  284. (let ((directory (string-append
  285. (repository-working-directory repository)
  286. "/" (submodule-path submodule))))
  287. (with-repository directory repository
  288. (update-submodules repository
  289. #:fetch-options fetch-options
  290. #:log-port log-port)))))
  291. (repository-submodules repository)))
  292. (define-syntax-rule (false-if-git-not-found exp)
  293. "Evaluate EXP, returning #false if a GIT_ENOTFOUND error is raised."
  294. (catch 'git-error
  295. (lambda ()
  296. exp)
  297. (lambda (key error . rest)
  298. (if (= GIT_ENOTFOUND (git-error-code error))
  299. #f
  300. (apply throw key error rest)))))
  301. (define (reference-available? repository ref)
  302. "Return true if REF, a reference such as '(commit . \"cabba9e\"), is
  303. definitely available in REPOSITORY, false otherwise."
  304. (match ref
  305. (('commit . commit)
  306. (let ((len (string-length commit))
  307. (oid (string->oid commit)))
  308. (false-if-git-not-found
  309. (->bool (if (< len 40)
  310. (object-lookup-prefix repository oid len OBJ-COMMIT)
  311. (commit-lookup repository oid))))))
  312. (_
  313. #f)))
  314. (define cached-checkout-expiration
  315. ;; Return the expiration time procedure for a cached checkout.
  316. ;; TODO: Honor $GUIX_GIT_CACHE_EXPIRATION.
  317. ;; Use the mtime rather than the atime to cope with file systems mounted
  318. ;; with 'noatime'.
  319. (file-expiration-time (* 90 24 3600) stat:mtime))
  320. (define %checkout-cache-cleanup-period
  321. ;; Period for the removal of expired cached checkouts.
  322. (* 5 24 3600))
  323. (define (delete-checkout directory)
  324. "Delete DIRECTORY recursively, in an atomic fashion."
  325. (let ((trashed (string-append directory ".trashed")))
  326. (rename-file directory trashed)
  327. (delete-file-recursively trashed)))
  328. (define* (update-cached-checkout url
  329. #:key
  330. (ref '())
  331. recursive?
  332. (check-out? #t)
  333. starting-commit
  334. (log-port (%make-void-port "w"))
  335. (cache-directory
  336. (url-cache-directory
  337. url (%repository-cache-directory)
  338. #:recursive? recursive?)))
  339. "Update the cached checkout of URL to REF in CACHE-DIRECTORY. Return three
  340. values: the cache directory name, and the SHA1 commit (a string) corresponding
  341. to REF, and the relation of the new commit relative to STARTING-COMMIT (if
  342. provided) as returned by 'commit-relation'.
  343. REF is pair whose key is [branch | commit | tag | tag-or-commit ] and value
  344. the associated data: [<branch name> | <sha1> | <tag name> | <string>].
  345. If REF is the empty list, the remote HEAD is used.
  346. When RECURSIVE? is true, check out submodules as well, if any.
  347. When CHECK-OUT? is true, reset the cached working tree to REF; otherwise leave
  348. it unchanged."
  349. (define (cache-entries directory)
  350. (filter-map (match-lambda
  351. ((or "." "..")
  352. #f)
  353. (file
  354. (string-append directory "/" file)))
  355. (or (scandir directory) '())))
  356. (define canonical-ref
  357. ;; We used to require callers to specify "origin/" for each branch, which
  358. ;; made little sense since the cache should be transparent to them. So
  359. ;; here we append "origin/" if it's missing and otherwise keep it.
  360. (match ref
  361. (() '(symref . "refs/remotes/origin/HEAD"))
  362. (('branch . branch)
  363. `(branch . ,(if (string-prefix? "origin/" branch)
  364. branch
  365. (string-append "origin/" branch))))
  366. (_ ref)))
  367. (with-libgit2
  368. (let* ((cache-exists? (openable-repository? cache-directory))
  369. (repository (if cache-exists?
  370. (repository-open cache-directory)
  371. (clone* url cache-directory))))
  372. ;; Only fetch remote if it has not been cloned just before.
  373. (when (and cache-exists?
  374. (not (reference-available? repository ref)))
  375. (remote-fetch (remote-lookup repository "origin")
  376. #:fetch-options (make-default-fetch-options)))
  377. (when recursive?
  378. (update-submodules repository #:log-port log-port
  379. #:fetch-options (make-default-fetch-options)))
  380. ;; Note: call 'commit-relation' from here because it's more efficient
  381. ;; than letting users re-open the checkout later on.
  382. (let* ((oid (if check-out?
  383. (switch-to-ref repository canonical-ref)
  384. (object-id
  385. (resolve-reference repository canonical-ref))))
  386. (new (and starting-commit
  387. (commit-lookup repository oid)))
  388. (old (and starting-commit
  389. (false-if-git-not-found
  390. (commit-lookup repository
  391. (string->oid starting-commit)))))
  392. (relation (and starting-commit
  393. (if old
  394. (commit-relation old new)
  395. 'unrelated))))
  396. ;; Reclaim file descriptors and memory mappings associated with
  397. ;; REPOSITORY as soon as possible.
  398. (repository-close! repository)
  399. ;; Update CACHE-DIRECTORY's mtime to so the cache logic sees it.
  400. (match (gettimeofday)
  401. ((seconds . microseconds)
  402. (let ((nanoseconds (* 1000 microseconds)))
  403. (utime cache-directory
  404. seconds seconds
  405. nanoseconds nanoseconds))))
  406. ;; When CACHE-DIRECTORY is a sub-directory of the default cache
  407. ;; directory, remove expired checkouts that are next to it.
  408. (let ((parent (dirname cache-directory)))
  409. (when (string=? parent (%repository-cache-directory))
  410. (maybe-remove-expired-cache-entries parent cache-entries
  411. #:entry-expiration
  412. cached-checkout-expiration
  413. #:delete-entry delete-checkout
  414. #:cleanup-period
  415. %checkout-cache-cleanup-period)))
  416. (values cache-directory (oid->string oid) relation)))))
  417. (define* (latest-repository-commit store url
  418. #:key
  419. recursive?
  420. (log-port (%make-void-port "w"))
  421. (cache-directory
  422. (%repository-cache-directory))
  423. (ref '()))
  424. "Return two values: the content of the git repository at URL copied into a
  425. store directory and the sha1 of the top level commit in this directory. The
  426. reference to be checkout, once the repository is fetched, is specified by REF.
  427. REF is pair whose key is [branch | commit | tag] and value the associated
  428. data, respectively [<branch name> | <sha1> | <tag name>]. If REF is the empty
  429. list, the remote HEAD is used.
  430. When RECURSIVE? is true, check out submodules as well, if any.
  431. Git repositories are kept in the cache directory specified by
  432. %repository-cache-directory parameter.
  433. Log progress and checkout info to LOG-PORT."
  434. (define (dot-git? file stat)
  435. (and (string=? (basename file) ".git")
  436. (or (eq? 'directory (stat:type stat))
  437. ;; Submodule checkouts end up with a '.git' regular file that
  438. ;; contains metadata about where their actual '.git' directory
  439. ;; lives.
  440. (and recursive?
  441. (eq? 'regular (stat:type stat))))))
  442. (format log-port "updating checkout of '~a'...~%" url)
  443. (let*-values
  444. (((checkout commit _)
  445. (update-cached-checkout url
  446. #:recursive? recursive?
  447. #:ref ref
  448. #:cache-directory
  449. (url-cache-directory url cache-directory
  450. #:recursive?
  451. recursive?)
  452. #:log-port log-port))
  453. ((name)
  454. (url+commit->name url commit)))
  455. (format log-port "retrieved commit ~a~%" commit)
  456. (values (add-to-store store name #t "sha256" checkout
  457. #:select? (negate dot-git?))
  458. commit)))
  459. (define (print-git-error port key args default-printer)
  460. (match args
  461. (((? git-error? error) . _)
  462. (format port (G_ "Git error: ~a~%")
  463. (git-error-message error)))))
  464. (set-exception-printer! 'git-error print-git-error)
  465. ;;;
  466. ;;; Commit difference.
  467. ;;;
  468. (define* (commit-closure commit #:optional (visited (setq)))
  469. "Return the closure of COMMIT as a set. Skip commits contained in VISITED,
  470. a set, and adjoin VISITED to the result."
  471. (let loop ((commits (list commit))
  472. (visited visited))
  473. (match commits
  474. (()
  475. visited)
  476. ((head . tail)
  477. (if (set-contains? visited head)
  478. (loop tail visited)
  479. (loop (append (commit-parents head) tail)
  480. (set-insert head visited)))))))
  481. (define* (commit-difference new old #:optional (excluded '()))
  482. "Return the list of commits between NEW and OLD, where OLD is assumed to be
  483. an ancestor of NEW. Exclude all the commits listed in EXCLUDED along with
  484. their ancestors.
  485. Essentially, this computes the set difference between the closure of NEW and
  486. that of OLD."
  487. (let loop ((commits (list new))
  488. (result '())
  489. (visited (fold commit-closure
  490. (setq)
  491. (cons old excluded))))
  492. (match commits
  493. (()
  494. (reverse result))
  495. ((head . tail)
  496. (if (set-contains? visited head)
  497. (loop tail result visited)
  498. (loop (append (commit-parents head) tail)
  499. (cons head result)
  500. (set-insert head visited)))))))
  501. (define (commit-relation old new)
  502. "Return a symbol denoting the relation between OLD and NEW, two commit
  503. objects: 'ancestor (meaning that OLD is an ancestor of NEW), 'descendant, or
  504. 'unrelated, or 'self (OLD and NEW are the same commit)."
  505. (if (eq? old new)
  506. 'self
  507. (let ((newest (commit-closure new)))
  508. (if (set-contains? newest old)
  509. 'ancestor
  510. (let* ((seen (list->setq (commit-parents new)))
  511. (oldest (commit-closure old seen)))
  512. (if (set-contains? oldest new)
  513. 'descendant
  514. 'unrelated))))))
  515. ;;;
  516. ;;; Checkouts.
  517. ;;;
  518. ;; Representation of the "latest" checkout of a branch or a specific commit.
  519. (define-record-type* <git-checkout>
  520. git-checkout make-git-checkout
  521. git-checkout?
  522. (url git-checkout-url)
  523. (branch git-checkout-branch (default #f))
  524. (commit git-checkout-commit (default #f)) ;#f | tag | commit
  525. (recursive? git-checkout-recursive? (default #f)))
  526. (define* (latest-repository-commit* url #:key ref recursive? log-port)
  527. ;; Monadic variant of 'latest-repository-commit'.
  528. (lambda (store)
  529. ;; The caller--e.g., (guix scripts build)--may not handle 'git-error' so
  530. ;; translate it into '&message' conditions that we know will be properly
  531. ;; handled.
  532. (catch 'git-error
  533. (lambda ()
  534. (values (latest-repository-commit store url
  535. #:ref ref
  536. #:recursive? recursive?
  537. #:log-port log-port)
  538. store))
  539. (lambda (key error . _)
  540. (raise (condition
  541. (&message
  542. (message
  543. (match ref
  544. (('commit . commit)
  545. (format #f (G_ "cannot fetch commit ~a from ~a: ~a")
  546. commit url (git-error-message error)))
  547. (('branch . branch)
  548. (format #f (G_ "cannot fetch branch '~a' from ~a: ~a")
  549. branch url (git-error-message error)))
  550. (_
  551. (format #f (G_ "Git failure while fetching ~a: ~a")
  552. url (git-error-message error))))))))))))
  553. (define-gexp-compiler (git-checkout-compiler (checkout <git-checkout>)
  554. system target)
  555. ;; "Compile" CHECKOUT by updating the local checkout and adding it to the
  556. ;; store.
  557. (match checkout
  558. (($ <git-checkout> url branch commit recursive?)
  559. (latest-repository-commit* url
  560. #:ref (cond (commit
  561. `(tag-or-commit . ,commit))
  562. (branch
  563. `(branch . ,branch))
  564. (else '()))
  565. #:recursive? recursive?
  566. #:log-port (current-error-port)))))
  567. ;; Local Variables:
  568. ;; eval: (put 'with-repository 'scheme-indent-function 2)
  569. ;; End: