A very common workflow for preparing patches involves working off a topic branch and generating patches against 'master' to send off to the maintainer. However, a plain $ git format-patch -o outgoing is a no-op on a topic branch, and the user has to remember to specify 'master' explicitly everytime. Save the user the extra keystrokes by introducing format.defaultTo which can contain the name of a branch against which to base patches. Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx> --- Documentation/config.txt | 4 ++++ builtin/log.c | 7 +++++++ contrib/completion/git-completion.bash | 1 + t/t4014-format-patch.sh | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index a405806..b90abd1 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1135,6 +1135,10 @@ format.coverLetter:: format-patch is invoked, but in addition can be set to "auto", to generate a cover-letter only when there's more than one patch. +format.defaultTo:: + The name of a branch against which to generate patches by + default. You'd usually want this to be 'master'. + filter.<driver>.clean:: The command which is used to convert the content of a worktree file to a blob upon checkin. See linkgit:gitattributes[5] for diff --git a/builtin/log.c b/builtin/log.c index b97373d..ebc419e 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -674,6 +674,7 @@ static int thread; static int do_signoff; static const char *signature = git_version_string; static int config_cover_letter; +static const char *config_defaultto; enum { COVER_UNSET, @@ -750,6 +751,8 @@ static int git_format_config(const char *var, const char *value, void *cb) config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF; return 0; } + if (!strcmp(var, "format.defaultto")) + return git_config_string(&config_defaultto, var, value); return git_log_config(var, value, cb); } @@ -1324,6 +1327,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) die (_("--subject-prefix and -k are mutually exclusive.")); rev.preserve_subject = keep_subject; + if (argc < 2 && config_defaultto) { + argv[1] = config_defaultto; + argc++; + } argc = setup_revisions(argc, argv, &rev, &s_r_opt); if (argc > 1) die (_("unrecognized argument: %s"), argv[1]); diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 39b81f7..75699d4 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1992,6 +1992,7 @@ _git_config () format.attach format.cc format.coverLetter + format.defaultTo format.headers format.numbered format.pretty diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 73194b2..46c0337 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1370,4 +1370,14 @@ test_expect_success 'cover letter auto user override' ' test_line_count = 2 list ' +test_expect_success 'defaultTo side' ' + mkdir -p tmp && + test_when_finished "rm -rf tmp; + git config --unset format.defaultTo" && + + git config format.defaultTo side && + git format-patch -o tmp >list && + test_line_count = 3 list +' + test_done -- 1.8.5.2.229.g4448466.dirty -- 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