Merge branch 'ak/format-patch-odir-config'
authorJunio C Hamano <gitster@pobox.com>
Tue, 26 Jan 2016 23:40:30 +0000 (15:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Jan 2016 23:40:30 +0000 (15:40 -0800)
"git format-patch" learned to notice format.outputDirectory
configuration variable. This allows "-o <dir>" option to be
omitted on the command line if you always use the same directory in
your workflow.

* ak/format-patch-odir-config:
format-patch: introduce format.outputDirectory configuration

Documentation/config.txt
Documentation/git-format-patch.txt
builtin/log.c
t/t4014-format-patch.sh
index 0f710ca3c2fcdfa552c15d346af6995b599b0af4..877cbc875ec38ef7dca9f3e2a2c860ea9a2f1790 100644 (file)
@@ -1245,6 +1245,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
index b149e09065a11ecf21f166261d12cfb585f3cc50..6821441d7d7beedac1f5b322248c3012d23bb103 100644 (file)
@@ -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
index e00cea75cca8bbde28ba45359c28b5a13a1b75e7..0d738d6ddc0d6335e15392dd90e4118e2cb58b88 100644 (file)
@@ -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,
@@ -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);
 }
@@ -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
index 646c4750ec6d3003379da34ee29f247d45cf5b57..3b99434e3e6f534efe44850fef3d1d77c04f5856 100755 (executable)
@@ -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