Browse Source

Merge branch 'dl/rebase-with-autobase'

"git rebase" did not work well when format.useAutoBase
configuration variable is set, which has been corrected.

* dl/rebase-with-autobase:
  rebase: fix format.useAutoBase breakage
  format-patch: teach --no-base
  t4014: use test_config()
  format-patch: fix indentation
  t3400: demonstrate failure with format.useAutoBase
maint
Junio C Hamano 5 years ago
parent
commit
71a7de7a99
  1. 5
      Documentation/git-format-patch.txt
  2. 7
      builtin/log.c
  3. 3
      builtin/rebase.c
  4. 6
      t/t3400-rebase.sh
  5. 14
      t/t4014-format-patch.sh

5
Documentation/git-format-patch.txt

@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`. @@ -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

7
builtin/log.c

@ -1428,7 +1428,7 @@ static struct commit *get_base_commit(const char *base_commit, @@ -1428,7 +1428,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) {
@ -1732,6 +1732,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) @@ -1732,6 +1732,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;
@ -1995,7 +1998,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) @@ -1995,7 +1998,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);

3
builtin/rebase.c

@ -1039,7 +1039,8 @@ static int run_am(struct rebase_options *opts) @@ -1039,7 +1039,8 @@ static int run_am(struct rebase_options *opts)
argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout",
"--full-index", "--cherry-pick", "--right-only",
"--src-prefix=a/", "--dst-prefix=b/", "--no-renames",
"--no-cover-letter", "--pretty=mboxrd", "--topo-order", NULL);
"--no-cover-letter", "--pretty=mboxrd", "--topo-order",
"--no-base", NULL);
if (opts->git_format_patch_opt.len)
argv_array_split(&format_patch.args,
opts->git_format_patch_opt.buf);

6
t/t3400-rebase.sh

@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' ' @@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '
test_must_fail git rebase
'

test_expect_success 'rebase works with format.useAutoBase' '
test_config format.useAutoBase true &&
git checkout topic &&
git rebase master
'

test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
git checkout -b default-base master &&
git checkout -b default topic &&

14
t/t4014-format-patch.sh

@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross' @@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross'
test_must_fail git format-patch --base=auto -1
'

test_expect_success 'format-patch format.useAutoBaseoption' '
test_when_finished "git config --unset format.useAutoBase" &&
test_expect_success 'format-patch format.useAutoBase option' '
git checkout local &&
git config format.useAutoBase true &&
test_config format.useAutoBase true &&
git format-patch --stdout -1 >patch &&
grep "^base-commit:" patch >actual &&
git rev-parse upstream >commit-id-base &&
@ -1951,8 +1950,7 @@ test_expect_success 'format-patch format.useAutoBaseoption' ' @@ -1951,8 +1950,7 @@ test_expect_success 'format-patch format.useAutoBaseoption' '
'

test_expect_success 'format-patch --base overrides format.useAutoBase' '
test_when_finished "git config --unset format.useAutoBase" &&
git config format.useAutoBase true &&
test_config format.useAutoBase true &&
git format-patch --stdout --base=HEAD~1 -1 >patch &&
grep "^base-commit:" patch >actual &&
git rev-parse HEAD~1 >commit-id-base &&
@ -1960,6 +1958,12 @@ test_expect_success 'format-patch --base overrides format.useAutoBase' ' @@ -1960,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" \

Loading…
Cancel
Save