mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Merge branch 'ds/background-maintenance-with-credential'
Background tasks "git maintenance" runs may need to use credential information when going over the network, but a credential helper may work only in an interactive environment, and end up blocking a scheduled task waiting for UI. Credential helpers can now behave differently when they are not running interactively. * ds/background-maintenance-with-credential: scalar: configure maintenance during 'reconfigure' maintenance: add custom config to background jobs credential: add new interactive config option
This commit is contained in:
30
credential.c
30
credential.c
@@ -13,6 +13,8 @@
|
||||
#include "strbuf.h"
|
||||
#include "urlmatch.h"
|
||||
#include "git-compat-util.h"
|
||||
#include "trace2.h"
|
||||
#include "repository.h"
|
||||
|
||||
void credential_init(struct credential *c)
|
||||
{
|
||||
@@ -251,14 +253,36 @@ static char *credential_ask_one(const char *what, struct credential *c,
|
||||
return xstrdup(r);
|
||||
}
|
||||
|
||||
static void credential_getpass(struct credential *c)
|
||||
static int credential_getpass(struct credential *c)
|
||||
{
|
||||
int interactive;
|
||||
char *value;
|
||||
if (!git_config_get_maybe_bool("credential.interactive", &interactive) &&
|
||||
!interactive) {
|
||||
trace2_data_intmax("credential", the_repository,
|
||||
"interactive/skipped", 1);
|
||||
return -1;
|
||||
}
|
||||
if (!git_config_get_string("credential.interactive", &value)) {
|
||||
int same = !strcmp(value, "never");
|
||||
free(value);
|
||||
if (same) {
|
||||
trace2_data_intmax("credential", the_repository,
|
||||
"interactive/skipped", 1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
trace2_region_enter("credential", "interactive", the_repository);
|
||||
if (!c->username)
|
||||
c->username = credential_ask_one("Username", c,
|
||||
PROMPT_ASKPASS|PROMPT_ECHO);
|
||||
if (!c->password)
|
||||
c->password = credential_ask_one("Password", c,
|
||||
PROMPT_ASKPASS);
|
||||
trace2_region_leave("credential", "interactive", the_repository);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int credential_has_capability(const struct credential_capability *capa,
|
||||
@@ -501,8 +525,8 @@ void credential_fill(struct credential *c, int all_capabilities)
|
||||
c->helpers.items[i].string);
|
||||
}
|
||||
|
||||
credential_getpass(c);
|
||||
if (!c->username && !c->password && !c->credential)
|
||||
if (credential_getpass(c) ||
|
||||
(!c->username && !c->password && !c->credential))
|
||||
die("unable to get password from user");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user