From 34be4b3f2df49842a487cbe99d219326e76492c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Thu, 30 Sep 2021 06:16:48 -0700 Subject: [PATCH] builtin/commit: reset terminal after calling EDITOR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When EDITOR is invoked to modify a commit message, it will likely change the console settings, and if it misbehaves, will leave the console output as shown in microsoft/terminal#9359. Use the recently added {push,pop}_term() functions to save the terminal state and recover safely, instead. [1] https://github.com/microsoft/terminal/issues/9359 Signed-off-by: Carlo Marcelo Arenas Belón --- builtin/commit.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin/commit.c b/builtin/commit.c index 243c626307c644..d106eed6fda26a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -36,6 +36,7 @@ #include "help.h" #include "commit-reach.h" #include "commit-graph.h" +#include "compat/terminal.h" static const char * const builtin_commit_usage[] = { N_("git commit [] [--] ..."), @@ -1074,11 +1075,14 @@ static int prepare_to_commit(const char *index_file, const char *prefix, struct strvec env = STRVEC_INIT; strvec_pushf(&env, "GIT_INDEX_FILE=%s", index_file); + push_term(1); if (launch_editor(git_path_commit_editmsg(), NULL, env.v)) { + pop_term(); fprintf(stderr, _("Please supply the message using either -m or -F option.\n")); exit(1); } + pop_term(); strvec_clear(&env); }