Skip to content

Commit 881d72e

Browse files
committed
Merge branch 'js/rebase-stat-unrelated-fix'
"git rebase --stat" to transplant a piece of history onto a totally unrelated history were not working before and silently showed wrong result. With the recent reimplementation in C, it started to instead die with an error message, as the original logic was not prepared to cope with this case. This has now been fixed. * js/rebase-stat-unrelated-fix: rebase --stat: fix when rebasing to an unrelated history
2 parents 945f6bd + 8797f0f commit 881d72e

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

builtin/rebase.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,10 +1503,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15031503
if (options.flags & REBASE_DIFFSTAT) {
15041504
struct diff_options opts;
15051505

1506-
if (options.flags & REBASE_VERBOSE)
1507-
printf(_("Changes from %s to %s:\n"),
1508-
oid_to_hex(&merge_base),
1509-
oid_to_hex(&options.onto->object.oid));
1506+
if (options.flags & REBASE_VERBOSE) {
1507+
if (is_null_oid(&merge_base))
1508+
printf(_("Changes to %s:\n"),
1509+
oid_to_hex(&options.onto->object.oid));
1510+
else
1511+
printf(_("Changes from %s to %s:\n"),
1512+
oid_to_hex(&merge_base),
1513+
oid_to_hex(&options.onto->object.oid));
1514+
}
15101515

15111516
/* We want color (if set), but no pager */
15121517
diff_setup(&opts);
@@ -1516,8 +1521,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15161521
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
15171522
opts.detect_rename = DIFF_DETECT_RENAME;
15181523
diff_setup_done(&opts);
1519-
diff_tree_oid(&merge_base, &options.onto->object.oid,
1520-
"", &opts);
1524+
diff_tree_oid(is_null_oid(&merge_base) ?
1525+
the_hash_algo->empty_tree : &merge_base,
1526+
&options.onto->object.oid, "", &opts);
15211527
diffcore_std(&opts);
15221528
diff_flush(&opts);
15231529
}

git-legacy-rebase.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,16 @@ if test -n "$diffstat"
718718
then
719719
if test -n "$verbose"
720720
then
721-
echo "$(eval_gettext "Changes from \$mb to \$onto:")"
721+
if test -z "$mb"
722+
then
723+
echo "$(eval_gettext "Changes to \$onto:")"
724+
else
725+
echo "$(eval_gettext "Changes from \$mb to \$onto:")"
726+
fi
722727
fi
728+
mb_tree="${mb:-$(git hash-object -t tree /dev/null)}"
723729
# We want color (if set), but no pager
724-
GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
730+
GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto"
725731
fi
726732

727733
test -n "$interactive_rebase" && run_specific_rebase

t/t3406-rebase-message.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,14 @@ test_expect_success 'GIT_REFLOG_ACTION' '
117117
test_cmp expect actual
118118
'
119119

120+
test_expect_success 'rebase -i onto unrelated history' '
121+
git init unrelated &&
122+
test_commit -C unrelated 1 &&
123+
git -C unrelated remote add -f origin "$PWD" &&
124+
git -C unrelated branch --set-upstream-to=origin/master &&
125+
git -C unrelated -c core.editor=true rebase -i -v --stat >actual &&
126+
test_i18ngrep "Changes to " actual &&
127+
test_i18ngrep "5 files changed" actual
128+
'
129+
120130
test_done

0 commit comments

Comments
 (0)