Skip to content

Commit 3d411af

Browse files
carenasgitster
authored andcommitted
editor: save and reset terminal after calling EDITOR
When EDITOR is invoked to modify a commit message, it will likely change the terminal settings, and if it misbehaves will leave the terminal output damaged as shown in a recent report from Windows Terminal[1] Instead use the functions provided by compat/terminal to save the settings and recover safely. [1] microsoft/terminal#9359 Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e22b245 commit 3d411af

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

editor.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "strbuf.h"
44
#include "run-command.h"
55
#include "sigchain.h"
6+
#include "compat/terminal.h"
67

78
#ifndef DEFAULT_EDITOR
89
#define DEFAULT_EDITOR "vi"
@@ -50,6 +51,8 @@ const char *git_sequence_editor(void)
5051
static int launch_specified_editor(const char *editor, const char *path,
5152
struct strbuf *buffer, const char *const *env)
5253
{
54+
int term_fail;
55+
5356
if (!editor)
5457
return error("Terminal is dumb, but EDITOR unset");
5558

@@ -83,14 +86,19 @@ static int launch_specified_editor(const char *editor, const char *path,
8386
p.env = env;
8487
p.use_shell = 1;
8588
p.trace2_child_class = "editor";
89+
term_fail = save_term(1);
8690
if (start_command(&p) < 0) {
91+
if (!term_fail)
92+
restore_term();
8793
strbuf_release(&realpath);
8894
return error("unable to start editor '%s'", editor);
8995
}
9096

9197
sigchain_push(SIGINT, SIG_IGN);
9298
sigchain_push(SIGQUIT, SIG_IGN);
9399
ret = finish_command(&p);
100+
if (!term_fail)
101+
restore_term();
94102
strbuf_release(&realpath);
95103
sig = ret - 128;
96104
sigchain_pop(SIGINT);

0 commit comments

Comments
 (0)