Code

grep doc: add --break / --heading / -W to synopsis
[git.git] / advice.c
index 0be4b5f008e1646946ba12fa5e51aa0830911ece..65a07859f261e12e88d638a1f4546583e0133d4c 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -19,6 +19,25 @@ static struct {
        { "detachedhead", &advice_detached_head },
 };
 
+void advise(const char *advice, ...)
+{
+       struct strbuf buf = STRBUF_INIT;
+       va_list params;
+       const char *cp, *np;
+
+       va_start(params, advice);
+       strbuf_addf(&buf, advice, params);
+       va_end(params);
+
+       for (cp = buf.buf; *cp; cp = np) {
+               np = strchrnul(cp, '\n');
+               fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
+               if (*np)
+                       np++;
+       }
+       strbuf_release(&buf);
+}
+
 int git_default_advice_config(const char *var, const char *value)
 {
        const char *k = skip_prefix(var, "advice.");
@@ -34,16 +53,23 @@ int git_default_advice_config(const char *var, const char *value)
        return 0;
 }
 
-void NORETURN die_resolve_conflict(const char *me)
+int error_resolve_conflict(const char *me)
 {
+       error("'%s' is not possible because you have unmerged files.", me);
        if (advice_resolve_conflict)
                /*
                 * Message used both when 'git commit' fails and when
                 * other commands doing a merge do.
                 */
-               die("'%s' is not possible because you have unmerged files.\n"
-                   "Please, fix them up in the work tree, and then use 'git add/rm <file>' as\n"
-                   "appropriate to mark resolution and make a commit, or use 'git commit -a'.", me);
-       else
-               die("'%s' is not possible because you have unmerged files.", me);
+               advise(_("Fix them up in the work tree,\n"
+                        "and then use 'git add/rm <file>' as\n"
+                        "appropriate to mark resolution and make a commit,\n"
+                        "or use 'git commit -a'."));
+       return -1;
+}
+
+void NORETURN die_resolve_conflict(const char *me)
+{
+       error_resolve_conflict(me);
+       die("Exiting because of an unresolved conflict.");
 }