Milestone 4: taking access back
Removing someone from a vault, a device, or the team opens departures on the hub. Each device stops syncing, saves, goes read-only, hands unshared work over (secrets redacted), and deletes the folder only if the app created it. Managers review handovers (show/keep/discard/skip); removed devices may only hand over, then their key is retired. Adds the delete-from-devices vault setting and team restore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -381,6 +381,27 @@ impl Vault {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Sends this device's whole history to `dst` on the remote (the hub's handover area for this device).
|
||||
pub fn hand_over(&self, dst: &str) -> Result<()> {
|
||||
let mut remote = self.repo.find_remote("origin")?;
|
||||
let rejected = RefCell::new(None::<String>);
|
||||
let mut cb = remote::callbacks();
|
||||
cb.push_update_reference(|_, status| {
|
||||
if let Some(s) = status {
|
||||
*rejected.borrow_mut() = Some(s.to_string());
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
let mut opts = PushOptions::new();
|
||||
opts.remote_callbacks(cb);
|
||||
remote.push(&[format!("+{}:{dst}", self.branch_ref())], Some(&mut opts))?;
|
||||
drop(opts);
|
||||
if let Some(why) = rejected.into_inner() {
|
||||
bail!("the hub didn't take the handover: {why}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// One sync round: fetch, combine, write the result to disk, share local history.
|
||||
pub fn sync(&self) -> Result<SyncReport> {
|
||||
let mut report = SyncReport::default();
|
||||
@@ -467,33 +488,7 @@ impl Vault {
|
||||
|
||||
/// Resolves every clash in `index` without markers: "their" version in place, ours beside it (S4).
|
||||
fn keep_both(&self, index: &mut git2::Index, kept_both: &mut Vec<(String, String)>) -> Result<()> {
|
||||
if index.has_conflicts() {
|
||||
let conflicts: Vec<_> = index.conflicts()?.collect::<Result<_, _>>()?;
|
||||
for c in conflicts {
|
||||
for e in [&c.ancestor, &c.our, &c.their].into_iter().flatten() {
|
||||
let _ = index.conflict_remove(&names::bytes_path(&e.path));
|
||||
}
|
||||
match (c.our, c.their) {
|
||||
(Some(ours), Some(theirs)) if ours.path == theirs.path && ours.id != theirs.id => {
|
||||
let note = String::from_utf8_lossy(&theirs.path).into_owned();
|
||||
let copy = (1..)
|
||||
.map(|n| names::copy_name(¬e, &self.label, n))
|
||||
.find(|p| index.get_path(Path::new(p), 0).is_none())
|
||||
.unwrap();
|
||||
index.add(&stage0(&theirs, None))?;
|
||||
index.add(&stage0(&ours, Some(copy.as_bytes())))?;
|
||||
kept_both.push((note, copy));
|
||||
}
|
||||
// Different paths, or one side removed the note: keep whatever still exists.
|
||||
(ours, theirs) => {
|
||||
for e in [ours, theirs].into_iter().flatten() {
|
||||
index.add(&stage0(&e, None))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
keep_both(index, &self.label, kept_both)
|
||||
}
|
||||
|
||||
/// Paths that differ only by letter case can't coexist on macOS/Windows. There, rename the extras so
|
||||
@@ -641,6 +636,38 @@ impl Vault {
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves every clash in `index` without markers: "their" version in place, ours beside it labeled
|
||||
/// with `label` (S4). Used for syncing, undo, and keeping handovers on the hub.
|
||||
pub fn keep_both(index: &mut git2::Index, label: &str, kept_both: &mut Vec<(String, String)>) -> Result<()> {
|
||||
if index.has_conflicts() {
|
||||
let conflicts: Vec<_> = index.conflicts()?.collect::<Result<_, _>>()?;
|
||||
for c in conflicts {
|
||||
for e in [&c.ancestor, &c.our, &c.their].into_iter().flatten() {
|
||||
let _ = index.conflict_remove(&names::bytes_path(&e.path));
|
||||
}
|
||||
match (c.our, c.their) {
|
||||
(Some(ours), Some(theirs)) if ours.path == theirs.path && ours.id != theirs.id => {
|
||||
let note = String::from_utf8_lossy(&theirs.path).into_owned();
|
||||
let copy = (1..)
|
||||
.map(|n| names::copy_name(¬e, label, n))
|
||||
.find(|p| index.get_path(Path::new(p), 0).is_none())
|
||||
.unwrap();
|
||||
index.add(&stage0(&theirs, None))?;
|
||||
index.add(&stage0(&ours, Some(copy.as_bytes())))?;
|
||||
kept_both.push((note, copy));
|
||||
}
|
||||
// Different paths, or one side removed the note: keep whatever still exists.
|
||||
(ours, theirs) => {
|
||||
for e in [ours, theirs].into_iter().flatten() {
|
||||
index.add(&stage0(&e, None))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn blob_ids(tree: Option<&git2::Tree>) -> HashSet<Oid> {
|
||||
let mut ids = HashSet::new();
|
||||
if let Some(t) = tree {
|
||||
|
||||
Reference in New Issue
Block a user