feat: start git client module

This commit is contained in:
CJ van den Berg 2025-04-19 23:41:30 +02:00
parent 05da3205b7
commit 5ad074c681
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 37 additions and 0 deletions

View file

@ -420,6 +420,15 @@ pub fn build_exe(
}, },
}); });
const git_mod = b.createModule(.{
.root_source_file = b.path("src/git.zig"),
.imports = &.{
.{ .name = "thespian", .module = thespian_mod },
.{ .name = "cbor", .module = cbor_mod },
.{ .name = "shell", .module = shell_mod },
},
});
const ripgrep_mod = b.createModule(.{ const ripgrep_mod = b.createModule(.{
.root_source_file = b.path("src/ripgrep.zig"), .root_source_file = b.path("src/ripgrep.zig"),
.imports = &.{ .imports = &.{
@ -486,6 +495,7 @@ pub fn build_exe(
.{ .name = "Buffer", .module = Buffer_mod }, .{ .name = "Buffer", .module = Buffer_mod },
.{ .name = "keybind", .module = keybind_mod }, .{ .name = "keybind", .module = keybind_mod },
.{ .name = "shell", .module = shell_mod }, .{ .name = "shell", .module = shell_mod },
.{ .name = "git", .module = git_mod },
.{ .name = "ripgrep", .module = ripgrep_mod }, .{ .name = "ripgrep", .module = ripgrep_mod },
.{ .name = "theme", .module = themes_dep.module("theme") }, .{ .name = "theme", .module = themes_dep.module("theme") },
.{ .name = "themes", .module = themes_dep.module("themes") }, .{ .name = "themes", .module = themes_dep.module("themes") },

21
src/git.zig Normal file
View file

@ -0,0 +1,21 @@
const std = @import("std");
const tp = @import("thespian");
const shell = @import("shell");
const git_binary = "git";
pub fn get_current_branch(allocator: std.mem.Allocator) !void {
const git_current_branch_cmd = tp.message.fmt(.{ git_binary, "rev-parse", "--abbrev-ref", "HEAD" });
const handlers = struct {
fn out(_: usize, parent: tp.pid_ref, _: []const u8, output: []const u8) void {
var it = std.mem.splitScalar(u8, output, '\n');
while (it.next()) |line| if (line.len > 0)
parent.send(.{ "git", "current_branch", line }) catch {};
}
};
try shell.execute(allocator, git_current_branch_cmd, .{
.out = handlers.out,
.err = shell.log_err_handler,
.exit = shell.log_exit_err_handler,
});
}

View file

@ -2,6 +2,7 @@ const std = @import("std");
const tp = @import("thespian"); const tp = @import("thespian");
const cbor = @import("cbor"); const cbor = @import("cbor");
const tracy = @import("tracy"); const tracy = @import("tracy");
const git = @import("git");
const ripgrep = @import("ripgrep"); const ripgrep = @import("ripgrep");
const root = @import("root"); const root = @import("root");
const location_history = @import("location_history"); const location_history = @import("location_history");
@ -827,6 +828,11 @@ const cmds = struct {
} }
pub const find_in_files_query_meta: Meta = .{ .arguments = &.{.string} }; pub const find_in_files_query_meta: Meta = .{ .arguments = &.{.string} };
pub fn git_branch(self: *Self, _: Ctx) Result {
try git.get_current_branch(self.allocator);
}
pub const git_branch_meta: Meta = .{ .description = "Get the current git branch" };
pub fn shell_execute_log(self: *Self, ctx: Ctx) Result { pub fn shell_execute_log(self: *Self, ctx: Ctx) Result {
if (!try ctx.args.match(.{ tp.string, tp.more })) if (!try ctx.args.match(.{ tp.string, tp.more }))
return error.InvalidShellArgument; return error.InvalidShellArgument;