Skip to content

Commit

Permalink
fix: Commit message checking description even if it should be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hejsil committed Dec 28, 2024
1 parent 978d81e commit 4386a45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/git.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ pub fn commitFile(gpa: std.mem.Allocator, dir: std.fs.Dir, file: []const u8, msg
_ = try child.wait();
}

pub const MessageOptions = struct {
description: bool = false,
};

/// Create a commit message based on what `Package.update` did. Depending on what changed between
/// the old and new package, the commit message will differ.
pub fn createCommitMessage(gpa: std.mem.Allocator, package: Package.Named, m_old_package: ?Package) ![]u8 {
pub fn createCommitMessage(
gpa: std.mem.Allocator,
package: Package.Named,
m_old_package: ?Package,
options: MessageOptions,
) ![]u8 {
const old_package = m_old_package orelse {
return std.fmt.allocPrint(gpa, "{s}: Add {s}", .{
package.name,
Expand All @@ -31,7 +40,7 @@ pub fn createCommitMessage(gpa: std.mem.Allocator, package: Package.Named, m_old
return std.fmt.allocPrint(gpa, "{s}: Update hash", .{package.name});
if (!std.mem.eql(u8, package.package.linux_x86_64.url, old_package.linux_x86_64.url))
return std.fmt.allocPrint(gpa, "{s}: Update url", .{package.name});
if (!std.mem.eql(u8, package.package.info.description, old_package.info.description))
if (options.description and !std.mem.eql(u8, package.package.info.description, old_package.info.description))
return std.fmt.allocPrint(gpa, "{s}: Update description", .{package.name});
if (package.package.info.donate.len != old_package.info.donate.len)
return std.fmt.allocPrint(gpa, "{s}: Update donations", .{package.name});
Expand All @@ -45,7 +54,9 @@ pub fn createCommitMessage(gpa: std.mem.Allocator, package: Package.Named, m_old
}

fn expectCreateCommitMessage(expected: []const u8, package: Package.Named, m_old_package: ?Package) !void {
const actual = try createCommitMessage(std.testing.allocator, package, m_old_package);
const actual = try createCommitMessage(std.testing.allocator, package, m_old_package, .{
.description = true,
});
defer std.testing.allocator.free(actual);

try std.testing.expectEqualStrings(expected, actual);
Expand Down
4 changes: 3 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ fn pkgsAdd(program: *Program, options: PackagesAddOptions) !void {
try packages.writeToFileOverride(pkgs_ini_file);
try pkgs_ini_file.sync();

const msg = try git.createCommitMessage(program.arena, package, old_package);
const msg = try git.createCommitMessage(program.arena, package, old_package, .{
.description = options.update_description,
});
try git.commitFile(program.gpa, pkgs_ini_dir, pkgs_ini_base_name, msg);
}
}
Expand Down

0 comments on commit 4386a45

Please sign in to comment.