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