diff --git a/main.rkt b/main.rkt index d68a9b4..127d823 100644 --- a/main.rkt +++ b/main.rkt @@ -3,6 +3,7 @@ (require "private/git-provider.rkt" "private/git-commands.rkt" "private/config.rkt" + simple-log ) (provide git) @@ -15,12 +16,20 @@ (cond ([eq? command 'status] (cmd-git-status args)) ([eq? command 'add] (cmd-git-add args)) + ([eq? command 'commit] (cmd-git-commit args)) (else (error "Not supported git command '~a" command)) ) ) -(define (git-status . args) - (cmd-git-status args)) +(define-syntax def-cmd + (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)) diff --git a/private/git-commands.rkt b/private/git-commands.rkt index 7937219..55ff10e 100644 --- a/private/git-commands.rkt +++ b/private/git-commands.rkt @@ -7,6 +7,7 @@ (provide cmd-git-status cmd-git-add + cmd-git-commit ) (define (cmd-git-status args) @@ -21,8 +22,10 @@ ([eq? state 'M] (list 'modified file)) ([eq? state 'A] (list 'added file)) ([eq? state 'D] (list 'deleted file)) - ([eq? state 'AM] (list 'modified-added file)) - ([eq? state 'AD] (list 'deleted-added file)) + ([eq? state 'AM] (list 'modified file)) + ([eq? state 'AD] (list 'deleted file)) + ([eq? state 'MM] (list 'modified file)) + ([eq? state 'MD] (list 'deleted file)) (else (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 - (begin - (git-displ out) - result) - (git-error 'add "Error" out))))) - \ No newline at end of file + + + +(define-syntax def-proxy-cmd + (syntax-rules () + ((_ f cmd) + (define (f args) + (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) + diff --git a/private/git-provider.rkt b/private/git-provider.rkt index a3b9766..68d40cf 100644 --- a/private/git-provider.rkt +++ b/private/git-provider.rkt @@ -150,6 +150,7 @@ (define (git-displ out) (let ((str (if (string? out) out (string-join out "\n")))) - (info-git str) - (when (cfg-get 'git 'display-output #t) - (displayln str)))) \ No newline at end of file + (unless (string=? (string-trim str) "") + (info-git str) + (when (cfg-get 'git 'display-output #t) + (displayln str)))))