When using a workflow with a default commit message template/header, git-cherry-pick should also pick that up. Users can manually read the header into the commit message, but this is simpler. Signed-off-by: Deepak Saxena <dsaxena@xxxxxxxxxx> --- We are using git to manage our kernel tree and we often cherry-pick patches from upstream and while we want to save the original commit message, we also want to apply our default commit header to the log. If this patch is not the ideal solution, please let me know how I should go about this. (I'm not on the mailing list, so please cc: me on replies) diff --git a/builtin-commit.c b/builtin-commit.c index 73f1e35..6bd937a 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -43,7 +43,8 @@ static enum { COMMIT_PARTIAL, } commit_style; -static char *logfile, *force_author, *template_file; +char *template_file; +static char *logfile, *force_author; static char *edit_message, *use_message; static int all, edit_flag, also, interactive, only, amend, signoff; static int quiet, verbose, untracked_files, no_verify, allow_empty; @@ -89,7 +90,7 @@ static struct option builtin_commit_options[] = { OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit "), OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"), OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by: header"), - OPT_STRING('t', "template", &template_file, "FILE", "use specified template file"), + OPT_STRING('t', "template", &template_file, "FILE", "use specified commit message template file"), OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"), OPT_GROUP("Commit contents options"), diff --git a/builtin-revert.c b/builtin-revert.c index 4bf8eb2..cbb57c6 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -8,6 +8,7 @@ #include "exec_cmd.h" #include "utf8.h" #include "parse-options.h" +#include "strbuf.h" /* * This implements the builtins revert and cherry-pick. @@ -49,6 +50,7 @@ static void parse_args(int argc, const char **argv) OPT_BOOLEAN('n', "no-commit", &no_commit, "don't automatically commit"), OPT_BOOLEAN('e', "edit", &edit, "edit the commit message"), OPT_BOOLEAN('x', NULL, &no_replay, "append commit name when cherry-picking"), + OPT_STRING('t', "template", &template_file, "FILE", "use specified commit message template file"), OPT_BOOLEAN('r', NULL, &noop, "no-op (backward compatibility)"), OPT_INTEGER('m', "mainline", &mainline, "parent number"), OPT_END(), @@ -249,16 +251,24 @@ static int revert_or_cherry_pick(int argc, const char **argv) { unsigned char head[20]; struct commit *base, *next, *parent; + struct strbuf sb; int i; char *oneline, *reencoded_message = NULL; const char *message, *encoding; const char *defmsg = xstrdup(git_path("MERGE_MSG")); - git_config(git_default_config); + git_config(git_commit_config); me = action == REVERT ? "revert" : "cherry-pick"; setenv(GIT_REFLOG_ACTION, me, 0); parse_args(argc, argv); + strbuf_init(&sb, 0); + if (template_file) { + if (strbuf_read_file(&sb, template_file, 0) < 0) + die("could not read %s: %s", + template_file, strerror(errno)); + } + /* this is copied from the shell script, but it's never triggered... */ if (action == REVERT && !no_replay) die("revert is incompatible with replay"); @@ -332,6 +342,8 @@ static int revert_or_cherry_pick(int argc, const char **argv) oneline = get_oneline(message); + add_to_msg(sb.buf); + if (action == REVERT) { char *oneline_body = strchr(oneline, ' '); diff --git a/commit.h b/commit.h index 10e2b5d..7746ec6 100644 --- a/commit.h +++ b/commit.h @@ -23,6 +23,7 @@ struct commit { extern int save_commit_buffer; extern const char *commit_type; +extern char *template_file; /* While we can decorate any object with a name, it's only used for commits.. */ extern struct decoration name_decoration; @@ -116,6 +117,8 @@ int in_merge_bases(struct commit *, struct commit **, int); extern int interactive_add(int argc, const char **argv, const char *prefix); extern int rerere(void); +extern int git_commit_config(const char *k, const char *v); + static inline int single_parent(struct commit *commit) { return commit->parents && !commit->parents->next; -- _____ __o Living Deepak Saxena - CarFree and CareFree (o> ------ -\<, Towards Carfree Cities 2008 - www.carfreeportland.org //\ ----- ( )/ ( ) Linux Plumber's Conference - www.linuxplumbersconf.org V_/_ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html