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:
@@ -198,11 +198,15 @@ impl Vault {
|
||||
|
||||
/// Changed notes (not yet saved) that seem to contain a secret on a new line.
|
||||
pub fn secret_holds(&self) -> Result<Vec<SecretNote>> {
|
||||
static SCANNED: std::sync::LazyLock<std::sync::Mutex<std::collections::HashMap<Oid, Vec<Hit>>>> =
|
||||
std::sync::LazyLock::new(Default::default);
|
||||
let allowed = secrets::load_allowed(&self.git_dir);
|
||||
let head_tree = self.head_commit()?.map(|c| c.tree()).transpose()?;
|
||||
// A vault on this device only hasn't shared anything with where it may go next (a team), so every line counts.
|
||||
let local = self.is_local();
|
||||
let head_tree = if local { None } else { self.head_commit()?.map(|c| c.tree()).transpose()? };
|
||||
let mut known_blobs: Option<HashSet<Oid>> = None;
|
||||
let mut opts = StatusOptions::new();
|
||||
opts.include_untracked(true).recurse_untracked_dirs(true).include_ignored(false);
|
||||
opts.include_untracked(true).recurse_untracked_dirs(true).include_ignored(false).include_unmodified(local);
|
||||
let mut out = vec![];
|
||||
for entry in self.repo.statuses(Some(&mut opts))?.iter() {
|
||||
let st = entry.status();
|
||||
@@ -213,6 +217,7 @@ impl Vault {
|
||||
let Ok(bytes) = std::fs::read(self.root.join(path)) else { continue };
|
||||
let old = match head_tree.as_ref().and_then(|t| t.get_path(Path::new(path)).ok()) {
|
||||
Some(e) => Some(self.repo.find_blob(e.id())?.content().to_vec()),
|
||||
None if local => None,
|
||||
None => {
|
||||
// A new file whose exact bytes are already in the vault (a copy or a move) was already shared.
|
||||
let known = known_blobs.get_or_insert_with(|| blob_ids(head_tree.as_ref()));
|
||||
@@ -222,7 +227,15 @@ impl Vault {
|
||||
None
|
||||
}
|
||||
};
|
||||
let hits = secrets::scan_bytes(&bytes, old.as_deref(), &allowed);
|
||||
let hits = if local {
|
||||
// Every note is checked each time here, so results are kept by content: only edits cost a scan.
|
||||
let id = Oid::hash_object(git2::ObjectType::Blob, &bytes)?;
|
||||
let mut cache = SCANNED.lock().unwrap();
|
||||
let all = cache.entry(id).or_insert_with(|| secrets::scan_bytes(&bytes, None, &HashSet::new()));
|
||||
all.iter().filter(|h| !allowed.contains(&h.line_hash)).cloned().collect()
|
||||
} else {
|
||||
secrets::scan_bytes(&bytes, old.as_deref(), &allowed)
|
||||
};
|
||||
if !hits.is_empty() {
|
||||
out.push(SecretNote { path: path.to_string(), hits });
|
||||
}
|
||||
@@ -319,6 +332,26 @@ impl Vault {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Whether this vault's history and the one at `url` share entries: the same vault, kept in two places.
|
||||
pub fn shares_history_with(&self, url: &str) -> Result<bool> {
|
||||
const PROBE: &str = "refs/lune/probe";
|
||||
let mut remote = self.repo.remote_anonymous(url)?;
|
||||
let mut opts = FetchOptions::new();
|
||||
opts.remote_callbacks(remote::callbacks());
|
||||
opts.download_tags(AutotagOption::None);
|
||||
remote.fetch(&[format!("+{}:{PROBE}", self.branch_ref())], Some(&mut opts), None)?;
|
||||
let theirs = self.repo.find_reference(PROBE).ok().and_then(|r| r.target());
|
||||
let ours = self.head_commit()?.map(|c| c.id());
|
||||
let shared = match (ours, theirs) {
|
||||
(Some(a), Some(b)) => self.repo.merge_base(a, b).is_ok(),
|
||||
_ => false,
|
||||
};
|
||||
if let Ok(mut r) = self.repo.find_reference(PROBE) {
|
||||
r.delete()?;
|
||||
}
|
||||
Ok(shared)
|
||||
}
|
||||
|
||||
/// Starts history over with just the current notes (the old history stays only on this device).
|
||||
/// Returns where history was, to go back if needed.
|
||||
pub fn fresh_start(&self, message: &str) -> Result<Oid> {
|
||||
|
||||
Reference in New Issue
Block a user