From 2cb7e9310e035760e41705881492dd74e5a3036c Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Thu, 13 Aug 2026 02:00:08 +0200 Subject: [PATCH] Small changes. git main function is now a real function, not syntax --- info.rkt | 46 +++++++++++----------- main.rkt | 91 +++++++++++++++++++++++++++---------------- scribblings/git.scrbl | 3 +- 3 files changed, 82 insertions(+), 58 deletions(-) diff --git a/info.rkt b/info.rkt index f83ca6c..a55034b 100644 --- a/info.rkt +++ b/info.rkt @@ -1,23 +1,23 @@ -#lang info - -(define collection "git-cli") -(define pkg-desc "Command-line-like Git operations for Racket, interface to the git cli command") -(define version "0.3.10") -(define pkg-authors '("Hans Dijkema")) -(define license 'MIT) - -(define deps - '("base" - "simple-ini" - "simple-log" - "racket-index" - "scribble-lib" - "racket-makefile" - "package-zipper")) - -(define build-deps - '("rackunit-lib" - "racket-doc")) - -(define scribblings - '(("scribblings/git.scrbl" () ("Git")))) +#lang info + +(define collection "git-cli") +(define pkg-desc "Command-line-like Git operations for Racket, interface to the git cli command") +(define version "0.3.11") +(define pkg-authors '("Hans Dijkema")) +(define license 'MIT) + +(define deps + '("base" + "simple-ini" + "simple-log" + "racket-index" + "scribble-lib" + "racket-makefile" + "package-zipper")) + +(define build-deps + '("rackunit-lib" + "racket-doc")) + +(define scribblings + '(("scribblings/git.scrbl" () ("Git")))) \ No newline at end of file diff --git a/main.rkt b/main.rkt index 7d4a105..98a59e6 100644 --- a/main.rkt +++ b/main.rkt @@ -22,25 +22,29 @@ ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Provided commands +;; Internal variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define git-commands (make-hash)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Command invocation using 'git' +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; goal: Invoke a supported Git command through the command table. ;; pre: command is a registered Git command symbol. ;; post: The selected command has processed all supplied arguments. ;; result: The command-specific result. -(define-syntax git - (syntax-rules () - ((_ command b1 ...) - ((hash-ref git-commands command - (λ () - (error "Not a supported or recognized git command: " command))) - (list b1 ...))) - ) - ) + +(define (git command . args) + ((hash-ref git-commands command + (λ () + (error "Not a supported or recognized git command: " command))) + args)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Supporting functions +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (git-prompt p) (display p) @@ -76,6 +80,9 @@ (string-contains? line* "no changes added to commit")))) out)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Command definition macro +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-syntax def-cmd (syntax-rules () @@ -93,6 +100,10 @@ ) ) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Typical git commands +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; goal: Return the complete Git index and worktree status for every reported file. ;; pre: The current directory is inside a Git working tree. ;; post: Git status has been invoked with --porcelain. @@ -154,7 +165,9 @@ ;; post: Git pull has completed successfully or an exception has been raised. ;; result: #t after a successful pull. (def-cmd git-pull cmd-git-pull 'pull) + (def-cmd git-branch cmd-git-branch 'branch) + (def-cmd git-clone cmd-git-clone 'clone) ;; goal: Display the Git commit log. @@ -162,32 +175,9 @@ ;; post: Git log has completed successfully or an exception has been raised. ;; result: #t after successfully displaying the log. (def-cmd git-log cmd-git-log 'log) + (def-cmd git-rev-list cmd-git-rev-list 'rev-list) -(define (git-version . args) - (cmd-git-version args)) - -(define (cmd-git-version args) - (info-version ".")) - -(hash-set! git-commands 'version cmd-git-version) - -;; goal: Increment the package version in info.rkt. -;; pre: kind is 'maj, 'major, 'min, 'minor or 'patch. -;; post: The version definition in info.rkt has been updated. -;; result: The new version as a list containing major, minor and patch. -(define (git-new-version . args) - (cmd-git-new-version args)) - -(define (cmd-git-new-version args) - (when(null? args) - (error "git-new-version expects 'maj, 'major, 'min, 'minor or 'patch")) - (let ((kind (car args))) - (git-next-version kind ".") - (git-version))) - -(hash-set! git-commands 'new-version cmd-git-new-version) - (def-cmd git-diff cmd-git-diff 'diff (λ (args info) args) (λ (cmd exit-code result output out info) @@ -257,3 +247,36 @@ (def-cmd git-help cmd-git-help 'help) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Racket module versioning +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define (git-version . args) + (cmd-git-version args)) + +(define (cmd-git-version args) + (info-version ".")) + +(hash-set! git-commands 'version cmd-git-version) + +;; goal: Increment the package version in info.rkt. +;; pre: kind is 'maj, 'major, 'min, 'minor or 'patch. +;; post: The version definition in info.rkt has been updated. +;; result: The new version as a list containing major, minor and patch. +(define (git-new-version . args) + (cmd-git-new-version args)) + +(define (cmd-git-new-version args) + (when(null? args) + (error "git-new-version expects 'maj, 'major, 'min, 'minor or 'patch")) + (let ((kind (car args))) + (git-next-version kind ".") + (git-version))) + +(hash-set! git-commands 'new-version cmd-git-new-version) + + + + + + diff --git a/scribblings/git.scrbl b/scribblings/git.scrbl index 61ac4e0..7a79fd9 100644 --- a/scribblings/git.scrbl +++ b/scribblings/git.scrbl @@ -1,7 +1,8 @@ #lang scribble/manual @(require (for-label racket/base - git-cli)) + "../main.rkt")) +@;git-cli)) @title[#:tag "top"]{git-cli} @author{Hans Dijkema}