class
Agate::Worktree
- Agate::Worktree
- Reference
- Object
Overview
Represents a git worktree (linked working directory).
# List worktrees
repo.worktrees # => ["feature-branch"]
# Add a new worktree
wt = Worktree.add(repo, "feature", "/tmp/feature-wt")
wt.name # => "feature"
wt.path # => "/tmp/feature-wt"
# Look up an existing worktree
wt = Worktree.lookup(repo, "feature")
wt.valid? # => true
wt.locked? # => false
# Lock/unlock
wt.lock("on USB drive")
wt.locked? # => true
wt.lock_reason # => "on USB drive"
wt.unlock
# Prune (remove)
wt.prune
Defined in:
agate/worktree.crConstructors
-
.add(repo : Repository, name : String, path : String | Path) : Worktree
Adds a new worktree to the repository.
-
.lookup(repo : Repository, name : String) : Worktree
Looks up a worktree by name.
-
.open_from_repository(repo : Repository) : Worktree
Opens the worktree for a repository that is itself a worktree.
Class Method Summary
-
.list(repo : Repository) : Array(String)
Lists the names of all linked worktrees for a repository.
-
.lookup?(repo : Repository, name : String) : Worktree | Nil
Looks up a worktree by name, returning nil if not found.
Instance Method Summary
-
#lock(reason : String | Nil = nil) : Nil
Locks the worktree with an optional reason.
-
#lock_reason : String | Nil
Returns the lock reason, or nil if not locked.
-
#locked? : Bool
Returns true if the worktree is locked.
-
#name : String
Returns the worktree name.
-
#path : Path
Returns the filesystem path of the worktree.
-
#prunable?(flags : PruneFlags = PruneFlags::None) : Bool
Returns true if the worktree can be pruned with the given flags.
-
#prune(flags : PruneFlags = PruneFlags::None) : Nil
Prunes (removes) the worktree, deleting the git data structures.
-
#unlock : Bool
Unlocks the worktree.
-
#valid? : Bool
Returns true if the worktree is valid (both git data structures and working copy are present).
Constructor Detail
Adds a new worktree to the repository. Checks out HEAD at the given path.
Looks up a worktree by name. Raises on failure.
Opens the worktree for a repository that is itself a worktree.
Class Method Detail
Lists the names of all linked worktrees for a repository.
Looks up a worktree by name, returning nil if not found.
Instance Method Detail
Returns true if the worktree can be pruned with the given flags.
Prunes (removes) the worktree, deleting the git data structures. By default only prunes if the worktree is invalid and unlocked. Pass flags to override these checks.
Unlocks the worktree. Returns true if the worktree was locked, false if it was already unlocked.
Returns true if the worktree is valid (both git data structures and working copy are present).