git

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package git provides Git utility functions for Chief.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddChiefToGitignore

func AddChiefToGitignore(dir string) error

AddChiefToGitignore adds .chief to the local .gitignore file. Creates the file if it doesn't exist.

func BranchExists

func BranchExists(dir, branchName string) (bool, error)

BranchExists returns true if a branch with the given name exists.

func CheckGHCLI

func CheckGHCLI() (installed bool, authenticated bool, err error)

CheckGHCLI validates that the GitHub CLI is installed and authenticated.

func CommitCount

func CommitCount(repoDir, branch string) int

CommitCount returns the number of commits on branch that are not on the default branch. Returns 0 if the count cannot be determined.

func CreateBranch

func CreateBranch(dir, branchName string) error

CreateBranch creates a new branch and switches to it.

func CreatePR

func CreatePR(dir, branch, title, body string) (string, error)

CreatePR creates a pull request via `gh pr create` and returns the PR URL.

func CreateWorktree

func CreateWorktree(repoDir, worktreePath, branch string) error

CreateWorktree creates a branch from the default branch and adds a worktree at the given path. If the worktree path already exists and is a valid worktree on the expected branch, it is reused. If the worktree path exists but is stale (wrong branch or invalid), it is removed and recreated.

func DeleteBranch

func DeleteBranch(repoDir, branch string) error

DeleteBranch deletes a local branch.

func DetectOrphanedWorktrees

func DetectOrphanedWorktrees(baseDir string) map[string]string

DetectOrphanedWorktrees scans .chief/worktrees/ and returns a map of PRD name -> absolute worktree path for worktrees that exist on disk. The caller is responsible for determining which are orphaned (i.e., have no corresponding registered/running PRD).

func FindCommitForStory

func FindCommitForStory(dir, storyID, title string) (string, error)

FindCommitForStory searches the git log for a commit whose subject line matches the chief commit format "feat: <storyID> - <title>". Both the story ID and title are required to avoid false positives from previous PRD runs that may reuse the same story IDs. Returns the commit hash if found, empty string otherwise.

func GetCurrentBranch

func GetCurrentBranch(dir string) (string, error)

GetCurrentBranch returns the current git branch name for a directory.

func GetDefaultBranch

func GetDefaultBranch(repoDir string) (string, error)

GetDefaultBranch detects the default branch (main or master) for a repository.

func GetDiff

func GetDiff(dir string) (string, error)

GetDiff returns the git diff output for the working directory. It shows the diff between the current branch and its merge base with the default branch. If on main/master or if merge-base fails, it shows the last few commits' diff.

func GetDiffForCommit

func GetDiffForCommit(dir, commitHash string) (string, error)

GetDiffForCommit returns the diff for a single commit using git show.

func GetDiffStats

func GetDiffStats(dir string) (string, error)

GetDiffStats returns a short diffstat summary.

func GetDiffStatsForCommit

func GetDiffStatsForCommit(dir, commitHash string) (string, error)

GetDiffStatsForCommit returns the diffstat for a single commit.

func IsChiefIgnored

func IsChiefIgnored(dir string) bool

IsChiefIgnored checks if .chief is gitignored either locally or globally. Returns true if .chief is already ignored, false otherwise.

func IsGitRepo

func IsGitRepo(dir string) bool

IsGitRepo returns true if the directory is inside a git repository.

func IsProtectedBranch

func IsProtectedBranch(branch string) bool

IsProtectedBranch returns true if the branch name is main or master.

func IsWorktree

func IsWorktree(path string) bool

IsWorktree checks if a path is a valid git worktree.

func MergeBranch

func MergeBranch(repoDir, branch string) ([]string, error)

MergeBranch merges a branch into the current branch, returning conflicting file list on failure.

func PRBodyFromPRD

func PRBodyFromPRD(p *prd.PRD) string

PRBodyFromPRD generates a PR body with a summary and list of completed stories.

func PRTitleFromPRD

func PRTitleFromPRD(prdName string, p *prd.PRD) string

PRTitleFromPRD generates a conventional-commits title for a PR. Format: feat(<prd-name>): <project name>

func PromptAddChiefToGitignore

func PromptAddChiefToGitignore() bool

PromptAddChiefToGitignore asks the user if they want to add .chief to .gitignore. Returns true if the user wants to add it, false otherwise.

func PruneWorktrees

func PruneWorktrees(repoDir string) error

PruneWorktrees runs `git worktree prune` to clean up stale worktree tracking.

func PushBranch

func PushBranch(dir, branch string) error

PushBranch pushes the branch to origin.

func RemoveWorktree

func RemoveWorktree(repoDir, worktreePath string) error

RemoveWorktree removes a git worktree at the given path.

func WorktreePathForPRD

func WorktreePathForPRD(baseDir, prdName string) string

WorktreePathForPRD returns the worktree path for a given PRD name.

Types

type Worktree

type Worktree struct {
	Path     string
	Branch   string
	HEAD     string
	Prunable bool
}

Worktree represents a git worktree entry.

func ListWorktrees

func ListWorktrees(repoDir string) ([]Worktree, error)

ListWorktrees parses `git worktree list --porcelain` and returns all worktrees.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL