advice.con commit http: default text charset to iso-8859-1 (c553fd1)
   1#include "cache.h"
   2
   3int advice_push_update_rejected = 1;
   4int advice_push_non_ff_current = 1;
   5int advice_push_non_ff_matching = 1;
   6int advice_push_already_exists = 1;
   7int advice_push_fetch_first = 1;
   8int advice_push_needs_force = 1;
   9int advice_status_hints = 1;
  10int advice_status_u_option = 1;
  11int advice_commit_before_merge = 1;
  12int advice_resolve_conflict = 1;
  13int advice_implicit_identity = 1;
  14int advice_detached_head = 1;
  15int advice_set_upstream_failure = 1;
  16int advice_object_name_warning = 1;
  17int advice_rm_hints = 1;
  18
  19static struct {
  20        const char *name;
  21        int *preference;
  22} advice_config[] = {
  23        { "pushupdaterejected", &advice_push_update_rejected },
  24        { "pushnonffcurrent", &advice_push_non_ff_current },
  25        { "pushnonffmatching", &advice_push_non_ff_matching },
  26        { "pushalreadyexists", &advice_push_already_exists },
  27        { "pushfetchfirst", &advice_push_fetch_first },
  28        { "pushneedsforce", &advice_push_needs_force },
  29        { "statushints", &advice_status_hints },
  30        { "statusuoption", &advice_status_u_option },
  31        { "commitbeforemerge", &advice_commit_before_merge },
  32        { "resolveconflict", &advice_resolve_conflict },
  33        { "implicitidentity", &advice_implicit_identity },
  34        { "detachedhead", &advice_detached_head },
  35        { "setupstreamfailure", &advice_set_upstream_failure },
  36        { "objectnamewarning", &advice_object_name_warning },
  37        { "rmhints", &advice_rm_hints },
  38
  39        /* make this an alias for backward compatibility */
  40        { "pushnonfastforward", &advice_push_update_rejected }
  41};
  42
  43void advise(const char *advice, ...)
  44{
  45        struct strbuf buf = STRBUF_INIT;
  46        va_list params;
  47        const char *cp, *np;
  48
  49        va_start(params, advice);
  50        strbuf_vaddf(&buf, advice, params);
  51        va_end(params);
  52
  53        for (cp = buf.buf; *cp; cp = np) {
  54                np = strchrnul(cp, '\n');
  55                fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
  56                if (*np)
  57                        np++;
  58        }
  59        strbuf_release(&buf);
  60}
  61
  62int git_default_advice_config(const char *var, const char *value)
  63{
  64        const char *k = skip_prefix(var, "advice.");
  65        int i;
  66
  67        for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
  68                if (strcmp(k, advice_config[i].name))
  69                        continue;
  70                *advice_config[i].preference = git_config_bool(var, value);
  71                return 0;
  72        }
  73
  74        return 0;
  75}
  76
  77int error_resolve_conflict(const char *me)
  78{
  79        error("'%s' is not possible because you have unmerged files.", me);
  80        if (advice_resolve_conflict)
  81                /*
  82                 * Message used both when 'git commit' fails and when
  83                 * other commands doing a merge do.
  84                 */
  85                advise(_("Fix them up in the work tree,\n"
  86                         "and then use 'git add/rm <file>' as\n"
  87                         "appropriate to mark resolution and make a commit,\n"
  88                         "or use 'git commit -a'."));
  89        return -1;
  90}
  91
  92void NORETURN die_resolve_conflict(const char *me)
  93{
  94        error_resolve_conflict(me);
  95        die("Exiting because of an unresolved conflict.");
  96}
  97
  98void detach_advice(const char *new_name)
  99{
 100        const char fmt[] =
 101        "Note: checking out '%s'.\n\n"
 102        "You are in 'detached HEAD' state. You can look around, make experimental\n"
 103        "changes and commit them, and you can discard any commits you make in this\n"
 104        "state without impacting any branches by performing another checkout.\n\n"
 105        "If you want to create a new branch to retain commits you create, you may\n"
 106        "do so (now or later) by using -b with the checkout command again. Example:\n\n"
 107        "  git checkout -b new_branch_name\n\n";
 108
 109        fprintf(stderr, fmt, new_name);
 110}