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