Skip to content

Commit b815a72

Browse files
committed
Merge branch 'kf/askpass-config'
* kf/askpass-config: Extend documentation of core.askpass and GIT_ASKPASS. Allow core.askpass to override SSH_ASKPASS. Add a new option 'core.askpass'.
2 parents e250c59 + 453842c commit b815a72

7 files changed

Lines changed: 26 additions & 5 deletions

File tree

Documentation/config.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ core.excludesfile::
450450
to the value of `$HOME` and "{tilde}user/" to the specified user's
451451
home directory. See linkgit:gitignore[5].
452452

453+
core.askpass::
454+
Some commands (e.g. svn and http interfaces) that interactively
455+
ask for a password can be told to use an external program given
456+
via the value of this variable. Can be overridden by the 'GIT_ASKPASS'
457+
environment variable. If not set, fall back to the value of the
458+
'SSH_ASKPASS' environment variable or, failing that, a simple password
459+
prompt. The external program shall be given a suitable prompt as
460+
command line argument and write the password on its STDOUT.
461+
453462
core.editor::
454463
Commands such as `commit` and `tag` that lets you edit
455464
messages by launching an editor uses the value of this

Documentation/git.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ Usually it is easier to configure any desired options through your
639639
personal `.ssh/config` file. Please consult your ssh documentation
640640
for further details.
641641

642+
'GIT_ASKPASS'::
643+
If this environment variable is set, then git commands which need to
644+
acquire passwords or passphrases (e.g. for HTTP or IMAP authentication)
645+
will call this program with a suitable prompt as command line argument
646+
and read the password from its STDOUT. See also the 'core.askpass'
647+
option in linkgit:git-config[1].
648+
642649
'GIT_FLUSH'::
643650
If this environment variable is set to "1", then commands such
644651
as 'git blame' (in incremental mode), 'git rev-list', 'git log',

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ extern int pager_in_use(void);
10351035
extern int pager_use_color;
10361036

10371037
extern const char *editor_program;
1038+
extern const char *askpass_program;
10381039
extern const char *excludes_file;
10391040

10401041
/* base85 */

config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ static int git_default_core_config(const char *var, const char *value)
605605
if (!strcmp(var, "core.editor"))
606606
return git_config_string(&editor_program, var, value);
607607

608+
if (!strcmp(var, "core.askpass"))
609+
return git_config_string(&askpass_program, var, value);
610+
608611
if (!strcmp(var, "core.excludesfile"))
609612
return git_config_pathname(&excludes_file, var, value);
610613

connect.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,16 @@ int finish_connect(struct child_process *conn)
621621

622622
char *git_getpass(const char *prompt)
623623
{
624-
char *askpass;
624+
const char *askpass;
625625
struct child_process pass;
626626
const char *args[3];
627627
static struct strbuf buffer = STRBUF_INIT;
628628

629629
askpass = getenv("GIT_ASKPASS");
630-
630+
if (!askpass)
631+
askpass = askpass_program;
632+
if (!askpass)
633+
askpass = getenv("SSH_ASKPASS");
631634
if (!askpass || !(*askpass))
632635
return getpass(prompt);
633636

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ size_t delta_base_cache_limit = 16 * 1024 * 1024;
3737
const char *pager_program;
3838
int pager_use_color = 1;
3939
const char *editor_program;
40+
const char *askpass_program;
4041
const char *excludes_file;
4142
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
4243
int read_replace_refs = 1;

git.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
5656
{
5757
int handled = 0;
5858

59-
if (!getenv("GIT_ASKPASS") && getenv("SSH_ASKPASS"))
60-
setenv("GIT_ASKPASS", getenv("SSH_ASKPASS"), 1);
61-
6259
while (*argc > 0) {
6360
const char *cmd = (*argv)[0];
6461
if (cmd[0] != '-')

0 commit comments

Comments
 (0)