mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-27 00:58:30 -05:00
The source files for libgit.a have been moved into a new "lib/" directory to clean up the top-level directory and clearly separate library code. * ps/libgit-in-subdir: Move libgit.a sources into separate "lib/" directory t/helper: prepare "test-example-tap.c" for introduction of "lib/"
90 lines
2.2 KiB
C
90 lines
2.2 KiB
C
#define USE_THE_REPOSITORY_VARIABLE
|
|
|
|
#include "git-compat-util.h"
|
|
#include "autocorrect.h"
|
|
#include "config.h"
|
|
#include "parse.h"
|
|
#include "strbuf.h"
|
|
#include "prompt.h"
|
|
#include "gettext.h"
|
|
|
|
static enum autocorrect_mode parse_autocorrect(const char *value)
|
|
{
|
|
switch (git_parse_maybe_bool_text(value)) {
|
|
case 1:
|
|
return AUTOCORRECT_IMMEDIATELY;
|
|
case 0:
|
|
return AUTOCORRECT_HINT;
|
|
default: /* other random text */
|
|
break;
|
|
}
|
|
|
|
if (!strcmp(value, "prompt"))
|
|
return AUTOCORRECT_PROMPT;
|
|
else if (!strcmp(value, "never"))
|
|
return AUTOCORRECT_NEVER;
|
|
else if (!strcmp(value, "immediate"))
|
|
return AUTOCORRECT_IMMEDIATELY;
|
|
else if (!strcmp(value, "show"))
|
|
return AUTOCORRECT_HINT;
|
|
else
|
|
return AUTOCORRECT_DELAY;
|
|
}
|
|
|
|
static int resolve_autocorrect(const char *var, const char *value,
|
|
const struct config_context *ctx, void *data)
|
|
{
|
|
struct autocorrect *conf = data;
|
|
|
|
if (strcmp(var, "help.autocorrect"))
|
|
return 0;
|
|
|
|
conf->mode = parse_autocorrect(value);
|
|
|
|
/*
|
|
* Disable autocorrection prompt in a non-interactive session
|
|
*/
|
|
if (conf->mode == AUTOCORRECT_PROMPT && (!isatty(0) || !isatty(2)))
|
|
conf->mode = AUTOCORRECT_NEVER;
|
|
|
|
if (conf->mode == AUTOCORRECT_DELAY) {
|
|
conf->delay = git_config_int(var, value, ctx->kvi);
|
|
|
|
if (!conf->delay)
|
|
conf->mode = AUTOCORRECT_HINT;
|
|
else if (conf->delay < 0 || conf->delay == 1)
|
|
conf->mode = AUTOCORRECT_IMMEDIATELY;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void autocorrect_resolve(struct autocorrect *conf)
|
|
{
|
|
read_early_config(the_repository, resolve_autocorrect, conf);
|
|
}
|
|
|
|
void autocorrect_confirm(struct autocorrect *conf, const char *assumed)
|
|
{
|
|
if (conf->mode == AUTOCORRECT_IMMEDIATELY) {
|
|
fprintf_ln(stderr,
|
|
_("Continuing under the assumption that you meant '%s'."),
|
|
assumed);
|
|
} else if (conf->mode == AUTOCORRECT_PROMPT) {
|
|
char *answer;
|
|
struct strbuf msg = STRBUF_INIT;
|
|
|
|
strbuf_addf(&msg, _("Run '%s' instead [y/N]? "), assumed);
|
|
answer = git_prompt(msg.buf, PROMPT_ECHO);
|
|
strbuf_release(&msg);
|
|
|
|
if (!(starts_with(answer, "y") || starts_with(answer, "Y")))
|
|
exit(1);
|
|
} else if (conf->mode == AUTOCORRECT_DELAY) {
|
|
fprintf_ln(stderr,
|
|
_("Continuing in %0.1f seconds, assuming that you meant '%s'."),
|
|
conf->delay / 10.0, assumed);
|
|
sleep_millisec(conf->delay * 100);
|
|
}
|
|
}
|