config functionality extended
This commit is contained in:
@@ -55,10 +55,14 @@ See the Scribble documentation for command-specific behavior and return values.
|
|||||||
`git config` has a small Racket-oriented interface:
|
`git config` has a small Racket-oriented interface:
|
||||||
|
|
||||||
```racket
|
```racket
|
||||||
|
(git 'config '--all)
|
||||||
(git 'config 'get '--all)
|
(git 'config 'get '--all)
|
||||||
|
(git 'config '--global 'get '--all)
|
||||||
|
(git 'config 'get '--global "user.email")
|
||||||
(git 'config 'get '--all "credential.helper")
|
(git 'config 'get '--all "credential.helper")
|
||||||
(git 'config 'get "credential.helper")
|
(git 'config 'get "credential.helper")
|
||||||
(git 'config 'set! "user.email" "hans@example.invalid")
|
(git 'config 'set! "user.email" "hans@example.invalid")
|
||||||
|
(git 'config '--global 'set! "user.email" "hans@example.invalid")
|
||||||
(git 'config 'set! '--global "user.email" "hans@example.invalid")
|
(git 'config 'set! '--global "user.email" "hans@example.invalid")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -143,46 +143,79 @@
|
|||||||
; result : Arguments accepted by git config.
|
; result : Arguments accepted by git config.
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(define (git-config-args args info)
|
(define (git-config-args args info)
|
||||||
(if (null? args)
|
(define (scope? x)
|
||||||
(error 'git-config "Expected get or set!")
|
(member x '(--global --local --system)))
|
||||||
(let ((action (car args))
|
|
||||||
(rest (cdr args)))
|
|
||||||
(cond
|
|
||||||
((eq? action 'get)
|
|
||||||
(cond
|
|
||||||
((null? rest)
|
|
||||||
(error 'git-config "Expected a configuration key or --all"))
|
|
||||||
((eq? (car rest) '--all)
|
|
||||||
(cond
|
|
||||||
((null? (cdr rest))
|
|
||||||
(hash-set! info 'config-operation 'all)
|
|
||||||
'(--list))
|
|
||||||
((null? (cddr rest))
|
|
||||||
(hash-set! info 'config-operation 'get-all)
|
|
||||||
(list '--get-all (cadr rest)))
|
|
||||||
(else
|
|
||||||
(error 'git-config "Too many arguments for config get --all"))))
|
|
||||||
((null? (cdr rest))
|
|
||||||
(hash-set! info 'config-operation 'get)
|
|
||||||
(list '--get (car rest)))
|
|
||||||
(else
|
|
||||||
(error 'git-config "Too many arguments for config get"))))
|
|
||||||
|
|
||||||
((eq? action 'set!)
|
(define (split-scope args)
|
||||||
(cond
|
(cond
|
||||||
((= (length rest) 2)
|
((and (pair? args) (scope? (car args)))
|
||||||
(hash-set! info 'config-operation 'set)
|
(values (car args) (cdr args)))
|
||||||
rest)
|
(else
|
||||||
((and (= (length rest) 3)
|
(values #f args))))
|
||||||
(member (car rest) '(--global --local --system)))
|
|
||||||
(hash-set! info 'config-operation 'set)
|
(let-values (((scope args*) (split-scope args)))
|
||||||
rest)
|
(cond
|
||||||
(else
|
;; Short form: (git 'config '--all)
|
||||||
(error 'git-config
|
((and (not scope)
|
||||||
"Expected config set! [--global|--local|--system] key value"))))
|
(= (length args*) 1)
|
||||||
|
(eq? (car args*) '--all))
|
||||||
|
(hash-set! info 'config-operation 'all)
|
||||||
|
'(--list))
|
||||||
|
|
||||||
|
((null? args*)
|
||||||
|
(error 'git-config "Expected get or set!"))
|
||||||
|
|
||||||
|
(else
|
||||||
|
(let ((action (car args*))
|
||||||
|
(rest (cdr args*)))
|
||||||
|
(cond
|
||||||
|
((eq? action 'get)
|
||||||
|
;; Also accept scope directly after get.
|
||||||
|
(let-values (((scope* rest*) (split-scope rest)))
|
||||||
|
(let ((effective-scope (or scope scope*)))
|
||||||
|
(when (and scope scope*)
|
||||||
|
(error 'git-config "Configuration scope specified twice"))
|
||||||
|
(cond
|
||||||
|
((null? rest*)
|
||||||
|
(error 'git-config "Expected a configuration key or --all"))
|
||||||
|
|
||||||
|
((eq? (car rest*) '--all)
|
||||||
|
(cond
|
||||||
|
((null? (cdr rest*))
|
||||||
|
(hash-set! info 'config-operation 'all)
|
||||||
|
(append (if effective-scope (list effective-scope) '())
|
||||||
|
'(--list)))
|
||||||
|
((null? (cddr rest*))
|
||||||
|
(hash-set! info 'config-operation 'get-all)
|
||||||
|
(append (if effective-scope (list effective-scope) '())
|
||||||
|
(list '--get-all (cadr rest*))))
|
||||||
|
(else
|
||||||
|
(error 'git-config "Too many arguments for config get --all"))))
|
||||||
|
|
||||||
|
((null? (cdr rest*))
|
||||||
|
(hash-set! info 'config-operation 'get)
|
||||||
|
(append (if effective-scope (list effective-scope) '())
|
||||||
|
(list '--get (car rest*))))
|
||||||
|
|
||||||
|
(else
|
||||||
|
(error 'git-config "Too many arguments for config get"))))))
|
||||||
|
|
||||||
|
((eq? action 'set!)
|
||||||
|
;; Also accept scope directly after set!.
|
||||||
|
(let-values (((scope* rest*) (split-scope rest)))
|
||||||
|
(let ((effective-scope (or scope scope*)))
|
||||||
|
(when (and scope scope*)
|
||||||
|
(error 'git-config "Configuration scope specified twice"))
|
||||||
|
(if (= (length rest*) 2)
|
||||||
|
(begin
|
||||||
|
(hash-set! info 'config-operation 'set)
|
||||||
|
(append (if effective-scope (list effective-scope) '())
|
||||||
|
rest*))
|
||||||
|
(error 'git-config "Expected config set! [scope] key value")))))
|
||||||
|
|
||||||
|
(else
|
||||||
|
(error 'git-config "Expected get or set!"))))))))
|
||||||
|
|
||||||
(else
|
|
||||||
(error 'git-config "Expected get or set!"))))))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
; goal : Process the result of the Racket-oriented git config interface.
|
; goal : Process the result of the Racket-oriented git config interface.
|
||||||
|
|||||||
@@ -94,7 +94,10 @@ Provides a Racket-oriented interface to @tt{git config}. The same interface is
|
|||||||
available through @racket[git] with command @racket['config].
|
available through @racket[git] with command @racket['config].
|
||||||
|
|
||||||
@racketblock[
|
@racketblock[
|
||||||
|
(git 'config '--all)
|
||||||
(git 'config 'get '--all)
|
(git 'config 'get '--all)
|
||||||
|
(git 'config '--global 'get '--all)
|
||||||
|
(git 'config 'get '--global '--all)
|
||||||
]
|
]
|
||||||
|
|
||||||
returns all visible configuration entries as key/value items:
|
returns all visible configuration entries as key/value items:
|
||||||
@@ -122,11 +125,13 @@ Configuration values can be written with @racket['set!]:
|
|||||||
|
|
||||||
@racketblock[
|
@racketblock[
|
||||||
(git 'config 'set! "user.email" "hans@example.invalid")
|
(git 'config 'set! "user.email" "hans@example.invalid")
|
||||||
|
(git 'config '--global 'set! "user.email" "hans@example.invalid")
|
||||||
(git 'config 'set! '--global "user.email" "hans@example.invalid")
|
(git 'config 'set! '--global "user.email" "hans@example.invalid")
|
||||||
]
|
]
|
||||||
|
|
||||||
The optional write scope can be @tt{--global}, @tt{--local}, or @tt{--system}.
|
The optional scope can be @tt{--global}, @tt{--local}, or @tt{--system}. It may
|
||||||
A successful write returns @racket[#t].
|
appear directly after @racket['config] or directly after @racket['get] /
|
||||||
|
@racket['set!]. A successful write returns @racket[#t].
|
||||||
}
|
}
|
||||||
|
|
||||||
@defproc[(git-branch [argument any/c] ...) boolean?]{
|
@defproc[(git-branch [argument any/c] ...) boolean?]{
|
||||||
|
|||||||
Reference in New Issue
Block a user