unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] test: add known broken tests for setting NOTMUCH_CONFIG in hooks
@ 2022-05-30 11:38 David Bremner
  2022-05-30 11:38 ` [PATCH 2/2] CLI: set " David Bremner
  0 siblings, 1 reply; 4+ messages in thread
From: David Bremner @ 2022-05-30 11:38 UTC (permalink / raw)
  To: notmuch

Setting this according to --config was requested by Uwe
Kleine-König. There are some other ways that the configuration file
might be found in current notmuch, so check those as well.

As a bonus, fix a bug in the hook tests that left NOTMUCH_CONFIG set
even though a config file was provided via NOTMUCH_PROFILE.

[1]: id:8baa58c3-7ab9-ec03-1bbd-28aa5be838f2@kleine-koenig.org
---
 test/T400-hooks.sh | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
index 0c84b7dd..9ceefbad 100755
--- a/test/T400-hooks.sh
+++ b/test/T400-hooks.sh
@@ -15,6 +15,15 @@ EOF
     echo "${TOKEN}" > ${2}
 }
 
+create_printenv_hook () {
+    mkdir -p ${HOOK_DIR}
+    cat <<EOF >"${HOOK_DIR}/${1}"
+#!/bin/sh
+printenv "${2}" > "${3}"
+EOF
+    chmod +x "${HOOK_DIR}/${1}"
+}
+
 create_write_hook () {
     local TOKEN="${RANDOM}"
     mkdir -p ${HOOK_DIR}
@@ -53,8 +62,11 @@ add_message
 # create maildir structure for notmuch-insert
 mkdir -p "$MAIL_DIR"/{cur,new,tmp}
 
+ORIG_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
 for config in traditional profile explicit relative XDG split; do
     unset NOTMUCH_PROFILE
+    export NOTMUCH_CONFIG=${ORIG_NOTMUCH_CONFIG}
+    EXPECTED_CONFIG=${NOTMUCH_CONFIG}
     notmuch config set database.hook_dir
     notmuch config set database.path ${MAIL_DIR}
     case $config in
@@ -65,8 +77,10 @@ for config in traditional profile explicit relative XDG split; do
 	    dir=${HOME}/.config/notmuch/other
 	    mkdir -p ${dir}
 	    HOOK_DIR=${dir}/hooks
-	    cp ${NOTMUCH_CONFIG} ${dir}/config
+	    EXPECTED_CONFIG=${dir}/config
+	    cp ${NOTMUCH_CONFIG} ${EXPECTED_CONFIG}
 	    export NOTMUCH_PROFILE=other
+	    unset NOTMUCH_CONFIG
 	    ;;
 	explicit)
 	    HOOK_DIR=${HOME}/.notmuch-hooks
@@ -200,6 +214,27 @@ EOF
 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
+${EXPECTED_CONFIG}
+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
+    cat <<EOF > EXPECTED
+${EXPECTED_CONFIG}.alternate
+EOF
+    test_expect_equal_file_nonempty EXPECTED OUTPUT
+
     rm -rf ${HOOK_DIR}
 done
 test_done
-- 
2.35.2
\r

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] CLI: set NOTMUCH_CONFIG in hooks.
  2022-05-30 11:38 [PATCH 1/2] test: add known broken tests for setting NOTMUCH_CONFIG in hooks David Bremner
@ 2022-05-30 11:38 ` David Bremner
  2022-06-04 11:11   ` [PATCH v2] " David Bremner
  0 siblings, 1 reply; 4+ messages in thread
From: David Bremner @ 2022-05-30 11:38 UTC (permalink / raw)
  To: notmuch

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            | 7 +++++++
 test/T400-hooks.sh | 4 ----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/hooks.c b/hooks.c
index ec89b22e..eb47555f 100644
--- 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
diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
index 9ceefbad..35bf70c0 100755
--- a/test/T400-hooks.sh
+++ b/test/T400-hooks.sh
@@ -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
-- 
2.35.2
\r

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] CLI: set NOTMUCH_CONFIG in hooks.
  2022-05-30 11:38 ` [PATCH 2/2] CLI: set " David Bremner
@ 2022-06-04 11:11   ` David Bremner
  2022-06-18 11:27     ` David Bremner
  0 siblings, 1 reply; 4+ messages in thread
From: David Bremner @ 2022-06-04 11:11 UTC (permalink / raw)
  To: David Bremner, notmuch

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            | 7 +++++++
 test/T400-hooks.sh | 4 ----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/hooks.c b/hooks.c
index ec89b22e..0cf72e74 100644
--- 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
diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
index 9ceefbad..35bf70c0 100755
--- a/test/T400-hooks.sh
+++ b/test/T400-hooks.sh
@@ -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
-- 
2.35.2
\r

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] CLI: set NOTMUCH_CONFIG in hooks.
  2022-06-04 11:11   ` [PATCH v2] " David Bremner
@ 2022-06-18 11:27     ` David Bremner
  0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2022-06-18 11:27 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> 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).

series applied to master.\r

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-18 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30 11:38 [PATCH 1/2] test: add known broken tests for setting NOTMUCH_CONFIG in hooks David Bremner
2022-05-30 11:38 ` [PATCH 2/2] CLI: set " David Bremner
2022-06-04 11:11   ` [PATCH v2] " David Bremner
2022-06-18 11:27     ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).