Skip to main content

diff_ref_spec

Function diff_ref_spec 

Source
fn diff_ref_spec(target: &str) -> String
Expand description

Translate a caller-supplied diff target into the git ref-spec the underlying subprocess receives.

  • HEAD -> HEAD (two-dot semantics: working tree vs HEAD, which is what the user means by “uncommitted edits”).
  • Anything else (branch name, SHA) -> <target>...HEAD (three-dot semantics: diff from the merge-base of target and HEAD to HEAD, i.e. “what did THIS branch contribute”).

Why the asymmetry: after a squash-merge of the branch into the target, two-dot git diff main HEAD is empty (content already in main with a different SHA) while three-dot git diff main...HEAD still surfaces the branch’s contributions vs the merge-base. The Inspector GIT panel uses three-dot via forge_agent::env::git_diff::scan’s format!("{default}...HEAD") at the branch-ahead layer; this helper keeps the overlay scanner in sync so the panel + overlay never disagree on what’s diffable.