new version with git help

This commit is contained in:
2026-08-11 22:35:01 +02:00
parent fea7fb7a59
commit 7c6a338326
7 changed files with 175 additions and 19 deletions
+66
View File
@@ -9,12 +9,16 @@
racket/match
racket/path
racket/string
net/sendurl
setup/xref
scribble/xref
"credentials.rkt"
libgit2)
(provide git
dgit
git-version
git-help
git-repository?
git-root
git-init
@@ -80,6 +84,63 @@
(error 'git-version "cannot read info.rkt"))
(info 'version (lambda () (error 'git-version "info.rkt has no version"))))
(define git-help-bindings
(hash 'version 'git-version
'init 'git-init
'clone 'git-clone
'status 'git-status
'diff 'git-diff
'add 'git-add
'restore 'git-restore
'reset 'git-reset
'grep 'git-grep
'config 'git-config
'commit 'git-commit
'branch-current 'git-current-branch
'branch 'git-branch
'branch-create 'git-branch-create
'switch 'git-switch
'checkout 'git-checkout
'merge 'git-merge
'tag 'git-tag
'log 'git-log
'remote 'git-remotes
'fetch 'git-fetch
'pull 'git-pull
'push 'git-push
'push-tag 'git-push-tag
'credentials 'git-credentials-init!
'prompt 'git-prompt
'git-prompt 'git-prompt
'help 'git-help))
(define (git-help [topic #f])
(unless (or (not topic) (symbol? topic))
(raise-argument-error 'git-help "(or/c #f symbol?)" topic))
(define binding
(if topic
(hash-ref git-help-bindings topic
(lambda ()
(error 'git-help "unknown help topic: ~a" topic)))
'git))
;; Use Racket's installed-documentation cross-reference database instead of
;; guessing where raco setup placed this package's generated HTML.
(define xref (load-collections-xref))
(define tag
(xref-binding->definition-tag xref (list 'git binding) #f))
(unless tag
(error 'git-help
"documentation for ~a is not indexed; run raco setup git"
binding))
(define-values (path anchor)
(xref-tag->path+anchor xref tag))
(unless path
(error 'git-help
"documentation for ~a is indexed but has no local path"
binding))
(send-url/file path #:fragment anchor)
(void))
(define zero-oid-string (make-string GIT_OID_HEXSZ #\0))
(define branch-prefix "refs/heads/")
(define tag-prefix "refs/tags/")
@@ -1170,6 +1231,11 @@
(unless (null? args)
(error 'git "version takes no arguments"))
(git-version)]
[(help)
(match args
['() (git-help)]
[(list topic) (git-help topic)]
[_ (error 'git "help takes zero or one topic")])]
[(init) (apply git-init args)]
[(clone) (keyword-apply git-clone '(#:quiet) (list quiet) args)]
[(status) (apply git-status args)]