advice: Introduce error_resolve_conflict

Enable future callers to report a conflict and not die immediately by introducing a new function called error_resolve_conflict. Re-implement die_resolve_conflict as a call to error_resolve_conflict followed by a call to die. Consequently, the message printed by die_resolve_conflict changes from fatal: 'commit' is not possible because you have unmerged files. Please, fix them up in the work tree ... ... to error: 'commit' is not possible because you have unmerged files. hint: Fix them up in the work tree ... hint: ... fatal: Exiting because of an unresolved conflict. Hints are printed using the same advise function introduced in v1.7.3-rc0~26^2~3 (Introduce advise() to print hints, 2010-08-11). Inspired-by: Christian Couder <chistian.couder@gmail.com> Helped-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Aug 4, 2011 at 16:08 UTC 38ef61cfde8aea0864e898d37ce3213a5771c59e
3 files changed +26 -17
advice.c
+24 -7
@@ -19,6 +19,15 @@ static struct {
19 { "detachedhead", &advice_detached_head },
20 };
21
22 +void advise(const char *advice, ...)
23 +{
24 + va_list params;
25 +
26 + va_start(params, advice);
27 + vreportf("hint: ", advice, params);
28 + va_end(params);
29 +}
30 +
31 int git_default_advice_config(const char *var, const char *value)
32 {
33 const char *k = skip_prefix(var, "advice.");
@@ -34,16 +43,24 @@ int git_default_advice_config(const char *var, const char *value)
43 return 0;
44 }
45
37 -void NORETURN die_resolve_conflict(const char *me)
46 +int error_resolve_conflict(const char *me)
47 {
39 - if (advice_resolve_conflict)
48 + error("'%s' is not possible because you have unmerged files.", me);
49 + if (advice_resolve_conflict) {
50 /*
51 * Message used both when 'git commit' fails and when
52 * other commands doing a merge do.
53 */
44 - die("'%s' is not possible because you have unmerged files.\n"
45 - "Please, fix them up in the work tree, and then use 'git add/rm <file>' as\n"
46 - "appropriate to mark resolution and make a commit, or use 'git commit -a'.", me);
47 - else
48 - die("'%s' is not possible because you have unmerged files.", me);
54 + advise("Fix them up in the work tree,");
55 + advise("and then use 'git add/rm <file>' as");
56 + advise("appropriate to mark resolution and make a commit,");
57 + advise("or use 'git commit -a'.");
58 + }
59 + return -1;
60 +}
61 +
62 +void NORETURN die_resolve_conflict(const char *me)
63 +{
64 + error_resolve_conflict(me);
65 + die("Exiting because of an unresolved conflict.");
66 }
advice.h
+2 -1
@@ -11,7 +11,8 @@ extern int advice_implicit_identity;
11 extern int advice_detached_head;
12
13 int git_default_advice_config(const char *var, const char *value);
14 -
14 +void advise(const char *advice, ...);
15 +int error_resolve_conflict(const char *me);
16 extern void NORETURN die_resolve_conflict(const char *me);
17
18 #endif /* ADVICE_H */
builtin/revert.c
-9
@@ -214,15 +214,6 @@ static void write_cherry_pick_head(void)
214 strbuf_release(&buf);
215 }
216
217 -static void advise(const char *advice, ...)
218 -{
219 - va_list params;
220 -
221 - va_start(params, advice);
222 - vreportf("hint: ", advice, params);
223 - va_end(params);
224 -}
225 -
217 static void print_advice(void)
218 {
219 char *msg = getenv("GIT_CHERRY_PICK_HELP");