diff options
Diffstat (limited to 'src/exe.zig')
| -rw-r--r-- | src/exe.zig | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/exe.zig b/src/exe.zig index fc24c50..998ea3b 100644 --- a/src/exe.zig +++ b/src/exe.zig @@ -82,7 +82,6 @@ fn pandocWorker(ctx: *Context, page: []const u8) !void { defer ctx.allocator().free(mtime_str); const f = try fs.FileSwapper.createAt(ctx.allocator(), target_path); - defer f.close(); var buffer: [1024]u8 = undefined; var w = f.writer(&buffer); @@ -113,6 +112,45 @@ fn pandocWorker(ctx: *Context, page: []const u8) !void { "--output=-", source_path, }, &env_map, &w.interface); + + f.close(); + + if (f.swapped.*) { + try ctx.generated.append( + ctx.allocator(), + try ctx.allocator().dupe(u8, target_path), + ); + } +} + +pub fn commit(ctx: *Context, paths: []const []const u8) !void { + // skip early if we have nothing to do + if (paths.len == 0) return; + + // skip if staging is unclean + shell(ctx, + \\git diff --cached --exit-code + , null) catch |e| switch (e) { + error.NonZeroExitCode => return, + else => return e, + }; + + for (paths) |f| { + const cmd = try std.fmt.allocPrint(ctx.allocator(), "git add {s}", .{f}); + defer ctx.allocator().free(cmd); + + try shell(ctx, cmd, null); + } + + try shell(ctx, + \\GIT_COMMITTER_NAME=rbc git commit --quiet --message=* + , null); + + try shell(ctx, + \\git show --stat --pretty=oneline + , null); + + log.info("Committed {d} paths", .{paths.len}); } pub fn captureStdout(ctx: *Context, argv: []const []const u8, env_map: ?*std.process.EnvMap, w: *std.Io.Writer) !void { |