Skip to content

Commit

Permalink
format-patch: introduce format.outputDirectory configuration
Browse files Browse the repository at this point in the history
We can pass -o/--output-directory to the format-patch command to store
patches in some place other than the working directory. This patch
introduces format.outputDirectory configuration option for same
purpose.

The case of usage of this configuration option can be convenience
to not pass every time -o/--output-directory if an user has pattern
to store all patches in the /patches directory for example.

The format.outputDirectory has lower priority than command line
option, so if user will set format.outputDirectory and pass the
command line option, a result will be stored in a directory that
passed to command line option.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Alexander Kuleshov authored and Junio C Hamano committed Jan 13, 2016
1 parent 7548842 commit bc6bf2d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,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.outputDirectory::
Set a custom directory to store the resulting files instead of the
current working directory.

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
Expand Down
6 changes: 5 additions & 1 deletion Documentation/git-format-patch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ The names of the output files are printed to standard
output, unless the `--stdout` option is specified.

If `-o` is specified, output files are created in <dir>. Otherwise
they are created in the current working directory.
they are created in the current working directory. The default path
can be set with the 'format.outputDirectory' configuration option.
The `-o` option takes precedence over `format.outputDirectory`.
To store patches in the current working directory even when
`format.outputDirectory` points elsewhere, use `-o .`.

By default, the subject of a single patch is "[PATCH] " followed by
the concatenation of lines from the commit message up to the first blank
Expand Down
6 changes: 6 additions & 0 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ static int do_signoff;
static const char *signature = git_version_string;
static const char *signature_file;
static int config_cover_letter;
static const char *config_output_directory;

enum {
COVER_UNSET,
Expand Down Expand Up @@ -777,6 +778,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.outputdirectory"))
return git_config_string(&config_output_directory, var, value);

return git_log_config(var, value, cb);
}
Expand Down Expand Up @@ -1391,6 +1394,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
if (rev.show_notes)
init_display_notes(&rev.notes_opt);

if (!output_directory && !use_stdout)
output_directory = config_output_directory;

if (!use_stdout)
output_directory = set_outdir(prefix, output_directory);
else
Expand Down
15 changes: 15 additions & 0 deletions t/t4014-format-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1445,4 +1445,19 @@ test_expect_success 'From line has expected format' '
test_cmp from filtered
'

test_expect_success 'format-patch format.outputDirectory option' '
test_config format.outputDirectory patches &&
rm -fr patches &&
git format-patch master..side &&
test $(git rev-list master..side | wc -l) -eq $(ls patches | wc -l)
'

test_expect_success 'format-patch -o overrides format.outputDirectory' '
test_config format.outputDirectory patches &&
rm -fr patches patchset &&
git format-patch master..side -o patchset &&
test_path_is_missing patches &&
test_path_is_dir patchset
'

test_done

0 comments on commit bc6bf2d

Please sign in to comment.