class Agate::Worktree

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.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.add(repo : Repository, name : String, path : String | Path) : Worktree #

Adds a new worktree to the repository. Checks out HEAD at the given path.


[View source]
def self.lookup(repo : Repository, name : String) : Worktree #

Looks up a worktree by name. Raises on failure.


[View source]
def self.open_from_repository(repo : Repository) : Worktree #

Opens the worktree for a repository that is itself a worktree.


[View source]

Class Method Detail

def self.list(repo : Repository) : Array(String) #

Lists the names of all linked worktrees for a repository.


[View source]
def self.lookup?(repo : Repository, name : String) : Worktree | Nil #

Looks up a worktree by name, returning nil if not found.


[View source]

Instance Method Detail

def lock(reason : String | Nil = nil) : Nil #

Locks the worktree with an optional reason.


[View source]
def lock_reason : String | Nil #

Returns the lock reason, or nil if not locked.


[View source]
def locked? : Bool #

Returns true if the worktree is locked.


[View source]
def name : String #

Returns the worktree name.


[View source]
def path : Path #

Returns the filesystem path of the worktree.


[View source]
def prunable?(flags : PruneFlags = PruneFlags::None) : Bool #

Returns true if the worktree can be pruned with the given flags.


[View source]
def prune(flags : PruneFlags = PruneFlags::None) : Nil #

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.


[View source]
def unlock : Bool #

Unlocks the worktree. Returns true if the worktree was locked, false if it was already unlocked.


[View source]
def valid? : Bool #

Returns true if the worktree is valid (both git data structures and working copy are present).


[View source]