Skip to content

Commit

Permalink
builtin/commit: reset terminal after calling EDITOR
Browse files Browse the repository at this point in the history
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] microsoft/terminal#9359

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
  • Loading branch information
carenas committed Sep 30, 2021
1 parent d60439f commit 34be4b3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<options>] [--] <pathspec>..."),
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 34be4b3

Please sign in to comment.