Skip to main content

Module Git

Module Git 

Source
Expand description

§Local Git subprocess handlers

Mirrors stock VS Code’s ILocalGitService API (src/vs/platform/git/common/localGitService.ts) plus two Land-specific extensions: HandleExec for arbitrary argv (used by the Git extension) and HandleIsAvailable for synchronous feature detection.

Cancellation discipline: every long-running entry point takes an operationId; the spawned PID is registered in Shared::RunningProcesses for the duration of the run. HandleCancel(operationId) looks the PID up and SIGTERMs / taskkills it so the renderer can fire cancel from a different tauri::invoke than the one that started the operation.

Layout (one export per file, file name = identity):

  • HandleExec::HandleExec - arbitrary argv (object or positional shape).
  • HandleClone::HandleClone, HandlePull::HandlePull, HandleCheckout::HandleCheckout, HandleRevParse::HandleRevParse, HandleFetch::HandleFetch, HandleRevListCount::HandleRevListCount - curated git operations.
  • HandleCancel::HandleCancel - SIGTERM / taskkill by op id.
  • HandleIsAvailable::HandleIsAvailable - cached git --version probe.

Shared (private) - RunGit, the process registry, and small parsers.

Modules§

HandleCancel
localGit:cancel(operationId) - SIGTERM (Unix) or taskkill /T /F (Windows) the pid stashed for OperationId. Silent no-op when the id is unknown so late-arriving cancels for already-finished operations don’t spam errors.
HandleCheckout
localGit:checkout(operationId, repoPath, treeish, detached?). Detached=true adds --detach so the caller can land on a commit hash without creating a tracking branch.
HandleClone
localGit:clone(operationId, cloneUrl, targetPath, ref?). Optional ref becomes --branch <ref> so callers can shallow-clone a tag or branch.
HandleExec
localGit:exec - arbitrary git argv. Used by the Git extension for commands not on the curated clone/pull/… list. Accepts both the modern { Arguments, cwd?, operationId? } shape and the legacy positional (argv: string[], cwd?: string).
HandleFetch
localGit:fetch(operationId, repoPath). Plain git fetch against the configured upstream - no remote argument, no --all, mirroring stock VS Code’s LocalGitService.fetch.
HandleIsAvailable
localGit:isAvailable -> bool. Cheap git --version probe cached in a OnceLock for the process lifetime so the UI’s periodic poll doesn’t re-exec git every interval.
HandlePull
localGit:pull(operationId, repoPath) -> bool. Three-call sequence: read HEAD, pull --ff-only, read HEAD again. Returns true when the second HEAD differs from the first (i.e. the pull actually moved the branch). --ff-only avoids surprise merge commits - callers handle non-FF cases explicitly.
HandleRevListCount
localGit:revListCount(repoPath, fromRef, toRef) -> u64. Equivalent to git rev-list --count from..to - counts commits the GitLens / SCM viewlet “ahead/behind” badges display.
HandleRevParse
localGit:revParse(repoPath, ref) -> string. Defaults ref=HEAD so the caller can pass two args or three. Output is trimmed - git rev-parse ships a trailing newline that breaks string equality on the JS side.
Shared 🔒
Shared helpers for the Git/* atomic handlers. Holds: