]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: teach --no-base
authorDenton Liu <liu.denton@gmail.com>
Wed, 4 Dec 2019 21:25:06 +0000 (13:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Dec 2019 14:06:18 +0000 (06:06 -0800)
If `format.useAutoBase = true`, there was no way to override this from
the command-line. Teach the `--no-base` option in format-patch to
override `format.useAutoBase`.

Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-format-patch.txt
builtin/log.c
t/t4014-format-patch.sh

index 00bdf9b1251a1df819545f3da758c51cc25d7bfa..0d4f8951bbb1d1df0ebba15d2619d5a39568469d 100644 (file)
@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
   Output an all-zero hash in each patch's From header instead
   of the hash of the commit.
 
---base=<commit>::
+--[no-]base[=<commit>]::
        Record the base tree information to identify the state the
        patch series applies to.  See the BASE TREE INFORMATION section
        below for details. If <commit> is "auto", a base commit is
-       automatically chosen.
+       automatically chosen. The `--no-base` option overrides a
+       `format.useAutoBase` configuration.
 
 --root::
        Treat the revision argument as a <revision range>, even if it
index 9c44682f615f71c8824e6c386378a80af032dad9..bf904e887ffb060245d0b41c9d47a632c257533c 100644 (file)
@@ -1406,7 +1406,7 @@ static struct commit *get_base_commit(const char *base_commit,
                base = lookup_commit_reference_by_name(base_commit);
                if (!base)
                        die(_("unknown commit %s"), base_commit);
-       } else if ((base_commit && !strcmp(base_commit, "auto")) || base_auto) {
+       } else if ((base_commit && !strcmp(base_commit, "auto"))) {
                struct branch *curr_branch = branch_get(NULL);
                const char *upstream = branch_get_upstream(curr_branch, NULL);
                if (upstream) {
@@ -1710,6 +1710,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        s_r_opt.def = "HEAD";
        s_r_opt.revarg_opt = REVARG_COMMITTISH;
 
+       if (base_auto)
+               base_commit = "auto";
+
        if (default_attach) {
                rev.mime_boundary = default_attach;
                rev.no_inline = 1;
@@ -1973,7 +1976,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        }
 
        memset(&bases, 0, sizeof(bases));
-       if (base_commit || base_auto) {
+       if (base_commit) {
                struct commit *base = get_base_commit(base_commit, list, nr);
                reset_revision_walk();
                clear_object_flags(UNINTERESTING);
index c7cc643adf09a8a59491ab997ec53c175f8445b3..a5b6302a1c93c8e6ad64dd03787bf9a33f3fdf27 100755 (executable)
@@ -1958,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' '
        test_cmp expect actual
 '
 
+test_expect_success 'format-patch --no-base overrides format.useAutoBase' '
+       test_config format.useAutoBase true &&
+       git format-patch --stdout --no-base -1 >patch &&
+       ! grep "^base-commit:" patch
+'
+
 test_expect_success 'format-patch --base with --attach' '
        git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&
        sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \