47
static char *edit_message, *use_message;
48
static int all, edit_flag, also, interactive, only, amend, signoff;
49
static int quiet, verbose, untracked_files, no_verify, allow_empty;
50
+/*
51
+ * The default commit message cleanup mode will remove the lines
52
+ * beginning with # (shell comments) and leading and trailing
53
+ * whitespaces (empty lines or containing only whitespaces)
54
+ * if editor is used, and only the whitespaces if the message
55
+ * is specified explicitly.
56
+ */
57
+static enum {
58
+ CLEANUP_SPACE,
59
+ CLEANUP_NONE,
60
+ CLEANUP_ALL,
61
+} cleanup_mode;
62
+static char *cleanup_arg;
63
64
static int use_editor = 1, initial_commit, in_merge;
65
const char *only_include_assumed;
101
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
102
OPT_BOOLEAN(0, "untracked-files", &untracked_files, "show all untracked files"),
103
OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
104
+ OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
105
106
OPT_END()
107
};
360
if (fp == NULL)
361
die("could not open %s", git_path(commit_editmsg));
362
349
- stripspace(&sb, 0);
363
+ if (cleanup_mode != CLEANUP_NONE)
364
+ stripspace(&sb, 0);
365
366
if (signoff) {
367
struct strbuf sob;
426
fprintf(fp,
427
"\n"
428
"# Please enter the commit message for your changes.\n"
414
- "# (Comment lines starting with '#' will not be included)\n");
429
+ "# (Comment lines starting with '#' will ");
430
+ if (cleanup_mode == CLEANUP_ALL)
431
+ fprintf(fp, "not be included)\n");
432
+ else /* CLEANUP_SPACE, that is. */
433
+ fprintf(fp, "be kept.\n"
434
+ "# You can remove them yourself if you want to)\n");
435
if (only_include_assumed)
436
fprintf(fp, "# %s\n", only_include_assumed);
437
455
const char *nl;
456
int eol, i;
457
458
+ if (cleanup_mode == CLEANUP_NONE && sb->len)
459
+ return 0;
460
+
461
/* See if the template is just a prefix of the message. */
462
strbuf_init(&tmpl, 0);
463
if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) {
441
- stripspace(&tmpl, 1);
464
+ stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
465
if (start + tmpl.len <= sb->len &&
466
memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0)
467
start += tmpl.len;
614
only_include_assumed = "Explicit paths specified without -i nor -o; assuming --only paths...";
615
also = 0;
616
}
617
+ if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
618
+ cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
619
+ else if (!strcmp(cleanup_arg, "verbatim"))
620
+ cleanup_mode = CLEANUP_NONE;
621
+ else if (!strcmp(cleanup_arg, "whitespace"))
622
+ cleanup_mode = CLEANUP_SPACE;
623
+ else if (!strcmp(cleanup_arg, "strip"))
624
+ cleanup_mode = CLEANUP_ALL;
625
+ else
626
+ die("Invalid cleanup mode %s", cleanup_arg);
627
628
if (all && argc > 0)
629
die("Paths with -a does not make sense.");
850
if (p != NULL)
851
strbuf_setlen(&sb, p - sb.buf + 1);
852
820
- stripspace(&sb, 1);
853
+ if (cleanup_mode != CLEANUP_NONE)
854
+ stripspace(&sb, cleanup_mode == CLEANUP_ALL);
855
if (sb.len < header_len || message_is_empty(&sb, header_len)) {
856
rollback_index_files();
857
die("no commit message? aborting commit.");