]> git.cworth.org Git - notmuch/commitdiff
CLI: set NOTMUCH_CONFIG in hooks.
authorDavid Bremner <david@tethera.net>
Sat, 4 Jun 2022 11:11:19 +0000 (08:11 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 18 Jun 2022 11:24:46 +0000 (08:24 -0300)
This addresses a bug report / feature request of Uwe Kleine-König. The
assumption is that we always load a config file in the CLI (i.e. we
never pass "" as the config file argument to
notmuch_database_open_with_config).

[1]: id:8baa58c3-7ab9-ec03-1bbd-28aa5be838f2@kleine-koenig.org

hooks.c
test/T400-hooks.sh

diff --git a/hooks.c b/hooks.c
index ec89b22ec75497ee69a5d9cce888c6c2a1a95c81..0cf72e748bc983d60aa09a074375b5fef2c96d97 100644 (file)
--- a/hooks.c
+++ b/hooks.c
@@ -27,6 +27,7 @@ int
 notmuch_run_hook (notmuch_database_t *notmuch, const char *hook)
 {
     char *hook_path;
+    const char *config_path;
     int status = 0;
     pid_t pid;
 
@@ -38,6 +39,12 @@ notmuch_run_hook (notmuch_database_t *notmuch, const char *hook)
        return 1;
     }
 
+    config_path = notmuch_config_path (notmuch);
+    if (setenv ("NOTMUCH_CONFIG", config_path, 1)) {
+       perror ("setenv");
+       return 1;
+    }
+
     /* Check access before fork() for speed and simplicity of error handling. */
     if (access (hook_path, X_OK) == -1) {
        /* Ignore ENOENT. It's okay not to have a hook, hook dir, or even
index 9ceefbad03c00c026663b24d36f4548ec7fe03c5..35bf70c0df4a155fe498fe2976de6bf5bf7deed9 100755 (executable)
@@ -215,9 +215,6 @@ EOF
     test_expect_equal_file EXPECTED OUTPUT
 
     test_begin_subtest "NOTMUCH_CONFIG is set"
-    if [ "${config}" = "profile" ]; then
-       test_subtest_known_broken
-    fi
     create_printenv_hook "pre-new" NOTMUCH_CONFIG OUTPUT
     NOTMUCH_NEW
     cat <<EOF > EXPECTED
@@ -226,7 +223,6 @@ EOF
     test_expect_equal_file_nonempty EXPECTED OUTPUT
 
     test_begin_subtest "NOTMUCH_CONFIG is set by --config"
-    test_subtest_known_broken
     create_printenv_hook "pre-new" NOTMUCH_CONFIG OUTPUT
     cp "${EXPECTED_CONFIG}" "${EXPECTED_CONFIG}.alternate"
     notmuch --config "${EXPECTED_CONFIG}.alternate" new