Skip to content

Commit abfb04d

Browse files
larsxschneidergitster
authored andcommitted
launch_editor(): indicate that Git waits for user input
When a graphical GIT_EDITOR is spawned by a Git command that opens and waits for user input (e.g. "git rebase -i"), then the editor window might be obscured by other windows. The user might be left staring at the original Git terminal window without even realizing that s/he needs to interact with another window before Git can proceed. To this user Git appears hanging. Print a message that Git is waiting for editor input in the original terminal and get rid of it when the editor returns, if the terminal supports erasing the last line. Also, make sure that our message is terminated with a whitespace so that any message the editor may show upon starting up will be kept separate from our message. Power users might not want to see this message or their editor might already print such a message (e.g. emacsclient). Allow these users to suppress the message by disabling the "advice.waitingForEditor" config. The standard advise() function is not used here as it would always add a newline which would make deleting the message harder. Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Lars Schneider <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a64f213 commit abfb04d

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

Documentation/config.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ advice.*::
351351
addEmbeddedRepo::
352352
Advice on what to do when you've accidentally added one
353353
git repo inside of another.
354+
waitingForEditor::
355+
Print a message to the terminal whenever Git is waiting for
356+
editor input from the user.
354357
--
355358

356359
core.fileMode::

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ int advice_set_upstream_failure = 1;
1717
int advice_object_name_warning = 1;
1818
int advice_rm_hints = 1;
1919
int advice_add_embedded_repo = 1;
20+
int advice_waiting_for_editor = 1;
2021

2122
static struct {
2223
const char *name;
@@ -38,6 +39,7 @@ static struct {
3839
{ "objectnamewarning", &advice_object_name_warning },
3940
{ "rmhints", &advice_rm_hints },
4041
{ "addembeddedrepo", &advice_add_embedded_repo },
42+
{ "waitingforeditor", &advice_waiting_for_editor },
4143

4244
/* make this an alias for backward compatibility */
4345
{ "pushnonfastforward", &advice_push_update_rejected }

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern int advice_set_upstream_failure;
1919
extern int advice_object_name_warning;
2020
extern int advice_rm_hints;
2121
extern int advice_add_embedded_repo;
22+
extern int advice_waiting_for_editor;
2223

2324
int git_default_advice_config(const char *var, const char *value);
2425
__attribute__((format (printf, 1, 2)))

editor.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
4545
const char *args[] = { editor, real_path(path), NULL };
4646
struct child_process p = CHILD_PROCESS_INIT;
4747
int ret, sig;
48+
int print_waiting_for_editor = advice_waiting_for_editor && isatty(2);
49+
50+
if (print_waiting_for_editor) {
51+
/*
52+
* A dumb terminal cannot erase the line later on. Add a
53+
* newline to separate the hint from subsequent output.
54+
*
55+
* Make sure that our message is separated with a whitespace
56+
* from further cruft that may be written by the editor.
57+
*/
58+
const char term = is_terminal_dumb() ? '\n' : ' ';
59+
60+
fprintf(stderr,
61+
_("hint: Waiting for your editor to close the file...%c"),
62+
term);
63+
fflush(stderr);
64+
}
4865

4966
p.argv = args;
5067
p.env = env;
@@ -63,6 +80,13 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
6380
if (ret)
6481
return error("There was a problem with the editor '%s'.",
6582
editor);
83+
84+
if (print_waiting_for_editor && !is_terminal_dumb())
85+
/*
86+
* Go back to the beginning and erase the entire line to
87+
* avoid wasting the vertical space.
88+
*/
89+
fputs("\r\033[K", stderr);
6690
}
6791

6892
if (!buffer)

0 commit comments

Comments
 (0)