0.1.5: uploading checks everything first; no silent joining
- Before anything is made on the team, upload checks the vault the way the hub will (the hub's per-entry check now lives in core): a vault on one device only holds every line that looks like a secret as a red card to decide; lines marked "not a secret" are told to the team's hub at upload; history with a flagged entry offers a fresh start. A refused upload no longer leaves an empty vault on the team. - A vault on one device joins a same-named team vault only when they share history; otherwise the team's vault arrives beside it in its own folder. (A failed upload's empty vault had silently swallowed Brain.) - The upload sheet follows the vault live and waits for those decisions. - Full checks of such a vault are cached by content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -161,6 +161,38 @@ pub fn allow(git_dir: &Path, hit: &Hit, file: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Lines this history entry adds (relative to all its parents) that look like secrets. The hub refuses any
|
||||
/// entry with one (P3); devices use it to know beforehand.
|
||||
pub fn check_commit(repo: &git2::Repository, commit: &git2::Commit, allowed: &HashSet<String>) -> Result<Vec<String>> {
|
||||
let parents: Vec<git2::Tree> = commit.parents().map(|p| p.tree()).collect::<Result<_, _>>()?;
|
||||
let tree = commit.tree()?;
|
||||
let first = parents.first();
|
||||
let diff = repo.diff_tree_to_tree(first, Some(&tree), None)?;
|
||||
let mut out = vec![];
|
||||
for delta in diff.deltas() {
|
||||
if !matches!(delta.status(), git2::Delta::Added | git2::Delta::Modified) {
|
||||
continue;
|
||||
}
|
||||
let Some(path) = delta.new_file().path() else { continue };
|
||||
let new = repo.find_blob(delta.new_file().id())?;
|
||||
// A line already present in any parent isn't new here.
|
||||
let mut old = Vec::new();
|
||||
for p in &parents {
|
||||
if let Ok(e) = p.get_path(path)
|
||||
&& let Ok(b) = repo.find_blob(e.id())
|
||||
{
|
||||
old.extend_from_slice(b.content());
|
||||
old.push(b'\n');
|
||||
}
|
||||
}
|
||||
let old = if old.is_empty() { None } else { Some(old.as_slice()) };
|
||||
for hit in scan_bytes(new.content(), old, allowed) {
|
||||
out.push(format!("{} line {}: possible {}", path.display(), hit.line, hit.rule));
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user