Make raco pkg try git-checkout-credentials when cloning a repository
This commit is contained in:
parent
afa17a3df6
commit
6d63e4443f
24
racket/collects/pkg/private/checkout-credentials.rkt
Normal file
24
racket/collects/pkg/private/checkout-credentials.rkt
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(require net/git-checkout
|
||||||
|
racket/list
|
||||||
|
"config.rkt")
|
||||||
|
|
||||||
|
(provide call-with-git-checkout-credentials)
|
||||||
|
|
||||||
|
(define (call-with-git-checkout-credentials thunk)
|
||||||
|
(let loop ([credentials-list (cons #f (get-git-checkout-credentials))])
|
||||||
|
(define credentials (first credentials-list))
|
||||||
|
(with-handlers ([exn:fail:git? (λ (exn)
|
||||||
|
(if (empty? (rest credentials-list))
|
||||||
|
(raise exn)
|
||||||
|
(loop (rest credentials-list))))])
|
||||||
|
(define c (make-custodian))
|
||||||
|
(parameterize ([current-custodian c]
|
||||||
|
[current-git-username (and credentials (hash-ref credentials 'username))]
|
||||||
|
[current-git-password (and credentials (hash-ref credentials 'password))])
|
||||||
|
(dynamic-wind
|
||||||
|
void
|
||||||
|
thunk
|
||||||
|
(lambda ()
|
||||||
|
(custodian-shutdown-all c)))))))
|
|
@ -38,6 +38,10 @@
|
||||||
(or (current-pkg-network-retries)
|
(or (current-pkg-network-retries)
|
||||||
(read-pkg-cfg/def 'network-retries)))
|
(read-pkg-cfg/def 'network-retries)))
|
||||||
|
|
||||||
|
(define (get-git-checkout-credentials)
|
||||||
|
(or (current-pkg-git-checkout-credentials)
|
||||||
|
(read-pkg-cfg/def 'git-checkout-credentials)))
|
||||||
|
|
||||||
(define (read-pkg-cfg/def k)
|
(define (read-pkg-cfg/def k)
|
||||||
;; Lock is held for the current scope, but if
|
;; Lock is held for the current scope, but if
|
||||||
;; the key is not found in the current scope,
|
;; the key is not found in the current scope,
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
"path.rkt"
|
"path.rkt"
|
||||||
"print.rkt"
|
"print.rkt"
|
||||||
"config.rkt"
|
"config.rkt"
|
||||||
|
"checkout-credentials.rkt"
|
||||||
"network.rkt")
|
"network.rkt")
|
||||||
|
|
||||||
(provide download-file!
|
(provide download-file!
|
||||||
|
@ -101,6 +102,8 @@
|
||||||
(define (download!)
|
(define (download!)
|
||||||
(when download-printf
|
(when download-printf
|
||||||
(download-printf "Downloading repository ~a\n" (url->string url)))
|
(download-printf "Downloading repository ~a\n" (url->string url)))
|
||||||
|
(call-with-git-checkout-credentials
|
||||||
|
(lambda ()
|
||||||
(call-with-network-retries
|
(call-with-network-retries
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(git-checkout host #:port port repo
|
(git-checkout host #:port port repo
|
||||||
|
@ -109,10 +112,11 @@
|
||||||
#:status-printf (lambda (fmt . args)
|
#:status-printf (lambda (fmt . args)
|
||||||
(define (strip-ending-newline s)
|
(define (strip-ending-newline s)
|
||||||
(regexp-replace #rx"\n$" s ""))
|
(regexp-replace #rx"\n$" s ""))
|
||||||
(log-pkg-debug (strip-ending-newline (apply format fmt args))))
|
(log-pkg-debug (strip-ending-newline
|
||||||
|
(apply format fmt args))))
|
||||||
#:transport transport
|
#:transport transport
|
||||||
#:strict-links? #t
|
#:strict-links? #t
|
||||||
#:depth 1)))
|
#:depth 1)))))
|
||||||
(set! unpacked? #t)
|
(set! unpacked? #t)
|
||||||
;; package directory as ".tgz" so it can be cached:
|
;; package directory as ".tgz" so it can be cached:
|
||||||
(parameterize ([current-directory dest-dir])
|
(parameterize ([current-directory dest-dir])
|
||||||
|
|
|
@ -34,3 +34,6 @@
|
||||||
|
|
||||||
(define current-pkg-network-retries
|
(define current-pkg-network-retries
|
||||||
(make-parameter #f))
|
(make-parameter #f))
|
||||||
|
|
||||||
|
(define current-pkg-git-checkout-credentials
|
||||||
|
(make-parameter #f))
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
"orig-pkg.rkt"
|
"orig-pkg.rkt"
|
||||||
"git.rkt"
|
"git.rkt"
|
||||||
"prefetch.rkt"
|
"prefetch.rkt"
|
||||||
|
"checkout-credentials.rkt"
|
||||||
"network.rkt")
|
"network.rkt")
|
||||||
|
|
||||||
(provide (struct-out install-info)
|
(provide (struct-out install-info)
|
||||||
|
@ -735,6 +736,8 @@
|
||||||
(define-values (transport host port repo branch path)
|
(define-values (transport host port repo branch path)
|
||||||
(split-git-or-hub-url pkg-url #:type type))
|
(split-git-or-hub-url pkg-url #:type type))
|
||||||
(download-printf "Querying Git references for ~a at ~a\n" pkg-name pkg-url-str)
|
(download-printf "Querying Git references for ~a at ~a\n" pkg-name pkg-url-str)
|
||||||
|
(call-with-git-checkout-credentials
|
||||||
|
(lambda ()
|
||||||
(call-with-network-retries
|
(call-with-network-retries
|
||||||
(lambda ()
|
(lambda ()
|
||||||
;; Supplying `#:dest-dir #f` means that we just resolve `branch`
|
;; Supplying `#:dest-dir #f` means that we just resolve `branch`
|
||||||
|
@ -751,7 +754,7 @@
|
||||||
" the given URL might not refer to a Git repository\n"
|
" the given URL might not refer to a Git repository\n"
|
||||||
" given URL: ~a")
|
" given URL: ~a")
|
||||||
pkg-url-str))
|
pkg-url-str))
|
||||||
#:transport transport)))]
|
#:transport transport)))))]
|
||||||
[(github)
|
[(github)
|
||||||
(match-define (list* user repo branch path)
|
(match-define (list* user repo branch path)
|
||||||
(split-github-url pkg-url))
|
(split-github-url pkg-url))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user