Code

fmt-merge-msg -m to override merge title
authorJonathan Nieder <jrnieder@gmail.com>
Tue, 17 Aug 2010 23:00:34 +0000 (18:00 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2010 21:02:04 +0000 (14:02 -0700)
Since v1.7.1.1~23^2 (merge: --log appends shortlog to message if
specified, 2010-05-11), the fmt-merge-msg backend supports custom text
to override the merge title "Merge <foo> into <bar>".

Expose this functionality for scripted callers.  Example:

 git fmt-merge-msg --log -m \
"$(printf '%s\n' \
    "Merge branch 'api-cleanup' into feature" \
    '' \
    'This is to use a few functions refactored for this purpose.'
)" <.git/FETCH_HEAD

Cc: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-fmt-merge-msg.txt
builtin/fmt-merge-msg.c
t/t6200-fmt-merge-msg.sh

index a585dbe898171ddb8a205cc5a898d695540f80a6..302f56b88941cfaa002a8b75c078335bf8d86276 100644 (file)
@@ -9,8 +9,8 @@ git-fmt-merge-msg - Produce a merge commit message
 SYNOPSIS
 --------
 [verse]
-'git fmt-merge-msg' [--log | --no-log] <$GIT_DIR/FETCH_HEAD
-'git fmt-merge-msg' [--log | --no-log] -F <file>
+'git fmt-merge-msg' [-m <message>] [--log | --no-log] <$GIT_DIR/FETCH_HEAD
+'git fmt-merge-msg' [-m <message>] [--log | --no-log] -F <file>
 
 DESCRIPTION
 -----------
@@ -38,6 +38,11 @@ OPTIONS
        Synonyms to --log and --no-log; these are deprecated and will be
        removed in the future.
 
+-m <message>::
+--message <message>::
+       Use <message> instead of the branch names for the first line
+       of the log message.  For use with `--log`.
+
 -F <file>::
 --file <file>::
        Take the list of merged objects from <file> instead of
index bc3c5e6d3ec50eaa9829358ee0a82a1438c19f89..937d5a717ba3dd71e908f59297a5085e31b48c07 100644 (file)
@@ -7,7 +7,7 @@
 #include "string-list.h"
 
 static const char * const fmt_merge_msg_usage[] = {
-       "git fmt-merge-msg [--log|--no-log] [--file <file>]",
+       "git fmt-merge-msg [-m <message>] [--log|--no-log] [--file <file>]",
        NULL
 };
 
@@ -319,11 +319,14 @@ int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) {
 int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 {
        const char *inpath = NULL;
+       const char *message = NULL;
        struct option options[] = {
                OPT_BOOLEAN(0, "log",     &merge_summary, "populate log with the shortlog"),
                { OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL,
                  "alias for --log (deprecated)",
                  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
+               OPT_STRING('m', "message", &message, "text",
+                       "use <text> as start of message"),
                OPT_FILENAME('F', "file", &inpath, "file to read from"),
                OPT_END()
        };
@@ -337,6 +340,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
                             0);
        if (argc > 0)
                usage_with_options(fmt_merge_msg_usage, options);
+       if (message && !merge_summary) {
+               char nl = '\n';
+               write_in_full(STDOUT_FILENO, message, strlen(message));
+               write_in_full(STDOUT_FILENO, &nl, 1);
+               return 0;
+       }
 
        if (inpath && strcmp(inpath, "-")) {
                in = fopen(inpath, "r");
@@ -346,7 +355,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 
        if (strbuf_read(&input, fileno(in), 0) < 0)
                die_errno("could not read input file");
-       ret = fmt_merge_msg(merge_summary, &input, &output);
+       if (message) {
+               strbuf_addstr(&output, message);
+               ret = fmt_merge_msg_shortlog(&input, &output);
+       } else {
+               ret = fmt_merge_msg(merge_summary, &input, &output);
+       }
        if (ret)
                return ret;
        write_in_full(STDOUT_FILENO, output.buf, output.len);
index 5553dff55a0a0319ec3d36b6259483077ecb1daa..71f6cad3c2b8e8ed0b16d292f4922760901702ef 100755 (executable)
@@ -129,6 +129,38 @@ test_expect_success '[merge] summary/log configuration' '
        test_cmp expected actual2
 '
 
+test_expect_success 'fmt-merge-msg -m' '
+       echo "Sync with left" >expected &&
+       cat >expected.log <<-EOF &&
+       Sync with left
+
+       * ${apos}left${apos} of $(pwd):
+         Left #5
+         Left #4
+         Left #3
+         Common #2
+         Common #1
+       EOF
+
+       test_might_fail git config --unset merge.log &&
+       test_might_fail git config --unset merge.summary &&
+       git checkout master &&
+       git fetch "$(pwd)" left &&
+       git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
+       git fmt-merge-msg --log -m "Sync with left" \
+                                       <.git/FETCH_HEAD >actual.log &&
+       git config merge.log true &&
+       git fmt-merge-msg -m "Sync with left" \
+                                       <.git/FETCH_HEAD >actual.log-config &&
+       git fmt-merge-msg --no-log -m "Sync with left" \
+                                       <.git/FETCH_HEAD >actual.nolog &&
+
+       test_cmp expected actual &&
+       test_cmp expected.log actual.log &&
+       test_cmp expected.log actual.log-config &&
+       test_cmp expected actual.nolog
+'
+
 test_expect_success 'setup: expected shortlog for two branches' '
        cat >expected <<-EOF
        Merge branches ${apos}left${apos} and ${apos}right${apos}