lmgit guide

Typed Git repository model, dual dry-run architecture, report findings sink, and standard lmcode_std_v3 REST and CLI interfaces in lmgit.

Overview

lmgit embeds the reviewed lmcode-go runtime and exposes local Git operations through a strict schema contract (schema/lmgit.dsl.json). Every Git command runs as an isolated subprocess with argument vectors only, eliminating shell interpolation while returning full stdout, stderr, and commit histories without arbitrary output ceilings.

Repository, status, branch, and commit objects

Inside an _lmcode_ block, the global git context provides git.version(), git.open(path), and git.clone(url, dest). A Repo handle exposes three categories of methods:

p = _lmcode_ cli="lmgit";
let r = git.open(".");
let entries = r.status();
for (i in range(0, entries.len())) {
  let e = entries.at(i);
  if (e.work_status() != " ") {
    report.add("DIRTY_WORKTREE", e.path(), "uncommitted change (" + e.work_status() + ")");
  }
}
report.fail_if_any();
end _lmcode_

Dual dry-run policy

lmgit distinguishes two complementary dry-run layers:

  1. Operation-level dry_run (git.dry_run(true)): Used during live execution so read methods run real Git commands against the repository while write methods (checkout, branch_create, commit, push, tag_create) record their intended actions without modifying the repository.
  2. Invocation-level dry mode (LMCODE_INVOCATION_FILE with dry: true): Enforced by the lmcode-go SDK before any domain callback executes. All host callbacks return typed dummy values, git.is_dry_run() previews true, and no Git subprocess or report file write occurs.

Standard REST and stateless CLI interfaces

lmgit includes the full 226-signature lmcode_std_v3 standard catalog, supporting RestGet..RestOptions, RestHandler, CliCommand, CliOption, rest_config, rest_route, rest_serve, rest_stop, and rest_cli.

p = _lmcode_ cli="lmgit";
@"--repo"
fn opt_repo(x: RestExchange) -> void implements CliOption {
  x.set("repo", x.query("repo"));
}

@"branch"
fn cmd_branch(x: RestExchange) -> void implements CliCommand {
  let r = git.open(x.get("repo"));
  x.send("branch:" + r.current_branch());
}

@"/repo/tags"
fn get_tags(x: RestExchange) -> void implements RestGet {
  let r = git.open(".");
  x.json("{\"tags\":" + str(r.tags().len()) + "}");
}

rest_config("session", "global");
print(rest_cli(str_split("--repo=. branch", " ")));
print(rest_cli(str_split("/repo/tags", " ")));
end _lmcode_