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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Native knowledge, plan, fix and configuration commands send the selected organiz

## Reviews, history, and reruns

`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 --path src/main.rs` reviews only that file's local changes against the normal merge-base. Repeat it, as in `--path src/main.rs --path src/lib.rs`, to review several files in one review; name both sides of a rename to review it as a rename. Each path is literal and repository-relative; the command refuses directories, globs, and `..`, and one refused path stops the whole review before anything is sent. When the local changes are too large, have too many files or include text that is not UTF-8, the refusal suggests `--path` to review the files that matter. 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 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. These commands can find the reviews your token can still read after a repository disconnects. With a clone URL or Git remote, they resolve the project on its registered host and read its runs by repository ID. 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.

Expand Down
92 changes: 45 additions & 47 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub async fn local_changes(
dir: &Path,
remote: &str,
selection: LocalSelection,
path: Option<&str>,
paths: &[String],
) -> Result<LocalChanges, GitError> {
let root = line_in(dir, &["rev-parse", "--show-toplevel"]).await?;
let root = Path::new(&root);
Expand All @@ -298,10 +298,8 @@ pub async fn local_changes(
)
.await?;
}
if let Some(path) = path {
check_one_path(root, &index, &base_commit_sha, path).await?;
}
diff(root, Some(&index), base_commit_sha, None, path).await
check_paths(root, &index, &base_commit_sha, paths).await?;
diff(root, Some(&index), base_commit_sha, None, paths).await
}

/// Copies the repository's index to `index`. A repository with nothing
Expand All @@ -322,49 +320,49 @@ async fn copy_index(root: &Path, index: &Path) -> Result<(), GitError> {
}

/// Refuses a `--path` that is not one literal file: a malformed segment, a
/// directory in the scratch `index` or the base, or a path in neither.
async fn check_one_path(
/// directory in the scratch `index` or the base, or a path in neither. Git
/// lists every selected path in one call to the index and one to the base.
async fn check_paths(
root: &Path,
index: &Path,
base_commit_sha: &str,
path: &str,
paths: &[String],
) -> Result<(), GitError> {
if path.contains('\0') || path.split('/').any(|part| matches!(part, "" | "." | "..")) {
return Err(GitError::InvalidLocalPath(path.to_owned()));
if paths.is_empty() {
return Ok(());
}
let indexed = git_in(
root,
Some(index),
&["--literal-pathspecs", "ls-files", "-z", "--", path],
)
.await?;
let base_paths = git_in(
root,
None,
&[
"--literal-pathspecs",
"ls-tree",
"-r",
"--name-only",
"-z",
base_commit_sha,
"--",
path,
],
)
.await?;
let exact = |entries: &[u8]| {
entries
.split(|byte| *byte == 0)
.any(|entry| entry == path.as_bytes())
};
let prefix = format!("{path}/");
let descendants = indexed
if let Some(path) = paths.iter().find(|path| {
path.contains('\0') || path.split('/').any(|part| matches!(part, "" | "." | ".."))
}) {
return Err(GitError::InvalidLocalPath(path.clone()));
}
let mut ls_files = vec!["--literal-pathspecs", "ls-files", "-z", "--"];
ls_files.extend(paths.iter().map(String::as_str));
let indexed = git_in(root, Some(index), &ls_files).await?;
let mut ls_tree = vec![
"--literal-pathspecs",
"ls-tree",
"-r",
"--name-only",
"-z",
base_commit_sha,
"--",
];
ls_tree.extend(paths.iter().map(String::as_str));
let base_paths = git_in(root, None, &ls_tree).await?;
let entries: Vec<&[u8]> = indexed
.split(|byte| *byte == 0)
.chain(base_paths.split(|byte| *byte == 0))
.any(|entry| entry.starts_with(prefix.as_bytes()));
if descendants || (!exact(&indexed) && !exact(&base_paths)) {
return Err(GitError::InvalidLocalPath(path.to_owned()));
.collect();
for path in paths {
let prefix = format!("{path}/");
let exact = entries.contains(&path.as_bytes());
let descendants = entries
.iter()
.any(|entry| entry.starts_with(prefix.as_bytes()));
if descendants || !exact {
return Err(GitError::InvalidLocalPath(path.clone()));
}
}
Ok(())
}
Expand All @@ -375,7 +373,7 @@ async fn check_one_path(
pub async fn range_changes(dir: &Path, base: &str, head: &str) -> Result<LocalChanges, GitError> {
let root = line_in(dir, &["rev-parse", "--show-toplevel"]).await?;
let head = commit_sha(head)?;
diff(Path::new(&root), None, commit_sha(base)?, Some(&head), None).await
diff(Path::new(&root), None, commit_sha(base)?, Some(&head), &[]).await
}

/// The base of a branch the remote does not have yet: its merge-base with
Expand All @@ -386,13 +384,13 @@ pub async fn new_branch_base(dir: &Path, remote: &str, head: &str) -> Result<Str
}

/// The patch from `base_commit_sha` to `head`, or to `index` when `head` is
/// `None`.
/// `None`, limited to `paths` when any are named.
async fn diff(
root: &Path,
index: Option<&Path>,
base_commit_sha: String,
head: Option<&str>,
path: Option<&str>,
paths: &[String],
) -> Result<LocalChanges, GitError> {
let mut args = vec![
"--literal-pathspecs",
Expand Down Expand Up @@ -431,7 +429,7 @@ async fn diff(
]);
args.extend(head);
args.push("--");
args.extend(path);
args.extend(paths.iter().map(String::as_str));
let output = git_in(root, index, &args).await?;
let (paths, patch) = diff_paths(&output)?;
if patch.len() > MAX_PATCH_BYTES {
Expand Down Expand Up @@ -783,7 +781,7 @@ mod tests {
],
);

let unchanged = local_changes(dir, "origin", LocalSelection::Tracked, None)
let unchanged = local_changes(dir, "origin", LocalSelection::Tracked, &[])
.await
.unwrap();
assert_eq!(
Expand Down Expand Up @@ -827,7 +825,7 @@ mod tests {
],
),
] {
let changes = local_changes(dir, "origin", selection, None).await.unwrap();
let changes = local_changes(dir, "origin", selection, &[]).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 @@ -382,7 +382,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, LocalSelection::Staged, &[]).await,
}],
0,
)),
Expand Down
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,9 @@ struct ReviewArgs {
)]
range: Option<String>,
/// Review only this literal repository-relative file in the local patch.
/// Repeat to review several files in one review.
#[arg(long, value_name = "PATH", conflicts_with_all = ["pr", "commit", "range", "files"])]
path: Option<String>,
path: Vec<String>,
/// Re-verify these open findings of one pull request against the local
/// changes, and print each one's outcome. The outcome is local: the pull
/// request's findings are unchanged. Needs an API token.
Expand Down Expand Up @@ -1192,9 +1193,17 @@ async fn review_local(api: &Api, args: &ReviewArgs) -> anyhow::Result<Verdict> {
std::path::Path::new("."),
&args.repository.remote,
selection,
args.path.as_deref(),
&args.path,
)
.await?;
.await
.map_err(|error| match error {
git::GitError::TooLarge(_) | git::GitError::TooManyFiles(_) | git::GitError::NotUtf8
if args.path.is_empty() =>
{
anyhow::anyhow!("{error}; to review some of the files, name each one with --path FILE")
}
error => error.into(),
})?;
let files = changes.files();
if files == 0 && !args.verify.is_empty() {
bail!(
Expand Down
107 changes: 107 additions & 0 deletions tests/local_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,3 +1114,110 @@ async fn local_path_never_expands_a_file_replaced_by_a_directory() {
assert_eq!(checkout.index().await, index);
server.close().await;
}

#[tokio::test]
async fn repeated_local_paths_select_several_literal_files_and_a_rename() {
let checkout = Checkout::new(&[
("[file].txt", "base\n"),
("second.txt", "base\n"),
("old.txt", "moved\n"),
("other.txt", "base\n"),
])
.await;
checkout.write("[file].txt", "first\n").await;
checkout.write("second.txt", "second\n").await;
checkout.write("other.txt", "excluded\n").await;
checkout.git(&["mv", "old.txt", "new.txt"]).await;
let index = checkout.index().await;
let server = Server::start(true).await;
let output = checkout
.review(
&server,
&[],
&[
"--path",
"[file].txt",
"--path",
"second.txt",
"--path",
"second.txt",
"--path",
"old.txt",
"--path",
"new.txt",
],
)
.await;
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
assert!(String::from_utf8_lossy(&output.stderr).contains("review of 3 changed files"));
{
let uploads = server.fixture.uploads.lock().unwrap();
assert_eq!(uploads.len(), 1);
let patch = uploads[0]["patch"].as_str().unwrap();
assert!(patch.contains("+first"), "{patch}");
assert!(patch.contains("+second"), "{patch}");
assert!(
patch.contains("rename from old.txt\nrename to new.txt"),
"{patch}"
);
assert!(!patch.contains("excluded"), "{patch}");
assert_eq!(patch.matches("diff --git ").count(), 3);
}
assert_eq!(checkout.index().await, index);
server.close().await;
}

#[tokio::test]
async fn one_invalid_local_path_refuses_every_path_before_http() {
let checkout = Checkout::new(&[("kept.txt", "base\n"), ("nested/file.txt", "base\n")]).await;
checkout.write("kept.txt", "changed\n").await;
let server = Server::start(true).await;
for invalid in ["nested", "missing.txt", "../kept.txt"] {
let output = checkout
.review(&server, &[], &["--path", "kept.txt", "--path", invalid])
.await;
assert!(!output.status.success(), "{invalid}");
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains(&format!(
"{invalid:?} is not one exact repository-relative tracked file"
)),
"{stderr}"
);
}
server.assert_no_requests();
server.close().await;
}

#[tokio::test]
async fn an_unreviewable_patch_names_path_and_a_selection_reviews_the_rest() {
let checkout = Checkout::new(&[("latin1.txt", "base\n"), ("kept.txt", "base\n")]).await;
tokio::fs::write(checkout.root().join("latin1.txt"), b"caf\xe9\n")
.await
.unwrap();
checkout.write("kept.txt", "changed\n").await;
let server = Server::start(true).await;
let refused = checkout.review(&server, &[], &[]).await;
assert_eq!(refused.status.code(), Some(1));
let stderr = String::from_utf8_lossy(&refused.stderr);
assert!(stderr.contains("not UTF-8"), "{stderr}");
assert!(stderr.contains("--path FILE"), "{stderr}");
server.assert_no_requests();
let reviewed = checkout.review(&server, &[], &["--path", "kept.txt"]).await;
assert!(
reviewed.status.success(),
"{}",
String::from_utf8_lossy(&reviewed.stderr)
);
{
let uploads = server.fixture.uploads.lock().unwrap();
let patch = uploads[0]["patch"].as_str().unwrap();
assert!(patch.contains("+changed"), "{patch}");
assert!(!patch.contains("latin1.txt"), "{patch}");
}
server.close().await;
}