Honor core.hooksPath property

This commit is contained in:
Alberto Fanjul 2023-01-09 04:56:18 +01:00
parent a4af1d68a8
commit 71b16b3dfb
2 changed files with 19 additions and 3 deletions

View file

@ -44,6 +44,7 @@ class Dialog : Gtk.Dialog
private const string MERGE_MSG_FILENAME = "MERGE_MSG";
private const string CONFIG_COMMIT_TEMPLATE = "commit.template";
private const string CONFIG_HOOKS_PATH = "core.hooksPath";
[GtkChild (name = "source_view_message")]
private unowned Gtk.SourceView d_source_view_message;
@ -866,8 +867,14 @@ class Dialog : Gtk.Dialog
private string prepare_commit_msg_hook (string commit_msg, string commit_src = "", string commit_sha = "") {
string? output = null;
var hook_name = "%s/hooks/%s".printf(repository.get_location().get_path(),
PREPARE_COMMIT_MSG_FILENAME);
var config = repository.get_config().snapshot();
string? hooks_path = null;
try {
hooks_path = config.get_string(CONFIG_HOOKS_PATH);
} catch {
hooks_path = "%s/hooks".printf(repository.get_location().get_path());
}
var hook_name = "%s/%s".printf(hooks_path, PREPARE_COMMIT_MSG_FILENAME);
var hook_file = File.new_for_path(hook_name);
if (!hook_file.query_exists()) {

View file

@ -22,6 +22,8 @@ namespace Gitg
public class Hook : Object
{
private const string CONFIG_HOOKS_PATH = "core.hooksPath";
public Gee.HashMap<string, string> environment { get; set; }
public string name { get; set; }
private string[] d_arguments;
@ -109,7 +111,14 @@ public class Hook : Object
private File hook_file(Ggit.Repository repository)
{
var hooksdir = repository.get_location().get_child("hooks");
var config = repository.get_config().snapshot();
string? hooks_path = null;
try {
hooks_path = config.get_string(CONFIG_HOOKS_PATH);
} catch {
hooks_path = "%s/hooks".printf(repository.get_location().get_path());
}
var hooksdir = File.new_for_path(hooks_path);
var script = hooksdir.resolve_relative_path(name);
return script;