Documentation
¶
Overview ¶
Package git provides Git utility functions for Chief.
Index ¶
- func AddChiefToGitignore(dir string) error
- func BranchExists(dir, branchName string) (bool, error)
- func CheckGHCLI() (installed bool, authenticated bool, err error)
- func CommitCount(repoDir, branch string) int
- func CreateBranch(dir, branchName string) error
- func CreatePR(dir, branch, title, body string) (string, error)
- func CreateWorktree(repoDir, worktreePath, branch string) error
- func DeleteBranch(repoDir, branch string) error
- func DetectOrphanedWorktrees(baseDir string) map[string]string
- func FindCommitForStory(dir, storyID, title string) (string, error)
- func GetCurrentBranch(dir string) (string, error)
- func GetDefaultBranch(repoDir string) (string, error)
- func GetDiff(dir string) (string, error)
- func GetDiffForCommit(dir, commitHash string) (string, error)
- func GetDiffStats(dir string) (string, error)
- func GetDiffStatsForCommit(dir, commitHash string) (string, error)
- func IsChiefIgnored(dir string) bool
- func IsGitRepo(dir string) bool
- func IsProtectedBranch(branch string) bool
- func IsWorktree(path string) bool
- func MergeBranch(repoDir, branch string) ([]string, error)
- func PRBodyFromPRD(p *prd.PRD) string
- func PRTitleFromPRD(prdName string, p *prd.PRD) string
- func PromptAddChiefToGitignore() bool
- func PruneWorktrees(repoDir string) error
- func PushBranch(dir, branch string) error
- func RemoveWorktree(repoDir, worktreePath string) error
- func WorktreePathForPRD(baseDir, prdName string) string
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddChiefToGitignore ¶
AddChiefToGitignore adds .chief to the local .gitignore file. Creates the file if it doesn't exist.
func BranchExists ¶
BranchExists returns true if a branch with the given name exists.
func CheckGHCLI ¶
CheckGHCLI validates that the GitHub CLI is installed and authenticated.
func CommitCount ¶
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 ¶
CreateBranch creates a new branch and switches to it.
func CreateWorktree ¶
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 ¶
DeleteBranch deletes a local branch.
func DetectOrphanedWorktrees ¶
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 ¶
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 ¶
GetCurrentBranch returns the current git branch name for a directory.
func GetDefaultBranch ¶
GetDefaultBranch detects the default branch (main or master) for a repository.
func GetDiff ¶
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 ¶
GetDiffForCommit returns the diff for a single commit using git show.
func GetDiffStats ¶
GetDiffStats returns a short diffstat summary.
func GetDiffStatsForCommit ¶
GetDiffStatsForCommit returns the diffstat for a single commit.
func IsChiefIgnored ¶
IsChiefIgnored checks if .chief is gitignored either locally or globally. Returns true if .chief is already ignored, false otherwise.
func IsProtectedBranch ¶
IsProtectedBranch returns true if the branch name is main or master.
func IsWorktree ¶
IsWorktree checks if a path is a valid git worktree.
func MergeBranch ¶
MergeBranch merges a branch into the current branch, returning conflicting file list on failure.
func PRBodyFromPRD ¶
PRBodyFromPRD generates a PR body with a summary and list of completed stories.
func PRTitleFromPRD ¶
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 ¶
PruneWorktrees runs `git worktree prune` to clean up stale worktree tracking.
func RemoveWorktree ¶
RemoveWorktree removes a git worktree at the given path.
func WorktreePathForPRD ¶
WorktreePathForPRD returns the worktree path for a given PRD name.