summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Koutcher <thomas.koutcher@online.fr>2024-04-26 23:00:01 +0200
committerThomas Koutcher <thomas.koutcher@online.fr>2024-04-26 23:00:01 +0200
commitb795fc37962540641c96473a4297ac790496b768 (patch)
treeab28e0530cdc033064b2f1fe975249367d3d8b4c
parent663a69bedea38ddd9ceef0571cca8831f688244e (diff)
Fix editing when stdin is redirected
Closes #1330
-rw-r--r--NEWS.adoc1
-rw-r--r--include/tig/io.h2
-rw-r--r--src/display.c2
-rw-r--r--src/io.c11
-rw-r--r--src/status.c4
5 files changed, 13 insertions, 7 deletions
diff --git a/NEWS.adoc b/NEWS.adoc
index aac472fc..c520c257 100644
--- a/NEWS.adoc
+++ b/NEWS.adoc
@@ -10,6 +10,7 @@ Bug fixes:
markers (regression in 2.5.9). (#1326)
- Fix keybinding with +[cmd] not triggering view refreshing. (#1324)
- Fix reopening the blame view from the main view.
+ - Fix editing when stdin is redirected. (#1330)
tig-2.5.9
---------
diff --git a/include/tig/io.h b/include/tig/io.h
index 4e8f4176..2ee43dcb 100644
--- a/include/tig/io.h
+++ b/include/tig/io.h
@@ -87,7 +87,7 @@ bool io_done(struct io *io);
bool io_exec(struct io *io, enum io_type type, const char *dir, char * const env[], const char *argv[], int custom);
bool io_run(struct io *io, enum io_type type, const char *dir, char * const env[], const char *argv[]);
bool io_run_bg(const char **argv, const char *dir);
-bool io_run_fg(const char **argv, const char *dir);
+bool io_run_fg(const char **argv, const char *dir, int fd);
bool io_run_append(const char **argv, int fd);
bool io_eof(struct io *io);
int io_error(struct io *io);
diff --git a/src/display.c b/src/display.c
index 53c4d744..5152576d 100644
--- a/src/display.c
+++ b/src/display.c
@@ -88,7 +88,7 @@ open_external_viewer(const char *argv[], const char *dir, bool silent, bool conf
refresh();
endwin(); /* restore original tty modes */
tcsetattr(opt_tty.fd, TCSAFLUSH, opt_tty.attr);
- ok = io_run_fg(argv, dir);
+ ok = io_run_fg(argv, dir, opt_tty.fd);
if (confirm || !ok) {
if (!ok && *notice)
fprintf(stderr, "%s", notice);
diff --git a/src/io.c b/src/io.c
index f01a9ab3..26ad1c51 100644
--- a/src/io.c
+++ b/src/io.c
@@ -340,7 +340,7 @@ open_trace(int devnull, const char *argv[])
bool
io_trace(const char *fmt, ...)
{
- static FILE *trace_out; /* Intensionally leaked. */
+ static FILE *trace_out; /* Intentionally leaked. */
va_list args;
int retval;
@@ -418,6 +418,11 @@ io_exec(struct io *io, enum io_type type, const char *dir, char * const env[], c
close(pipefds[0]);
if (pipefds[1] != -1)
close(pipefds[1]);
+ } else {
+ if (custom != -1) {
+ dup2(custom, STDIN_FILENO);
+ close(custom);
+ }
}
if (dir && *dir && chdir(dir) == -1)
@@ -463,9 +468,9 @@ io_run_bg(const char **argv, const char *dir)
}
bool
-io_run_fg(const char **argv, const char *dir)
+io_run_fg(const char **argv, const char *dir, int fd)
{
- return io_complete(IO_FG, argv, dir, -1);
+ return io_complete(IO_FG, argv, dir, fd);
}
bool
diff --git a/src/status.c b/src/status.c
index 8c83c7fe..a8dffebc 100644
--- a/src/status.c
+++ b/src/status.c
@@ -691,13 +691,13 @@ status_revert(struct status *status, enum line_type type, bool has_none)
reset_argv[4] = NULL;
}
- if (!io_run_fg(reset_argv, repo.exec_dir))
+ if (!io_run_fg(reset_argv, repo.exec_dir, -1))
return false;
if (status->old.mode == 0 && status->new.mode == 0)
return true;
}
- return io_run_fg(checkout_argv, repo.exec_dir);
+ return io_run_fg(checkout_argv, repo.exec_dir, -1);
}
return false;