diff options
| author | Junio C Hamano <gitster@pobox.com> | 2018-12-01 21:41:42 +0900 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2018-12-01 21:41:42 +0900 |
| commit | 881d72eff8b0d23c8edc6f8d9673f8daafaace6f (patch) | |
| tree | 9858e8976d76dce70351bced3cc5edb6ea3cf1bb | |
| parent | Merge branch 'js/rebase-reflog-action-fix' (diff) | |
| parent | rebase --stat: fix when rebasing to an unrelated history (diff) | |
| download | git-881d72eff8b0d23c8edc6f8d9673f8daafaace6f.tar.gz git-881d72eff8b0d23c8edc6f8d9673f8daafaace6f.zip | |
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
| -rw-r--r-- | builtin/rebase.c | 18 | ||||
| -rwxr-xr-x | git-legacy-rebase.sh | 10 | ||||
| -rwxr-xr-x | t/t3406-rebase-message.sh | 10 |
3 files changed, 30 insertions, 8 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c index ba0c3c954b..c87da417fb 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1503,10 +1503,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (options.flags & REBASE_DIFFSTAT) { struct diff_options opts; - if (options.flags & REBASE_VERBOSE) - printf(_("Changes from %s to %s:\n"), - oid_to_hex(&merge_base), - oid_to_hex(&options.onto->object.oid)); + if (options.flags & REBASE_VERBOSE) { + if (is_null_oid(&merge_base)) + printf(_("Changes to %s:\n"), + oid_to_hex(&options.onto->object.oid)); + else + printf(_("Changes from %s to %s:\n"), + oid_to_hex(&merge_base), + oid_to_hex(&options.onto->object.oid)); + } /* We want color (if set), but no pager */ diff_setup(&opts); @@ -1516,8 +1521,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; opts.detect_rename = DIFF_DETECT_RENAME; diff_setup_done(&opts); - diff_tree_oid(&merge_base, &options.onto->object.oid, - "", &opts); + diff_tree_oid(is_null_oid(&merge_base) ? + the_hash_algo->empty_tree : &merge_base, + &options.onto->object.oid, "", &opts); diffcore_std(&opts); diff_flush(&opts); } diff --git a/git-legacy-rebase.sh b/git-legacy-rebase.sh index b97ffdc9dd..b4c7dbfa57 100755 --- a/git-legacy-rebase.sh +++ b/git-legacy-rebase.sh @@ -718,10 +718,16 @@ if test -n "$diffstat" then if test -n "$verbose" then - echo "$(eval_gettext "Changes from \$mb to \$onto:")" + if test -z "$mb" + then + echo "$(eval_gettext "Changes to \$onto:")" + else + echo "$(eval_gettext "Changes from \$mb to \$onto:")" + fi fi + mb_tree="${mb:-$(git hash-object -t tree /dev/null)}" # We want color (if set), but no pager - GIT_PAGER='' git diff --stat --summary "$mb" "$onto" + GIT_PAGER='' git diff --stat --summary "$mb_tree" "$onto" fi test -n "$interactive_rebase" && run_specific_rebase diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index db8505eb86..f64b130cb8 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -117,4 +117,14 @@ test_expect_success 'GIT_REFLOG_ACTION' ' test_cmp expect actual ' +test_expect_success 'rebase -i onto unrelated history' ' + git init unrelated && + test_commit -C unrelated 1 && + git -C unrelated remote add -f origin "$PWD" && + git -C unrelated branch --set-upstream-to=origin/master && + git -C unrelated -c core.editor=true rebase -i -v --stat >actual && + test_i18ngrep "Changes to " actual && + test_i18ngrep "5 files changed" actual +' + test_done |
