diff --git a/src/Project.zig b/src/Project.zig index 67060a2..946e23a 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -2174,6 +2174,8 @@ pub fn query_git(self: *Self) void { self.state.status = .failed; }; // TODO: This needs to be invoked when there are identified changes in the fs + for (self.new_or_modified_files.items) |file| self.allocator.free(file.path); + self.new_or_modified_files.clearRetainingCapacity(); self.state.vcs_new_or_modified_files = .running; git.new_or_modified_files(@intFromPtr(self)) catch { self.state.vcs_new_or_modified_files = .failed; diff --git a/src/project_manager.zig b/src/project_manager.zig index 14a3d8e..c5d380c 100644 --- a/src/project_manager.zig +++ b/src/project_manager.zig @@ -105,6 +105,13 @@ pub fn request_new_or_modified_files(max: usize) (ProjectManagerError || Project return send(.{ "request_new_or_modified_files", project, max }); } +pub fn request_sync_with_vcs() (ProjectManagerError || ProjectError)!void { + const project = tp.env.get().str("project"); + if (project.len == 0) + return error.NoProject; + return send(.{ "sync_with_vcs", project }); +} + pub fn request_recent_projects() (ProjectManagerError || ProjectError)!void { const project = tp.env.get().str("project"); return send(.{ "request_recent_projects", project }); @@ -386,6 +393,8 @@ const Process = struct { self.request_recent_files(from, project_directory, max) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; } else if (try cbor.match(m.buf, .{ "request_new_or_modified_files", tp.extract(&project_directory), tp.extract(&max) })) { self.request_new_or_modified_files(from, project_directory, max) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; + } else if (try cbor.match(m.buf, .{ "sync_with_vcs", tp.extract(&project_directory) })) { + self.request_sync_with_vcs(from, project_directory) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; } else if (try cbor.match(m.buf, .{ "request_recent_projects", tp.extract(&project_directory) })) { self.request_recent_projects(from, project_directory) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; } else if (try cbor.match(m.buf, .{ "query_recent_files", tp.extract(&project_directory), tp.extract(&max), tp.extract(&query) })) { @@ -486,6 +495,11 @@ const Process = struct { return project.request_recent_files(from, max); } + fn request_sync_with_vcs(self: *Process, _: tp.pid_ref, project_directory: []const u8) (ProjectError || Project.ClientError)!void { + const project = self.projects.get(project_directory) orelse return error.NoProject; + return project.query_git(); + } + fn request_new_or_modified_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize) (ProjectError || Project.ClientError)!void { const project = self.projects.get(project_directory) orelse return error.NoProject; return project.request_new_or_modified_files(from, max); diff --git a/src/tui/tui.zig b/src/tui/tui.zig index a0dbbff..65c7e3e 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -1370,6 +1370,10 @@ pub fn mainview() ?*MainView { return if (current().mainview_) |*mv| mv.dynamic_cast(MainView) else null; } +pub fn sync_with_vcs() !void { + try project_manager.request_sync_with_vcs(); +} + pub fn mainview_widget() Widget { return current().mainview_ orelse @panic("tui main view not found"); }