Cleaned up the code. added some documentation.
This commit is contained in:
+71
-17
@@ -1,27 +1,81 @@
|
||||
#lang scribble/manual
|
||||
|
||||
@(require (for-label racket/base git))
|
||||
@(require (for-label racket/base
|
||||
git-cli))
|
||||
|
||||
@title[#:tag "top"]{git}
|
||||
@title[#:tag "top"]{git-cli}
|
||||
@author{Hans Dijkema}
|
||||
|
||||
@defmodule[git]
|
||||
@defmodule[git-cli]
|
||||
|
||||
The @racketmodname[git] module provides a small command-line-like Git interface implemented on top of the @tt{libgit2} package. It does not invoke the @tt{git} executable.
|
||||
The @racketmodname[git-cli] module provides a command-line-like Git interface
|
||||
implemented by invoking the @tt{git} executable. Commands never read from
|
||||
standard input.
|
||||
|
||||
The short form is intended for build scripts and interactive use:
|
||||
@defform[(git command argument ...)]{
|
||||
Runs a supported Git @racket[command]. The arguments are passed to the Git
|
||||
command. Supported commands include @racket['status], @racket['add],
|
||||
@racket['commit], @racket['push], @racket['pull], @racket['branch],
|
||||
@racket['clone], @racket['log], @racket['rev-list], @racket['diff],
|
||||
@racket['grep], @racket['help], @racket['version], and
|
||||
@racket['new-version].
|
||||
}
|
||||
|
||||
@defproc[(git-status [argument any/c] ...) list?]{
|
||||
Runs @tt{git status --porcelain} with the supplied arguments.
|
||||
|
||||
Each result item has the form
|
||||
@racket[(index-status worktree-status file)]. The index status describes the
|
||||
change staged for the next commit. The worktree status describes the change in
|
||||
the working tree relative to the index.
|
||||
|
||||
Both statuses are one of @racket['unchanged], @racket['modified],
|
||||
@racket['type-changed], @racket['added], @racket['deleted], @racket['renamed],
|
||||
@racket['copied], @racket['unmerged], @racket['untracked], or
|
||||
@racket['ignored]. For an untracked file, Git reports @tt{??}, so both statuses
|
||||
are @racket['untracked].
|
||||
|
||||
@racketblock[
|
||||
(require git)
|
||||
((modified unchanged "staged.rkt")
|
||||
(unchanged modified "working-tree.rkt")
|
||||
(modified modified "both.rkt")
|
||||
(renamed unchanged "old.rkt -> new.rkt")
|
||||
(untracked untracked "new.rkt"))
|
||||
]}
|
||||
|
||||
(git 'status)
|
||||
(git 'diff)
|
||||
(git 'diff '--cached)
|
||||
(git 'add "main.rkt" "info.rkt")
|
||||
(git 'restore '--staged "scratch.rkt")
|
||||
(git 'reset 'HEAD "--" "main.rkt")
|
||||
(git 'grep '-i '-n "todo")
|
||||
(git 'commit "Implement raco support")
|
||||
(git 'tag "v0.1")
|
||||
(git 'checkout "main")
|
||||
]
|
||||
@defproc[(git-add [argument any/c] ...) boolean?]{
|
||||
Adds file contents to the index. Returns @racket[#t] when Git exits with status
|
||||
zero; otherwise an exception is raised.
|
||||
}
|
||||
|
||||
@defproc[(git-commit [argument any/c] ...) boolean?]{
|
||||
Creates a commit. When @tt{-m} is omitted, a commit message is requested before
|
||||
Git is started. A repository with nothing to commit returns @racket[#t]. Other
|
||||
non-zero exit statuses, including a rejected commit hook, raise an exception.
|
||||
}
|
||||
|
||||
@defproc[(git-push [argument any/c] ...) boolean?]{
|
||||
Pushes changes using @tt{--porcelain}. Returns @racket[#t] when Git exits with
|
||||
status zero; otherwise an exception is raised.
|
||||
}
|
||||
|
||||
@defproc[(git-pull [argument any/c] ...) boolean?]{
|
||||
Fetches and integrates changes. Normal progress written by Git to standard
|
||||
error is treated as output when Git exits successfully.
|
||||
}
|
||||
|
||||
@defproc[(git-log [argument any/c] ...) boolean?]{
|
||||
Displays Git log output and returns @racket[#t] when Git exits successfully.
|
||||
}
|
||||
|
||||
@defproc[(git-grep [argument any/c] ...) list?]{
|
||||
Searches tracked files. Each result contains the file, optional line number,
|
||||
optional match count, and matched text. Exit status one means that no matches
|
||||
were found and returns an empty list.
|
||||
}
|
||||
|
||||
@defproc[(git-new-version [kind symbol?]) list?]{
|
||||
Updates the version in @filepath{info.rkt}. The kind is @racket['major],
|
||||
@racket['minor], or @racket['patch], with @racket['maj] and @racket['min] as
|
||||
abbreviations. The result is the new version as a list of three integers.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user