GitWorktree class abstract interface Getting started

Work tree and index of one repository: status, staging, reset, cleaning, checkout, ignore checks and commits.

Every command runs inside the owning repository's context, so a derived view (an alternate index, extra environment variables) applies here too. Operations that change state fail on git's refusals — a checkout that would overwrite local changes, a reset to an unknown revision — and raise GitUnknownRevisionException for a revision that names nothing, GitLocalChangesOverwrittenException for local state a checkout would overwrite, and GitException otherwise.

An expression that reads like an option — a revision or branch parameter starting with - — is not part of the grammar of GitRevisionResolver: it names nothing, and the operations that take one refuse with GitUnknownRevisionException before any command runs. The path parameters of add, intentToAdd and isIgnored are literal paths relative to the repository root: no glob (*, ?, [...]) and no magic :(...) syntax is interpreted. Where add or intentToAdd takes a list of paths, a directory path covers its content and . covers the whole repository.

final List<GitStatusEntry> changes = await working.worktree.status();
final bool clean = await working.worktree.isClean();
await working.worktree.addAll();
await working.worktree.add(<String>['app.txt']);
final GitOid made = await working.worktree.commit('Add the notes');
await working.worktree.checkoutNewBranch('topic');
await working.worktree.reset(mode: GitResetMode.hard);
await working.worktree.clean(directories: true);

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(List<String> paths) → Future<void>
Stages paths (git add), work tree changes and removals included.
addAll() → Future<void>
Stages every change of the work tree, untracked files and deletions included, except ignored files (git add -A).
checkout(String branch) → Future<void>
Switches the work tree to branch, updating HEAD, the index and the files on disk.
checkoutDetached(String rev) → Future<void>
Detaches HEAD at rev, a revision expression of the grammar documented on GitRevisionResolver, updating the index and the files on disk.
checkoutNewBranch(String name, {String? startPoint, bool resetIfExists = false}) → Future<void>
Creates the branch name at startPoint (default: HEAD) and checks it out (git checkout -b).
clean({bool directories = false}) → Future<void>
Removes untracked files (git clean -f).
commit(String message, {GitIdentity? identity, bool allowEmpty = false}) → Future<GitOid>
Commits the staged changes with message and returns the new commit's object name.
intentToAdd(List<String> paths) → Future<void>
Records the intent to add paths without staging their content (git add -N), the usual preparation for a diff of new files.
isClean() → Future<bool>
Whether the index and the work tree hold no change at all — no staged, unstaged or untracked path. Ignored files do not count.
isIgnored(String path, {bool noIndex = false}) → Future<bool>
Whether path is ignored by the repository's ignore rules (git check-ignore).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset({GitResetMode mode = GitResetMode.mixed, String? target}) → Future<void>
Moves HEAD to target and updates the index and work tree according to mode.
scanConflictMarkers(List<String> paths) → Future<List<GitConflictRegion>>
Scans paths of the work tree for real conflict markers, line by line.
status() → Future<List<GitStatusEntry>>
Status of every path that differs between HEAD, the index and the work tree, as git reports it.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited