Use commit template when cherry picking
PATCH 1/1 Use commit template when cherry picking
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.
---
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)
builtin-commit.c +3 -2
@@ -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"),
builtin-revert.c +13 -1
@@ -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,' ' );
commit.h +3 -0
@@ -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;
Signature · 4 lines
_____ __o Living Deepak Saxena - CarFree and CareFree (o> ------ -\<, Towards Carfree Cities 2008 - www.carfreeportland.org //\ ----- ( )/ ( ) Linux Plumber's Conference - www.linuxplumbersconf.org V_/_ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi,
Quoted 5 lines · Deepak Saxena
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 would do a combination of "cherry-pick -n", "cat-file commit <commit> | sed '1,/^$/d'" and "commit -F" or "commit -f".
You can make this an alias, too.
Hth,
Dscho
Quoted 2 lines · Johannes Schindelin
I would do a combination of "cherry-pick -n", "cat-file commit <commit> | sed '1,/^$/d'" and "commit -F" or "commit -f".
Doesn't cherry-pick have -e switch to allow you further edit the message?
Hi,
Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Johannes Schindelin
I would do a combination of "cherry-pick -n", "cat-file commit <commit> | sed '1,/^$/d'" and "commit -F" or "commit -f".
Doesn't cherry-pick have -e switch to allow you further edit the message?
Good point. But nevertheless, Deepak wanted to have a template which is automatically added, and I think the only way to do that right now is as I described.
Ciao,
Dscho