utils/git/git_diff_utils
library
Functions
-
clearRepositoryCaches()
→ void
-
Clear cached repository data.
-
deriveReviewState({required bool isDraft, required String reviewDecision})
→ PrReviewState
-
Derive review state from GitHub API values.
-
detectCurrentRepository({String? cwd})
→ Future<String?>
-
Detect the current repository (github.com only, "owner/repo").
-
detectCurrentRepositoryWithHost({String? cwd})
→ Future<ParsedRepository?>
-
Detect current repository including host.
-
dirIsInGitRepo(String cwd)
→ Future<bool>
-
Check if directory is in a git repo.
-
fetchGitDiff({String? cwd})
→ Future<GitDiffResult?>
-
Fetch git diff stats comparing working tree to HEAD.
Returns null if not in a git repo or during transient git states.
-
fetchGitDiffHunks({String? cwd})
→ Future<Map<String, List<StructuredPatchHunk>>>
-
Fetch git diff hunks on-demand.
-
fetchPrStatus({String? cwd})
→ Future<PrStatus?>
-
Fetch PR status for the current branch using
gh pr view.
-
fetchSingleFileGitDiff(String absoluteFilePath)
→ Future<ToolUseDiff?>
-
Fetch a structured diff for a single file against the merge base.
-
findCanonicalGitRoot(String startPath)
→ String?
-
Find the canonical git root, resolving through worktrees.
-
findGitRoot(String startPath)
→ String?
-
Find the git root by walking up the directory tree.
Looks for a .git directory or file (worktrees/submodules use a file).
-
findRemoteBase({String? cwd})
→ Future<String?>
-
Find the best remote branch to use as a base.
-
getBranch({String? cwd})
→ Future<String>
-
Get current branch name.
-
getCachedRepository({String? cwd})
→ String?
-
Return cached repository ("owner/name") for github.com, or null.
-
getChangedFiles({String? cwd})
→ Future<List<String>>
-
Get a list of changed files (porcelain output).
-
getDefaultBranch({String? cwd})
→ Future<String>
-
Get the default branch (main/master/etc).
-
getFileStatus({String? cwd})
→ Future<GitFileStatus>
-
Get file status (tracked vs untracked).
-
getGitDir(String cwd)
→ Future<String?>
-
Resolve the .git directory (handles worktrees).
-
getGithubRepo({String? cwd})
→ Future<String?>
-
Get the GitHub repo in "owner/repo" format.
-
getGitState({String? cwd})
→ Future<GitRepoState?>
-
Get the full git repository state.
-
getHead({String? cwd})
→ Future<String>
-
Get HEAD commit hash.
-
getIsClean({String? cwd, bool ignoreUntracked = false})
→ Future<bool>
-
Check if the working tree is clean.
-
getIsGit({String? cwd})
→ Future<bool>
-
Check if cwd is inside a git repository.
-
getIsHeadOnRemote({String? cwd})
→ Future<bool>
-
Check if HEAD is on a remote-tracking branch.
-
getRemoteUrl({String? cwd})
→ Future<String?>
-
Get the remote URL.
-
getRepoRemoteHash({String? cwd})
→ Future<String?>
-
Returns a SHA256 hash (first 16 chars) of the normalized git remote URL.
-
gitExe()
→ String
-
-
hasUnpushedCommits({String? cwd})
→ Future<bool>
-
Check if there are unpushed commits.
-
isAtGitRoot({String? cwd})
→ Future<bool>
-
Check if the cwd is at the git root.
-
isCurrentDirectoryBareGitRepo({String? cwd})
→ bool
-
Check if cwd looks like a bare git repo (security check).
-
isShallowClone({String? cwd})
→ Future<bool>
-
Check if in a shallow clone.
-
normalizeGitRemoteUrl(String url)
→ String?
-
Normalise a git remote URL to a canonical form for hashing.
Converts SSH and HTTPS URLs to: host/owner/repo (lowercase, no .git).
-
parseGitDiff(String stdout)
→ Map<String, List<StructuredPatchHunk>>
-
Parse unified diff output into per-file hunks.
-
parseGitHubRepository(String input)
→ String?
-
Parse a GitHub repository string or URL.
-
parseGitNumstat(String stdout)
→ NumstatResult
-
Parse git diff --numstat output.
-
parseGitRemote(String input)
→ ParsedRepository?
-
Parse a git remote URL into host, owner, and name.
-
parseShortstat(String stdout)
→ GitDiffStats?
-
Parse git diff --shortstat output.
-
preserveGitStateForIssue({String? cwd})
→ Future<PreservedGitState?>
-
Preserve git state for issue submission.
-
resolveCanonicalGitRoot(String gitRoot)
→ String
-
Resolve a git root to the canonical main repository root.
For worktrees follows .git file -> gitdir: -> commondir chain.
-
stashToCleanState({String? cwd, String? message})
→ Future<bool>
-
Stash all changes (including untracked) to return git to a clean state.