added command structure for git calling

This commit is contained in:
2026-08-12 14:58:47 +02:00
parent 5ee7145ac7
commit 7be7007285
3 changed files with 44 additions and 18 deletions
+13 -4
View File
@@ -3,6 +3,7 @@
(require "private/git-provider.rkt" (require "private/git-provider.rkt"
"private/git-commands.rkt" "private/git-commands.rkt"
"private/config.rkt" "private/config.rkt"
simple-log
) )
(provide git) (provide git)
@@ -15,12 +16,20 @@
(cond (cond
([eq? command 'status] (cmd-git-status args)) ([eq? command 'status] (cmd-git-status args))
([eq? command 'add] (cmd-git-add args)) ([eq? command 'add] (cmd-git-add args))
([eq? command 'commit] (cmd-git-commit args))
(else (error "Not supported git command '~a" command)) (else (error "Not supported git command '~a" command))
) )
) )
(define (git-status . args) (define-syntax def-cmd
(cmd-git-status args)) (syntax-rules ()
((_ cmd cmd*)
(define (cmd . args)
(cmd* args)))))
(def-cmd git-status cmd-git-status)
(def-cmd git-add cmd-git-add)
(def-cmd git-commit cmd-git-commit)
(define (git-add . args)
(cmd-git-add args))
+27 -11
View File
@@ -7,6 +7,7 @@
(provide cmd-git-status (provide cmd-git-status
cmd-git-add cmd-git-add
cmd-git-commit
) )
(define (cmd-git-status args) (define (cmd-git-status args)
@@ -21,8 +22,10 @@
([eq? state 'M] (list 'modified file)) ([eq? state 'M] (list 'modified file))
([eq? state 'A] (list 'added file)) ([eq? state 'A] (list 'added file))
([eq? state 'D] (list 'deleted file)) ([eq? state 'D] (list 'deleted file))
([eq? state 'AM] (list 'modified-added file)) ([eq? state 'AM] (list 'modified file))
([eq? state 'AD] (list 'deleted-added file)) ([eq? state 'AD] (list 'deleted file))
([eq? state 'MM] (list 'modified file))
([eq? state 'MD] (list 'deleted file))
(else (else
(git-error 'status "Unexpected state" state)) (git-error 'status "Unexpected state" state))
) )
@@ -34,12 +37,25 @@
) )
) )
(define (cmd-git-add args)
(let ((output (run-git (cons 'add args))))
(let-values (((result out) (git-out 'add output)))
(if result (define-syntax def-proxy-cmd
(begin (syntax-rules ()
(git-displ out) ((_ f cmd)
result) (define (f args)
(git-error 'add "Error" out))))) (let ((output (run-git (cons 'cmd args))))
(let-values (((result out) (git-out 'cmd output)))
(if result
(begin
(git-displ out)
result)
(git-error 'cmd "Error" out)))))
)
)
)
(def-proxy-cmd cmd-git-add add)
(def-proxy-cmd cmd-git-commit commit)
+4 -3
View File
@@ -150,6 +150,7 @@
(define (git-displ out) (define (git-displ out)
(let ((str (if (string? out) out (string-join out "\n")))) (let ((str (if (string? out) out (string-join out "\n"))))
(info-git str) (unless (string=? (string-trim str) "")
(when (cfg-get 'git 'display-output #t) (info-git str)
(displayln str)))) (when (cfg-get 'git 'display-output #t)
(displayln str)))))