]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-commit.c
Be more user-friendly when refusing to do something because of conflict.
[thirdparty/git.git] / builtin-commit.c
index f54772f74a14e480ae978b38ce3bcd49ee994411..c58712c5393245c62edc082a168c690bd7ecb466 100644 (file)
@@ -219,6 +219,16 @@ 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_resolve_conflict("commit");
+}
+
 static char *prepare_index(int argc, const char **argv, const char *prefix, int is_status)
 {
        int fd;
@@ -258,7 +268,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");
@@ -277,7 +287,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");