1#!/bin/sh
   2test_description='branch --contains <commit>, --merged, and --no-merged'
   4. ./test-lib.sh
   6test_expect_success setup '
   8        >file &&
  10        git add file &&
  11        test_tick &&
  12        git commit -m initial &&
  13        git branch side &&
  14        echo 1 >file &&
  16        test_tick &&
  17        git commit -a -m "second on master" &&
  18        git checkout side &&
  20        echo 1 >file &&
  21        test_tick &&
  22        git commit -a -m "second on side" &&
  23        git merge master
  25'
  27test_expect_success 'branch --contains=master' '
  29        git branch --contains=master >actual &&
  31        {
  32                echo "  master" && echo "* side"
  33        } >expect &&
  34        test_cmp expect actual
  35'
  37test_expect_success 'branch --contains master' '
  39        git branch --contains master >actual &&
  41        {
  42                echo "  master" && echo "* side"
  43        } >expect &&
  44        test_cmp expect actual
  45'
  47test_expect_success 'branch --contains=side' '
  49        git branch --contains=side >actual &&
  51        {
  52                echo "* side"
  53        } >expect &&
  54        test_cmp expect actual
  55'
  57test_expect_success 'branch --contains with pattern implies --list' '
  59        git branch --contains=master master >actual &&
  61        {
  62                echo "  master"
  63        } >expect &&
  64        test_cmp expect actual
  65'
  67test_expect_success 'side: branch --merged' '
  69        git branch --merged >actual &&
  71        {
  72                echo "  master" &&
  73                echo "* side"
  74        } >expect &&
  75        test_cmp expect actual
  76'
  78test_expect_success 'branch --merged with pattern implies --list' '
  80        git branch --merged=side master >actual &&
  82        {
  83                echo "  master"
  84        } >expect &&
  85        test_cmp expect actual
  86'
  88test_expect_success 'side: branch --no-merged' '
  90        git branch --no-merged >actual &&
  92        >expect &&
  93        test_cmp expect actual
  94'
  96test_expect_success 'master: branch --merged' '
  98        git checkout master &&
 100        git branch --merged >actual &&
 101        {
 102                echo "* master"
 103        } >expect &&
 104        test_cmp expect actual
 105'
 107test_expect_success 'master: branch --no-merged' '
 109        git branch --no-merged >actual &&
 111        {
 112                echo "  side"
 113        } >expect &&
 114        test_cmp expect actual
 115'
 117test_expect_success 'branch --no-merged with pattern implies --list' '
 119        git branch --no-merged=master master >actual &&
 121        >expect &&
 122        test_cmp expect actual
 123'
 125test_expect_success 'implicit --list conflicts with modification options' '
 127        test_must_fail git branch --contains=master -d &&
 129        test_must_fail git branch --contains=master -m foo
 130'
 132# We want to set up a case where the walk for the tracking info
 134# of one branch crosses the tip of another branch (and make sure
 135# that the latter walk does not mess up our flag to see if it was
 136# merged).
 137#
 138# Here "topic" tracks "master" with one extra commit, and "zzz" points to the
 139# same tip as master The name "zzz" must come alphabetically after "topic"
 140# as we process them in that order.
 141test_expect_success 'branch --merged with --verbose' '
 142        git branch --track topic master &&
 143        git branch zzz topic &&
 144        git checkout topic &&
 145        test_commit foo &&
 146        git branch --merged topic >actual &&
 147        cat >expect <<-\EOF &&
 148          master
 149        * topic
 150          zzz
 151        EOF
 152        test_cmp expect actual &&
 153        git branch --verbose --merged topic >actual &&
 154        cat >expect <<-\EOF &&
 155          master c77a0a9 second on master
 156        * topic  2c939f4 [ahead 1] foo
 157          zzz    c77a0a9 second on master
 158        EOF
 159        test_cmp expect actual
 160'
 161test_done