Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Native knowledge, plan, fix and configuration commands send the selected organiz

`proofline review --path src/main.rs` reviews only that file's local changes against the normal merge-base. The path is literal and repository-relative; the command refuses directories, globs, and `..`. Combine it with `--staged` to read the index, or `--include-untracked` to select a new, non-ignored file. The command preserves the real index and applies the usual secret preflight. You cannot combine `--path` with pushed-commit, range, or pull-request review.

`proofline review --base main` reviews the local changes against the merge-base of `HEAD` and `main` instead of the upstream or default branch, including commits you already pushed. Name the branch you build on: after a push, the upstream alone would leave the pushed commits out, and on a branch stacked on another, naming the parent reviews only the stacked branch's commits. GitHub must have the merge-base, so the command refuses one that no remote-tracking branch contains before it sends anything. Combine it with `--staged`, `--include-untracked`, `--path`, `--verify`, or `--allow-path`; you cannot combine it with pushed-commit, range, file, or pull-request review.

`proofline reviews --repository-id UUID --cursor CURSOR` returns one page with its continuation metadata, and all flags are optional. `proofline routing REVIEW_ID` reads recorded routing. `proofline run --repo owner/name --pr 7 --run 2` reads one retained run, and `proofline history --repo owner/name --pr 7` reads all recorded runs. Both commands send the API the name without its owner, and use the response only when its repository choices list `owner/name`, or the Git remote's owner and name, among the organization's reviewed repositories. A repository with no reviews in the organization exits nonzero. `proofline findings --pr 7` finds the pull request's newest review through the same route and counts only runs of the repository whose full name matches. None of these commands reads the organization's review list.

`proofline rerun REVIEW_ID` requests the original immutable subject and waits, while `--no-wait` returns its link. Reruns require `reviews:rerun`. `proofline guidance --repo owner/name` requires `guidance:read`, and `proofline fix-prompt FINDING_ID` requires `findings:read`. History, guidance, and fix prompts print JSON; prompt text remains untrusted.
Expand Down
57 changes: 52 additions & 5 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub enum GitError {
"the checkout has no base to review against: set an upstream branch with `git branch --set-upstream-to`, or run `git remote set-head {0} --auto`"
)]
NoBase(String),
#[error(
"the merge-base {base} of HEAD and {revision:?} is on no remote-tracking branch, so GitHub may not have it; push {revision:?}, or pass --base a revision that is already pushed"
)]
UnpushedBase { base: String, revision: String },
#[error("HEAD and {0:?} have no commit in common, so there is no base to review against")]
NoCommonBase(String),
#[error("the local changes include text that is not UTF-8, which Proofline cannot review")]
NotUtf8,
#[error("the local changes make a {0} MiB patch; Proofline reviews patches up to 5 MiB")]
Expand Down Expand Up @@ -239,6 +245,40 @@ async fn base(dir: &Path, remote: &str) -> Result<String, GitError> {
merge_base(dir, remote, "HEAD", &["@{upstream}", default.as_str()]).await
}

/// The merge-base of `HEAD` with the commit `revision` names, the base a
/// pull request from `HEAD` into it would have. GitHub must have the base,
/// so one that no remote-tracking branch contains is refused here, before
/// anything is sent.
async fn named_base(dir: &Path, revision: &str) -> Result<String, GitError> {
let commit = resolve(dir, revision).await?;
let base = line_in(dir, &["merge-base", "HEAD", &commit])
.await
.map_err(|error| match error {
GitError::Failed { .. } => GitError::NoCommonBase(revision.to_owned()),
error => error,
})?;
let base = commit_sha(&base)?;
let pushed = line_in(
dir,
&[
"for-each-ref",
"--count=1",
"--format=%(refname)",
"--contains",
&base,
"refs/remotes/",
],
)
.await?;
if pushed.is_empty() {
return Err(GitError::UnpushedBase {
base,
revision: revision.to_owned(),
});
}
Ok(base)
}

/// Which local bytes contribute to the patch against its pinned base.
#[derive(Debug, Clone, Copy)]
pub enum LocalSelection {
Expand All @@ -250,17 +290,22 @@ pub enum LocalSelection {
IncludeUntracked,
}

/// Local changes against one merge-base. A copied index collects the selected
/// bytes, so the person's index is untouched.
/// Local changes against one merge-base: with `base_revision` when the person
/// names one, otherwise with the upstream or default branch. A copied index
/// collects the selected bytes, so the person's index is untouched.
pub async fn local_changes(
dir: &Path,
remote: &str,
base_revision: Option<&str>,
selection: LocalSelection,
path: Option<&str>,
) -> Result<LocalChanges, GitError> {
let root = line_in(dir, &["rev-parse", "--show-toplevel"]).await?;
let root = Path::new(&root);
let base_commit_sha = base(root, remote).await?;
let base_commit_sha = match base_revision {
Some(revision) => named_base(root, revision).await?,
None => base(root, remote).await?,
};
let scratch = tempfile::tempdir()
.map_err(|error| GitError::Unavailable(format!("no temporary directory: {error}")))?;
let index = scratch.path().join("index");
Expand Down Expand Up @@ -705,7 +750,7 @@ mod tests {
],
);

let unchanged = local_changes(dir, "origin", LocalSelection::Tracked, None)
let unchanged = local_changes(dir, "origin", None, LocalSelection::Tracked, None)
.await
.unwrap();
assert_eq!(
Expand Down Expand Up @@ -749,7 +794,9 @@ mod tests {
],
),
] {
let changes = local_changes(dir, "origin", selection, None).await.unwrap();
let changes = local_changes(dir, "origin", None, selection, None)
.await
.unwrap();
assert_eq!(changes.base_commit_sha, base);
let mut expected = vec![
"diff --git a/committed.txt b/committed.txt",
Expand Down
2 changes: 1 addition & 1 deletion src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ async fn subjects(hook: Hook, here: &Path, remote: &str) -> anyhow::Result<(Vec<
Hook::PreCommit => Ok((
vec![Subject {
label: "the staged changes".to_owned(),
changes: git::local_changes(here, remote, LocalSelection::Staged, None).await,
changes: git::local_changes(here, remote, None, LocalSelection::Staged, None).await,
}],
0,
)),
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ struct ReviewArgs {
pr: Option<u64>,
#[command(flatten)]
local_selection: LocalSelectionArgs,
/// Review the local changes against the merge-base of HEAD and this
/// revision instead of the upstream or default branch, including commits
/// already pushed. The name is resolved once in the checkout; a
/// remote-tracking branch must contain the merge-base, so GitHub has it.
#[arg(
long,
value_name = "REVISION",
conflicts_with_all = ["pr", "commit", "range", "files"]
)]
base: Option<String>,
/// Review the change this pushed commit makes against its first parent.
/// The name is resolved once in the checkout; GitHub must have both commits.
/// With --files, review complete selected files at that commit instead.
Expand Down Expand Up @@ -1068,8 +1078,9 @@ async fn review(api: &Api, args: &ReviewArgs) -> anyhow::Result<Verdict> {
finish(api, requested.review_id, args).await
}

/// Reviews the checkout's local changes against the commit they build on.
/// Nothing is pushed: GitHub needs only the base commit.
/// Reviews the checkout's local changes against the commit they build on, or
/// against the merge-base with `--base`. Nothing is pushed: GitHub needs only
/// the base commit.
async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result<Verdict> {
let selection = if args.local_selection.staged {
git::LocalSelection::Staged
Expand All @@ -1081,6 +1092,7 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result<Verdict> {
let changes = git::local_changes(
std::path::Path::new("."),
&args.repository.remote,
args.base.as_deref(),
selection,
args.path.as_deref(),
)
Expand Down
Loading