git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org
Cc: Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [RFC/PATCH] commit: make the error message on unmerged entries user-friendly.
Date: Wed,  6 Jan 2010 14:10:14 +0100	[thread overview]
Message-ID: <1262783414-23101-1-git-send-email-Matthieu.Moy@imag.fr> (raw)

The error message used to look like this:

$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees

The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
As usual, I try to have error messages point to the solution, not just
the origin of the problem.

Two questions:

* Did anyone actually use the 3 "file: unmerged (sha1)" lines?

* Do you like my new message?

Thanks,

 builtin-commit.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index 3dfcd77..d491a01 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -235,6 +235,18 @@ static void create_base_index(void)
 		exit(128); /* We've already reported the error, finish dying */
 }
 
+static void refresh_cache_or_die(int refresh_flags)
+{
+	/*
+	 * refresh_flags contains REFRESH_QUIET, so the only errors
+	 * are for unmerged entries.
+	*/
+	if(refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))
+		die("Commit is not possible because you have unmerged files.\n"
+		    "Please, resolve the conflicts listed above, and then mark them\n"
+		    "as resolved with 'git add <filename>', or use 'git commit -a'.");
+}
+
 static char *prepare_index(int argc, const char **argv, const char *prefix, int is_status)
 {
 	int fd;
@@ -274,7 +286,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
 	if (all || (also && pathspec && *pathspec)) {
 		int fd = hold_locked_index(&index_lock, 1);
 		add_files_to_cache(also ? prefix : NULL, pathspec, 0);
-		refresh_cache(refresh_flags);
+		refresh_cache_or_die(refresh_flags);
 		if (write_cache(fd, active_cache, active_nr) ||
 		    close_lock_file(&index_lock))
 			die("unable to write new_index file");
@@ -293,7 +305,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
 	 */
 	if (!pathspec || !*pathspec) {
 		fd = hold_locked_index(&index_lock, 1);
-		refresh_cache(refresh_flags);
+		refresh_cache_or_die(refresh_flags);
 		if (write_cache(fd, active_cache, active_nr) ||
 		    commit_locked_index(&index_lock))
 			die("unable to write new_index file");
-- 
1.6.6.76.gd6b23.dirty

             reply	other threads:[~2010-01-06 13:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-06 13:10 Matthieu Moy [this message]
2010-01-06 17:13 ` [RFC/PATCH] commit: make the error message on unmerged entries user-friendly Junio C Hamano
2010-01-06 17:49   ` Matthieu Moy
2010-01-06 18:15     ` Junio C Hamano
2010-01-06 19:53       ` Matthieu Moy
2010-01-06 20:05         ` Junio C Hamano
2010-01-06 20:15           ` Matthieu Moy
2010-01-06 20:17             ` [PATCH v2] Be more user-friendly when refusing to do something because of conflict Matthieu Moy
2010-01-06 20:36               ` [PATCH v3] " Matthieu Moy
2010-01-06 21:04               ` [PATCH v2] " Junio C Hamano
2010-01-07 15:34                 ` Matthieu Moy
2010-01-07 15:35                   ` [PATCH v4] " Matthieu Moy
2010-01-07 18:10                     ` [PATCH v5] " Matthieu Moy
2010-01-13  6:56                       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1262783414-23101-1-git-send-email-Matthieu.Moy@imag.fr \
    --to=matthieu.moy@imag.fr \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).