mirror of
https://github.com/git/git.git
synced 2024-11-29 21:15:15 +08:00
8376a70441
When we run `branch --merged`, we use prepare_revision_walk with the merge-filter marked as UNINTERESTING. Any branch tips that are marked UNINTERESTING after it returns must be ancestors of that commit. As we iterate through the list of refs to show, we check item->commit->object.flags to see whether it was marked. This interacts badly with --verbose, which will do a separate walk to find the ahead/behind information for each branch. There are two bad things that can happen: 1. The ahead/behind walk may get the wrong results, because it can see a bogus UNINTERESTING flag leftover from the merge-filter walk. 2. We may omit some branches if their tips are involved in the ahead/behind traversal of a branch shown earlier. The ahead/behind walk carefully cleans up its commit flags, meaning it may also erase the UNINTERESTING flag that we expect to check later. We can solve this by moving the merge-filter state for each ref into its "struct ref_item" as soon as we finish the merge-filter walk. That fixes (2). Then we are free to clear the commit flags we used in the walk, fixing (1). Note that we actually do away with the matches_merge_filter helper entirely here, and inline it between the revision walk and the flag-clearing. This ensures that nobody accidentally calls it at the wrong time (it is only safe to check in that instant between the setting and clearing of the global flag). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
163 lines
3.0 KiB
Bash
Executable File
163 lines
3.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='branch --contains <commit>, --merged, and --no-merged'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
|
|
>file &&
|
|
git add file &&
|
|
test_tick &&
|
|
git commit -m initial &&
|
|
git branch side &&
|
|
|
|
echo 1 >file &&
|
|
test_tick &&
|
|
git commit -a -m "second on master" &&
|
|
|
|
git checkout side &&
|
|
echo 1 >file &&
|
|
test_tick &&
|
|
git commit -a -m "second on side" &&
|
|
|
|
git merge master
|
|
|
|
'
|
|
|
|
test_expect_success 'branch --contains=master' '
|
|
|
|
git branch --contains=master >actual &&
|
|
{
|
|
echo " master" && echo "* side"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'branch --contains master' '
|
|
|
|
git branch --contains master >actual &&
|
|
{
|
|
echo " master" && echo "* side"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'branch --contains=side' '
|
|
|
|
git branch --contains=side >actual &&
|
|
{
|
|
echo "* side"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'branch --contains with pattern implies --list' '
|
|
|
|
git branch --contains=master master >actual &&
|
|
{
|
|
echo " master"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'side: branch --merged' '
|
|
|
|
git branch --merged >actual &&
|
|
{
|
|
echo " master" &&
|
|
echo "* side"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'branch --merged with pattern implies --list' '
|
|
|
|
git branch --merged=side master >actual &&
|
|
{
|
|
echo " master"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'side: branch --no-merged' '
|
|
|
|
git branch --no-merged >actual &&
|
|
>expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'master: branch --merged' '
|
|
|
|
git checkout master &&
|
|
git branch --merged >actual &&
|
|
{
|
|
echo "* master"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'master: branch --no-merged' '
|
|
|
|
git branch --no-merged >actual &&
|
|
{
|
|
echo " side"
|
|
} >expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'branch --no-merged with pattern implies --list' '
|
|
|
|
git branch --no-merged=master master >actual &&
|
|
>expect &&
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
test_expect_success 'implicit --list conflicts with modification options' '
|
|
|
|
test_must_fail git branch --contains=master -d &&
|
|
test_must_fail git branch --contains=master -m foo
|
|
|
|
'
|
|
|
|
# We want to set up a case where the walk for the tracking info
|
|
# of one branch crosses the tip of another branch (and make sure
|
|
# that the latter walk does not mess up our flag to see if it was
|
|
# merged).
|
|
#
|
|
# Here "topic" tracks "master" with one extra commit, and "zzz" points to the
|
|
# same tip as master The name "zzz" must come alphabetically after "topic"
|
|
# as we process them in that order.
|
|
test_expect_success 'branch --merged with --verbose' '
|
|
git branch --track topic master &&
|
|
git branch zzz topic &&
|
|
git checkout topic &&
|
|
test_commit foo &&
|
|
git branch --merged topic >actual &&
|
|
cat >expect <<-\EOF &&
|
|
master
|
|
* topic
|
|
zzz
|
|
EOF
|
|
test_cmp expect actual &&
|
|
git branch --verbose --merged topic >actual &&
|
|
cat >expect <<-\EOF &&
|
|
master c77a0a9 second on master
|
|
* topic 2c939f4 [ahead 1] foo
|
|
zzz c77a0a9 second on master
|
|
EOF
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|