Expand description
Core library for git-workon, an opinionated git worktree workflow tool.
This crate (published as workon) provides the building blocks for cloning,
initialising, and managing git repositories in a bare-repo-plus-worktrees layout.
§Key types
WorktreeDescriptor— wraps a git2Worktreewith rich metadata methodsBranchType— controls how a branch is created for a new worktreeWorkonConfig— readsworkon.*settings from git configPullRequest/PrMetadata— PR reference parsing and gh CLI integrationMoveOptions— options formove_worktreeWorkonErrorand its sub-types — all error variants with miette diagnostics
§Key functions
| Function | Description |
|---|---|
clone | Clone a remote repository into the worktrees layout |
init | Initialise a new bare repository with an initial commit |
get_repo | Discover and open a bare repository from a path |
get_worktrees | List all worktrees in a repository |
add_worktree | Create a new worktree (normal, orphan, or detached) |
find_worktree | Locate a worktree by name or branch |
current_worktree | Return the worktree containing the current directory |
move_worktree | Atomically rename a worktree and its branch |
copy_untracked | Copy untracked files between worktrees using git status |
workon_root | Resolve the directory that holds all worktrees |
§Example
use workon::{get_repo, get_worktrees, add_worktree, BranchType};
let repo = get_repo(None)?;
for wt in get_worktrees(&repo)? {
println!("{}: {}", wt.name().unwrap_or("?"), wt.path().display());
}
let wt = add_worktree(&repo, "my-feature", BranchType::Normal, None)?;
println!("Created: {}", wt.path().display());Structs§
- Clone
Options - Options for
clone. - Copy
Options - Options for
copy_untracked. - Default
Branch - Builder for resolving the default branch name of a repository or remote.
- Move
Options - Options for moving a worktree
- PrMetadata
- PR metadata fetched from the
ghCLI. - Pull
Request - A parsed pull request reference from user input.
- Workon
Config - Configuration reader for workon settings stored in git config.
- Worktree
Descriptor - A handle to a git worktree with rich metadata access.
Enums§
- Branch
Type - Type of branch to create for a new worktree
- Config
Error - Configuration-related errors
- Copy
Error - File copy errors
- Default
Branch Error - Default branch detection errors
- PrError
- Pull request-related errors
- Repo
Error - Repository-specific errors
- Workon
Error - Main error type for the workon library
- Worktree
Error - Worktree-specific errors
Functions§
- add_
worktree - Create a new worktree for the given branch.
- check_
gh_ available - Return
Ok(())if theghCLI is installed and reachable inPATH. - clone
- Clone a remote repository into the worktrees layout.
- convert_
to_ bare - Convert a standard git repository into the worktrees layout.
- copy_
untracked - Copy only untracked (and optionally ignored) files from source to destination.
- current_
worktree - Return the worktree that contains the current working directory.
- detect_
pr_ remote - Select which remote to use for fetching PR refs.
- empty_
commit - Create an empty initial commit on HEAD with no parents.
- fetch_
branch - Fetch
branchfromremote_name, making it available asrefs/remotes/{remote_name}/{branch}. - fetch_
pr_ metadata - Fetch PR metadata for
pr_numberusing theghCLI. - find_
worktree - Find a worktree by its name or by its branch name.
- format_
pr_ name - Format a PR worktree name using the format string
- format_
pr_ name_ with_ metadata - Expand all placeholders in
formatusingmetadata. - get_
default_ branch - Get the default branch name for a repository, validated to exist.
- get_
default_ branch_ name - Convenience wrapper around
DefaultBranch. - get_
remote_ callbacks - Build
git2::RemoteCallbacksthat handle credential prompts via the system credential store (SSH keys, keychain, etc.). - get_
repo - Discover and open a bare repository from
path(or the current directory). - get_
worktrees - Return all worktrees registered with the repository.
- init
- Initialise a new bare repository at
pathin the worktrees layout. - is_
pr_ reference - Check if a string looks like a PR reference
- move_
worktree - Move (rename) a worktree and its branch atomically.
- parse_
pr_ reference - Parse a PR reference from user input
- prepare_
pr_ worktree - Prepare everything needed to create a worktree for PR
pr_number. - set_
upstream_ tracking - Set upstream tracking for a worktree branch
- setup_
fork_ remote - Ensure a remote for a fork PR exists, then return its name.
- validate_
move - Validate that a move from
sourcetotarget_nameis safe to perform. - workon_
root - Resolve the directory that contains all worktrees for the repository.
Type Aliases§
- Result
- Result type alias using WorkonError