git-commit: remove lego in i18n messages
[gitweb.git] / builtin / commit.c
index 7808be30e181e9cc4f031cdfea3b155f32970da8..c7c491e2506f82497be9ea1b51000903b9d3b9a3 100644 (file)
@@ -194,24 +194,6 @@ static void determine_whence(struct wt_status *s)
                s->whence = whence;
 }
 
-static const char *whence_s(void)
-{
-       const char *s = "";
-
-       switch (whence) {
-       case FROM_COMMIT:
-               break;
-       case FROM_MERGE:
-               s = _("merge");
-               break;
-       case FROM_CHERRY_PICK:
-               s = _("cherry-pick");
-               break;
-       }
-
-       return s;
-}
-
 static void rollback_index_files(void)
 {
        switch (commit_style) {
@@ -453,8 +435,12 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
         */
        commit_style = COMMIT_PARTIAL;
 
-       if (whence != FROM_COMMIT)
-               die(_("cannot do a partial commit during a %s."), whence_s());
+       if (whence != FROM_COMMIT) {
+               if (whence == FROM_MERGE)
+                       die(_("cannot do a partial commit during a merge."));
+               else if (whence == FROM_CHERRY_PICK)
+                       die(_("cannot do a partial commit during a cherry-pick."));
+       }
 
        memset(&partial, 0, sizeof(partial));
        partial.strdup_strings = 1;
@@ -796,13 +782,17 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                char *ai_tmp, *ci_tmp;
                if (whence != FROM_COMMIT)
                        status_printf_ln(s, GIT_COLOR_NORMAL,
-                               _("\n"
-                               "It looks like you may be committing a %s.\n"
-                               "If this is not correct, please remove the file\n"
-                               "       %s\n"
-                               "and try again.\n"
-                               ""),
-                               whence_s(),
+                           whence == FROM_MERGE
+                               ? _("\n"
+                                       "It looks like you may be committing a merge.\n"
+                                       "If this is not correct, please remove the file\n"
+                                       "       %s\n"
+                                       "and try again.\n")
+                               : _("\n"
+                                       "It looks like you may be committing a cherry-pick.\n"
+                                       "If this is not correct, please remove the file\n"
+                                       "       %s\n"
+                                       "and try again.\n"),
                                git_path(whence == FROM_MERGE
                                         ? "MERGE_HEAD"
                                         : "CHERRY_PICK_HEAD"));
@@ -921,27 +911,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        return 1;
 }
 
-/*
- * Find out if the message in the strbuf contains only whitespace and
- * Signed-off-by lines.
- */
-static int message_is_empty(struct strbuf *sb)
+static int rest_is_empty(struct strbuf *sb, int start)
 {
-       struct strbuf tmpl = STRBUF_INIT;
+       int i, eol;
        const char *nl;
-       int eol, i, start = 0;
-
-       if (cleanup_mode == CLEANUP_NONE && sb->len)
-               return 0;
-
-       /* See if the template is just a prefix of the message. */
-       if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) {
-               stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
-               if (start + tmpl.len <= sb->len &&
-                   memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0)
-                       start += tmpl.len;
-       }
-       strbuf_release(&tmpl);
 
        /* Check if the rest is just whitespace and Signed-of-by's. */
        for (i = start; i < sb->len; i++) {
@@ -964,6 +937,40 @@ static int message_is_empty(struct strbuf *sb)
        return 1;
 }
 
+/*
+ * Find out if the message in the strbuf contains only whitespace and
+ * Signed-off-by lines.
+ */
+static int message_is_empty(struct strbuf *sb)
+{
+       if (cleanup_mode == CLEANUP_NONE && sb->len)
+               return 0;
+       return rest_is_empty(sb, 0);
+}
+
+/*
+ * See if the user edited the message in the editor or left what
+ * was in the template intact
+ */
+static int template_untouched(struct strbuf *sb)
+{
+       struct strbuf tmpl = STRBUF_INIT;
+       char *start;
+
+       if (cleanup_mode == CLEANUP_NONE && sb->len)
+               return 0;
+
+       if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0)
+               return 0;
+
+       stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
+       start = (char *)skip_prefix(sb->buf, tmpl.buf);
+       if (!start)
+               start = sb->buf;
+       strbuf_release(&tmpl);
+       return rest_is_empty(sb, start - sb->buf);
+}
+
 static const char *find_author_by_nickname(const char *name)
 {
        struct rev_info revs;
@@ -1055,8 +1062,12 @@ static int parse_and_validate_options(int argc, const char *argv[],
        /* Sanity check options */
        if (amend && !current_head)
                die(_("You have nothing to amend."));
-       if (amend && whence != FROM_COMMIT)
-               die(_("You are in the middle of a %s -- cannot amend."), whence_s());
+       if (amend && whence != FROM_COMMIT) {
+               if (whence == FROM_MERGE)
+                       die(_("You are in the middle of a merge -- cannot amend."));
+               else if (whence == FROM_CHERRY_PICK)
+                       die(_("You are in the middle of a cherry-pick -- cannot amend."));
+       }
        if (fixup_message && squash_message)
                die(_("Options --squash and --fixup cannot be used together"));
        if (use_message)
@@ -1071,6 +1082,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
                die(_("Only one of -c/-C/-F/--fixup can be used."));
        if (message.len && f > 0)
                die((_("Option -m cannot be combined with -c/-C/-F/--fixup.")));
+       if (f || message.len)
+               template_file = NULL;
        if (edit_message)
                use_message = edit_message;
        if (amend && !use_message && !fixup_message)
@@ -1510,6 +1523,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
        if (cleanup_mode != CLEANUP_NONE)
                stripspace(&sb, cleanup_mode == CLEANUP_ALL);
+       if (template_untouched(&sb) && !allow_empty_message) {
+               rollback_index_files();
+               fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
+               exit(1);
+       }
        if (message_is_empty(&sb) && !allow_empty_message) {
                rollback_index_files();
                fprintf(stderr, _("Aborting commit due to empty commit message.\n"));