Register local worktrees after acquiring a project remote id

Antonio Scandurra created

Change summary

Cargo.lock                    |  1 +
crates/project/src/project.rs | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)

Detailed changes

Cargo.lock 🔗

@@ -5652,6 +5652,7 @@ version = "0.1.0"
 dependencies = [
  "anyhow",
  "client",
+ "clock",
  "gpui",
  "language",
  "log",

crates/project/src/project.rs 🔗

@@ -130,6 +130,27 @@ impl Project {
                                 } else {
                                     None
                                 };
+
+                                if let Some(project_id) = remote_id {
+                                    let mut registrations = Vec::new();
+                                    this.read_with(&cx, |this, cx| {
+                                        for worktree in &this.worktrees {
+                                            let worktree_id = worktree.id() as u64;
+                                            let worktree = worktree.read(cx).as_local().unwrap();
+                                            registrations.push(rpc.request(
+                                                proto::RegisterWorktree {
+                                                    project_id,
+                                                    worktree_id,
+                                                    root_name: worktree.root_name().to_string(),
+                                                    authorized_logins: worktree.authorized_logins(),
+                                                },
+                                            ));
+                                        }
+                                    });
+                                    for registration in registrations {
+                                        registration.await?;
+                                    }
+                                }
                                 this.update(&mut cx, |this, cx| this.set_remote_id(remote_id, cx));
                             }
                         }