From: Junio C Hamano Date: Fri, 10 Jan 2014 18:33:32 +0000 (-0800) Subject: Merge branch 'bm/merge-base-octopus-dedup' X-Git-Tag: v1.9-rc0~24 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/d5d1678b9c675a97b3ec3aaf843d02b1cf536c74 Merge branch 'bm/merge-base-octopus-dedup' "git merge-base --octopus" used to leave cleaning up suboptimal result to the caller, but now it does the clean-up itself. * bm/merge-base-octopus-dedup: merge-base --octopus: reduce the result from get_octopus_merge_bases() merge-base: separate "--independent" codepath into its own helper --- d5d1678b9c675a97b3ec3aaf843d02b1cf536c74 diff --cc builtin/merge-base.c index a2923235e1,87f4dbccae..0ecde8da30 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@@ -208,30 -122,20 +225,33 @@@ int cmd_merge_base(int argc, const cha git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0); - if (!octopus && !reduce && argc < 2) - usage_with_options(merge_base_usage, options); - if (is_ancestor && (show_all || octopus || reduce)) - die("--is-ancestor cannot be used with other options"); - if (is_ancestor) + + if (cmdmode == 'a') { + if (argc < 2) + usage_with_options(merge_base_usage, options); + if (show_all) + die("--is-ancestor cannot be used with --all"); return handle_is_ancestor(argc, argv); - if (reduce && (show_all || octopus)) - die("--independent cannot be used with other options"); + } - if (octopus) + if (cmdmode == 'r' && show_all) + die("--independent cannot be used with --all"); + - if (cmdmode == 'r' || cmdmode == 'o') - return handle_octopus(argc, argv, cmdmode == 'r', show_all); ++ if (cmdmode == 'o') + return handle_octopus(argc, argv, show_all); - else if (reduce) ++ ++ if (cmdmode == 'r') + return handle_independent(argc, argv); + if (cmdmode == 'f') { + if (argc < 1 || 2 < argc) + usage_with_options(merge_base_usage, options); + return handle_fork_point(argc, argv); + } + + if (argc < 2) + usage_with_options(merge_base_usage, options); + rev = xmalloc(argc * sizeof(*rev)); while (argc-- > 0) rev[rev_nr++] = get_commit_reference(*argv++); diff --cc t/t6010-merge-base.sh index 30a68335b3,abb5728b34..39b3238da2 --- a/t/t6010-merge-base.sh +++ b/t/t6010-merge-base.sh @@@ -230,32 -230,43 +230,71 @@@ test_expect_success 'criss-cross merge- test_cmp expected.sorted actual.sorted ' +test_expect_success 'using reflog to find the fork point' ' + git reset --hard && + git checkout -b base $E && + + ( + for count in 1 2 3 + do + git commit --allow-empty -m "Base commit #$count" && + git rev-parse HEAD >expect$count && + git checkout -B derived && + git commit --allow-empty -m "Derived #$count" && + git rev-parse HEAD >derived$count && + git checkout -B base $E || exit 1 + done + + for count in 1 2 3 + do + git merge-base --fork-point base $(cat derived$count) >actual && + test_cmp expect$count actual || exit 1 + done + + ) && + # check that we correctly default to HEAD + git checkout derived && + git merge-base --fork-point base >actual && + test_cmp expect3 actual +' + + test_expect_success 'merge-base --octopus --all for complex tree' ' + # Best common ancestor for JE, JAA and JDD is JC + # JE + # / | + # / | + # / | + # JAA / | + # |\ / | + # | \ | JDD | + # | \ |/ | | + # | JC JD | + # | | /| | + # | |/ | | + # JA | | | + # |\ /| | | + # X JB | X X + # \ \ | / / + # \__\|/___/ + # J + test_commit J && + test_commit JB && + git reset --hard J && + test_commit JC && + git reset --hard J && + test_commit JTEMP1 && + test_merge JA JB && + test_merge JAA JC && + git reset --hard J && + test_commit JTEMP2 && + test_merge JD JB && + test_merge JDD JC && + git reset --hard J && + test_commit JTEMP3 && + test_merge JE JC && + git rev-parse JC >expected && + git merge-base --all --octopus JAA JDD JE >actual && + test_cmp expected actual + ' + test_done