]> git.ipfire.org Git - thirdparty/git.git/commit - t/t4014-format-patch.sh
format-patch: teach format.useAutoBase "whenAble" option
authorJacob Keller <jacob.keller@gmail.com>
Thu, 1 Oct 2020 21:46:53 +0000 (14:46 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Oct 2020 22:22:10 +0000 (15:22 -0700)
commit7efba5fa39fa1608fccea51a849b36b0f85825bb
treefe40b85fef64486d6c70d994ddcc0abc68630ca5
parent9bc233ae1cf19a49e51842c7959d80a675dbd1c0
format-patch: teach format.useAutoBase "whenAble" option

The format.useAutoBase configuration option exists to allow users to
enable '--base=auto' for format-patch by default.

This can sometimes lead to poor workflow, due to unexpected failures
when attempting to format an ancient patch:

    $ git format-patch -1 <an old commit>
    fatal: base commit shouldn't be in revision list

This can be very confusing, as it is not necessarily immediately obvious
that the user requested a --base (since this was in the configuration,
not on the command line).

We do want --base=auto to fail when it cannot provide a suitable base,
as it would be equally confusing if a formatted patch did not include
the base information when it was requested.

Teach format.useAutoBase a new mode, "whenAble". This mode will cause
format-patch to attempt to include a base commit when it can. However,
if no valid base commit can be found, then format-patch will continue
formatting the patch without a base commit.

In order to avoid making yet another branch name unusable with --base,
do not teach --base=whenAble or --base=whenable.

Instead, refactor the base_commit option to use a callback, and rely on
the global configuration variable auto_base.

This does mean that a user cannot request this optional base commit
generation from the command line. However, this is likely not too
valuable. If the user requests base information manually, they will be
immediately informed of the failure to acquire a suitable base commit.
This allows the user to make an informed choice about whether to
continue the format.

Add tests to cover the new mode of operation for --base.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/format.txt
builtin/log.c
t/t4014-format-patch.sh