t / t3201-branch-contains.shon commit reflog-walk: don't free reflogs added to cache (8aae3cf)
   1#!/bin/sh
   2
   3test_description='branch --contains <commit>, --no-contains <commit> --merged, and --no-merged'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        >file &&
  10        git add file &&
  11        test_tick &&
  12        git commit -m initial &&
  13        git branch side &&
  14
  15        echo 1 >file &&
  16        test_tick &&
  17        git commit -a -m "second on master" &&
  18
  19        git checkout side &&
  20        echo 1 >file &&
  21        test_tick &&
  22        git commit -a -m "second on side" &&
  23
  24        git merge master
  25
  26'
  27
  28test_expect_success 'branch --contains=master' '
  29
  30        git branch --contains=master >actual &&
  31        {
  32                echo "  master" && echo "* side"
  33        } >expect &&
  34        test_cmp expect actual
  35
  36'
  37
  38test_expect_success 'branch --contains master' '
  39
  40        git branch --contains master >actual &&
  41        {
  42                echo "  master" && echo "* side"
  43        } >expect &&
  44        test_cmp expect actual
  45
  46'
  47
  48test_expect_success 'branch --no-contains=master' '
  49
  50        git branch --no-contains=master >actual &&
  51        >expect &&
  52        test_cmp expect actual
  53
  54'
  55
  56test_expect_success 'branch --no-contains master' '
  57
  58        git branch --no-contains master >actual &&
  59        >expect &&
  60        test_cmp expect actual
  61
  62'
  63
  64test_expect_success 'branch --contains=side' '
  65
  66        git branch --contains=side >actual &&
  67        {
  68                echo "* side"
  69        } >expect &&
  70        test_cmp expect actual
  71
  72'
  73
  74test_expect_success 'branch --no-contains=side' '
  75
  76        git branch --no-contains=side >actual &&
  77        {
  78                echo "  master"
  79        } >expect &&
  80        test_cmp expect actual
  81
  82'
  83
  84test_expect_success 'branch --contains with pattern implies --list' '
  85
  86        git branch --contains=master master >actual &&
  87        {
  88                echo "  master"
  89        } >expect &&
  90        test_cmp expect actual
  91
  92'
  93
  94test_expect_success 'branch --no-contains with pattern implies --list' '
  95
  96        git branch --no-contains=master master >actual &&
  97        >expect &&
  98        test_cmp expect actual
  99
 100'
 101
 102test_expect_success 'side: branch --merged' '
 103
 104        git branch --merged >actual &&
 105        {
 106                echo "  master" &&
 107                echo "* side"
 108        } >expect &&
 109        test_cmp expect actual
 110
 111'
 112
 113test_expect_success 'branch --merged with pattern implies --list' '
 114
 115        git branch --merged=side master >actual &&
 116        {
 117                echo "  master"
 118        } >expect &&
 119        test_cmp expect actual
 120
 121'
 122
 123test_expect_success 'side: branch --no-merged' '
 124
 125        git branch --no-merged >actual &&
 126        >expect &&
 127        test_cmp expect actual
 128
 129'
 130
 131test_expect_success 'master: branch --merged' '
 132
 133        git checkout master &&
 134        git branch --merged >actual &&
 135        {
 136                echo "* master"
 137        } >expect &&
 138        test_cmp expect actual
 139
 140'
 141
 142test_expect_success 'master: branch --no-merged' '
 143
 144        git branch --no-merged >actual &&
 145        {
 146                echo "  side"
 147        } >expect &&
 148        test_cmp expect actual
 149
 150'
 151
 152test_expect_success 'branch --no-merged with pattern implies --list' '
 153
 154        git branch --no-merged=master master >actual &&
 155        >expect &&
 156        test_cmp expect actual
 157
 158'
 159
 160test_expect_success 'implicit --list conflicts with modification options' '
 161
 162        test_must_fail git branch --contains=master -d &&
 163        test_must_fail git branch --contains=master -m foo &&
 164        test_must_fail git branch --no-contains=master -d &&
 165        test_must_fail git branch --no-contains=master -m foo
 166
 167'
 168
 169test_expect_success 'Assert that --contains only works on commits, not trees & blobs' '
 170        test_must_fail git branch --contains master^{tree} &&
 171        blob=$(git hash-object -w --stdin <<-\EOF
 172        Some blob
 173        EOF
 174        ) &&
 175        test_must_fail git branch --contains $blob &&
 176        test_must_fail git branch --no-contains $blob
 177'
 178
 179# We want to set up a case where the walk for the tracking info
 180# of one branch crosses the tip of another branch (and make sure
 181# that the latter walk does not mess up our flag to see if it was
 182# merged).
 183#
 184# Here "topic" tracks "master" with one extra commit, and "zzz" points to the
 185# same tip as master The name "zzz" must come alphabetically after "topic"
 186# as we process them in that order.
 187test_expect_success 'branch --merged with --verbose' '
 188        git branch --track topic master &&
 189        git branch zzz topic &&
 190        git checkout topic &&
 191        test_commit foo &&
 192        git branch --merged topic >actual &&
 193        cat >expect <<-\EOF &&
 194          master
 195        * topic
 196          zzz
 197        EOF
 198        test_cmp expect actual &&
 199        git branch --verbose --merged topic >actual &&
 200        cat >expect <<-\EOF &&
 201          master c77a0a9 second on master
 202        * topic  2c939f4 [ahead 1] foo
 203          zzz    c77a0a9 second on master
 204        EOF
 205        test_i18ncmp expect actual
 206'
 207
 208test_expect_success 'branch --contains combined with --no-contains' '
 209        git branch --contains zzz --no-contains topic >actual &&
 210        cat >expect <<-\EOF &&
 211          master
 212          side
 213          zzz
 214        EOF
 215        test_cmp expect actual
 216
 217'
 218
 219test_done