We use it in t/lei-q-save.t, and were inadvertently writing
to the worktree.
---
 lib/PublicInbox/TestCommon.pm | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index d506e4b5..465d4b9d 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -288,6 +288,7 @@ sub run_script ($;$$) {
        }
        if ($run_mode == 0) {
                # spawn an independent new process, like real-world use cases:
+               $spawn_opt->{$_} = $opt->{$_} for (qw(-C));
                require PublicInbox::Spawn;
                my $cmd = [ key2script($key), @argv ];
                my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
@@ -302,8 +303,14 @@ sub run_script ($;$$) {
                local %SIG = %SIG;
                local $0 = join(' ', @$cmd);
                my $orig_io = _prepare_redirects($fhref);
+               my $cwdfh;
+               if (my $d = $opt->{'-C'}) {
+                       opendir $cwdfh, '.' or die "opendir .: $!";
+                       chdir $d or die "chdir $d: $!";
+               }
                _run_sub($sub, $key, \@argv);
                eval { PublicInbox::Inbox::cleanup_task() };
+               die "chdir(restore): $!" if $cwdfh && !chdir($cwdfh);
                _undo_redirects($orig_io);
                select STDOUT;
        }
--
unsubscribe: one-click, see List-Unsubscribe header
archive: https://public-inbox.org/meta/

Reply via email to