Skip to main content

diff

Function diff 

Source
pub async fn diff(
    repo_path: PathBuf,
    base_branch: String,
) -> Result<String, GitError>
Expand description

Re-exported commit/sync/diff APIs. Returns the output of git diff for the given repository path, showing all changes (committed and uncommitted) relative to the base branch.

Uses git add --intent-to-add to mark untracked files in the index, then finds the merge-base between HEAD and base_branch to diff against the fork point. To avoid re-showing squash-merged/cherry-picked session commits on non-rebased branches, this also checks git cherry and, when applicable, diffs from the last leading commit already applied to base_branch. Finally resets the index to restore the original state.

§Arguments

  • repo_path - Path to the git repository or worktree
  • base_branch - Branch to diff against (e.g., main)

§Returns

The diff output as a string.

§Errors

Returns a GitError if preparing the index, generating the diff, or restoring index state fails.