Skip to content

Commit 71a7de7

Browse files
committed
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
2 parents c9f5fc9 + cae0bc0 commit 71a7de7

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

Documentation/git-format-patch.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,12 @@ you can use `--suffix=-patch` to get `0001-description-of-my-change-patch`.
333333
Output an all-zero hash in each patch's From header instead
334334
of the hash of the commit.
335335

336-
--base=<commit>::
336+
--[no-]base[=<commit>]::
337337
Record the base tree information to identify the state the
338338
patch series applies to. See the BASE TREE INFORMATION section
339339
below for details. If <commit> is "auto", a base commit is
340-
automatically chosen.
340+
automatically chosen. The `--no-base` option overrides a
341+
`format.useAutoBase` configuration.
341342

342343
--root::
343344
Treat the revision argument as a <revision range>, even if it

builtin/log.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
13721372
string_list_clear(&extra_to, 0);
13731373
string_list_clear(&extra_cc, 0);
13741374
} else {
1375-
add_header(arg);
1375+
add_header(arg);
13761376
}
13771377
return 0;
13781378
}
@@ -1428,7 +1428,7 @@ static struct commit *get_base_commit(const char *base_commit,
14281428
base = lookup_commit_reference_by_name(base_commit);
14291429
if (!base)
14301430
die(_("unknown commit %s"), base_commit);
1431-
} else if ((base_commit && !strcmp(base_commit, "auto")) || base_auto) {
1431+
} else if ((base_commit && !strcmp(base_commit, "auto"))) {
14321432
struct branch *curr_branch = branch_get(NULL);
14331433
const char *upstream = branch_get_upstream(curr_branch, NULL);
14341434
if (upstream) {
@@ -1732,6 +1732,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
17321732
s_r_opt.def = "HEAD";
17331733
s_r_opt.revarg_opt = REVARG_COMMITTISH;
17341734

1735+
if (base_auto)
1736+
base_commit = "auto";
1737+
17351738
if (default_attach) {
17361739
rev.mime_boundary = default_attach;
17371740
rev.no_inline = 1;
@@ -1995,7 +1998,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19951998
}
19961999

19972000
memset(&bases, 0, sizeof(bases));
1998-
if (base_commit || base_auto) {
2001+
if (base_commit) {
19992002
struct commit *base = get_base_commit(base_commit, list, nr);
20002003
reset_revision_walk();
20012004
clear_object_flags(UNINTERESTING);

builtin/rebase.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,8 @@ static int run_am(struct rebase_options *opts)
10391039
argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout",
10401040
"--full-index", "--cherry-pick", "--right-only",
10411041
"--src-prefix=a/", "--dst-prefix=b/", "--no-renames",
1042-
"--no-cover-letter", "--pretty=mboxrd", "--topo-order", NULL);
1042+
"--no-cover-letter", "--pretty=mboxrd", "--topo-order",
1043+
"--no-base", NULL);
10431044
if (opts->git_format_patch_opt.len)
10441045
argv_array_split(&format_patch.args,
10451046
opts->git_format_patch_opt.buf);

t/t3400-rebase.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ test_expect_success 'fail when upstream arg is missing and not configured' '
159159
test_must_fail git rebase
160160
'
161161

162+
test_expect_success 'rebase works with format.useAutoBase' '
163+
test_config format.useAutoBase true &&
164+
git checkout topic &&
165+
git rebase master
166+
'
167+
162168
test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' '
163169
git checkout -b default-base master &&
164170
git checkout -b default topic &&

t/t4014-format-patch.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,10 +1939,9 @@ test_expect_success 'format-patch errors out when history involves criss-cross'
19391939
test_must_fail git format-patch --base=auto -1
19401940
'
19411941

1942-
test_expect_success 'format-patch format.useAutoBaseoption' '
1943-
test_when_finished "git config --unset format.useAutoBase" &&
1942+
test_expect_success 'format-patch format.useAutoBase option' '
19441943
git checkout local &&
1945-
git config format.useAutoBase true &&
1944+
test_config format.useAutoBase true &&
19461945
git format-patch --stdout -1 >patch &&
19471946
grep "^base-commit:" patch >actual &&
19481947
git rev-parse upstream >commit-id-base &&
@@ -1951,15 +1950,20 @@ test_expect_success 'format-patch format.useAutoBaseoption' '
19511950
'
19521951

19531952
test_expect_success 'format-patch --base overrides format.useAutoBase' '
1954-
test_when_finished "git config --unset format.useAutoBase" &&
1955-
git config format.useAutoBase true &&
1953+
test_config format.useAutoBase true &&
19561954
git format-patch --stdout --base=HEAD~1 -1 >patch &&
19571955
grep "^base-commit:" patch >actual &&
19581956
git rev-parse HEAD~1 >commit-id-base &&
19591957
echo "base-commit: $(cat commit-id-base)" >expect &&
19601958
test_cmp expect actual
19611959
'
19621960

1961+
test_expect_success 'format-patch --no-base overrides format.useAutoBase' '
1962+
test_config format.useAutoBase true &&
1963+
git format-patch --stdout --no-base -1 >patch &&
1964+
! grep "^base-commit:" patch
1965+
'
1966+
19631967
test_expect_success 'format-patch --base with --attach' '
19641968
git format-patch --attach=mimemime --stdout --base=HEAD~ -1 >patch &&
19651969
sed -n -e "/^base-commit:/s/.*/1/p" -e "/^---*mimemime--$/s/.*/2/p" \

0 commit comments

Comments
 (0)