From: Christian Couder Date: Thu, 25 Nov 2010 21:20:32 GMT Subject: [RFC/PATCH 01/18] advice: add error_resolve_conflict() function Message-ID: <20101125212050.5188.50630.chriscool@tuxfamily.org> In-Reply-To: <20101125210138.5188.13115.chriscool@tuxfamily.org> in case we don't want to die, but still want the right error message to be printed. Signed-off-by: Christian Couder --- advice.c | 25 +++++++++++++++++++++---- advice.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/advice.c b/advice.c index 0be4b5f..d4ba29f 100644 --- a/advice.c +++ b/advice.c @@ -34,6 +34,13 @@ int git_default_advice_config(const char *var, const char *value) return 0; } +const char unmerged_file_advice[] = + "'%s' is not possible because you have unmerged files.\n" + "Please, fix them up in the work tree, and then use 'git add/rm ' as\n" + "appropriate to mark resolution and make a commit, or use 'git commit -a'."; +const char unmerged_file_no_advice[] = + "'%s' is not possible because you have unmerged files."; + void NORETURN die_resolve_conflict(const char *me) { if (advice_resolve_conflict) @@ -41,9 +48,19 @@ void NORETURN die_resolve_conflict(const char *me) * 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 ' as\n" - "appropriate to mark resolution and make a commit, or use 'git commit -a'.", me); + die(unmerged_file_advice, me); + else + die(unmerged_file_no_advice, me); +} + +int error_resolve_conflict(const char *me) +{ + if (advice_resolve_conflict) + /* + * Message used both when 'git commit' fails and when + * other commands doing a merge do. + */ + return error(unmerged_file_advice, me); else - die("'%s' is not possible because you have unmerged files.", me); + return error(unmerged_file_no_advice, me); } diff --git a/advice.h b/advice.h index 3244ebb..7b7cea5 100644 --- a/advice.h +++ b/advice.h @@ -13,5 +13,6 @@ extern int advice_detached_head; int git_default_advice_config(const char *var, const char *value); extern void NORETURN die_resolve_conflict(const char *me); +extern int error_resolve_conflict(const char *me); #endif /* ADVICE_H */ -- 1.7.3.2.504.g59d466