From 39ba986b0ea772ba41710c2a545fd07026b1f677 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Mon, 9 Sep 2024 02:23:48 +0100 Subject: [PATCH] config.mak.uname: add HAVE_DEV_TTY to cygwin config section If neither HAVE_DEV_TTY nor GIT_WINDOWS_NATIVE is set, while compiling the 'compat/terminal.c' code, then the fallback code calls the system getpass() function. Unfortunately, this ignores the 'echo' parameter of the git_terminal_prompt() function, since it has no way to implement that functionality. This results in a less than optimal user experience on cygwin, which does not define either of those build flags. However, cygwin does have a functional '/dev/tty', so that it can build with HAVE_DEV_TTY and benefit from the improved user experience. The improved git_terminal_prompt() function that comes with HAVE_DEV_TTY is used in the git_prompt() function, which in turn is used by the 'git credential', 'git bisect' and 'git help' commands. In addition to git_terminal_prompt(), read_key_without_echo() is likewise improved and used by the 'git add -p' command. While using the 'git credential fill' command, for example: $ printf "%s\n" protocol=https host=example.com path=git | ./git credential fill Username for 'https://example.com': user Password for 'https://user@example.com': protocol=https host=example.com username=user password=pass $ The 'user' name is now echoed while typing (the password isn't), where this wasn't the case before. When using the auto-correct feature: $ ./git -c help.autocorrect=prompt fred WARNING: You called a Git command named 'fred', which does not exist. Run 'grep' instead [y/N]? n $ ./git -c help.autocorrect=prompt fred WARNING: You called a Git command named 'fred', which does not exist. Run 'grep' instead [y/N]? y fatal: no pattern given $ The user can actually see what they are typing at the prompt. Similar comments apply to 'git bisect': $ ./git bisect bad master~1 You need to start by "git bisect start" Do you want me to do it for you [Y/n]? y status: waiting for both good and bad commits status: waiting for good commit(s), bad commit known $ ./git bisect reset Already on 'master-tmp' $ $ ./git bisect start status: waiting for both good and bad commits $ ./git bisect bad master~1 status: waiting for good commit(s), bad commit known $ ./git bisect next warning: bisecting only with a bad commit Are you sure [Y/n]? n $ ./git bisect reset Already on 'master-tmp' $ The read_key_without_echo() function leads to a much improved 'git add -p' command, when the 'interactive.singleKey' configuration is set: $ cd .. $ mkdir test-git $ cd test-git $ git init -q $ echo foo >file $ git add file $ echo bar >file $ ../git/git -c interactive.singleKey=true add -p diff --git a/file b/file index 257cc56..5716ca5 100644 --- a/file +++ b/file @@ -1 +1 @@ -foo +bar (1/1) Stage this hunk [y,n,q,a,d,e,p,?]? y $ Note that, not only is the user input echoed, but that it is immediately accepted (without having to type ) and the program exits with the hunk staged (in this case) or not. In order to reap these benefits, set the HAVE_DEV_TTY build flag in the cygwin configuration section of config.mak.uname. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- config.mak.uname | 1 + 1 file changed, 1 insertion(+) diff --git a/config.mak.uname b/config.mak.uname index 64c44db805..96e2ea8ec1 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -235,6 +235,7 @@ ifeq ($(uname_O),Cygwin) else NO_REGEX = UnfortunatelyYes endif + HAVE_DEV_TTY = YesPlease HAVE_ALLOCA_H = YesPlease NEEDS_LIBICONV = YesPlease NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes