t / t1507-rev-parse-upstream.shon commit conditional markdown preprocessing (c8b1cd9)
   1#!/bin/sh
   2
   3test_description='test <branch>@{upstream} syntax'
   4
   5. ./test-lib.sh
   6
   7
   8test_expect_success 'setup' '
   9
  10        test_commit 1 &&
  11        git checkout -b side &&
  12        test_commit 2 &&
  13        git checkout master &&
  14        git clone . clone &&
  15        test_commit 3 &&
  16        (cd clone &&
  17         test_commit 4 &&
  18         git branch --track my-side origin/side &&
  19         git branch --track local-master master &&
  20         git branch --track fun@ny origin/side &&
  21         git branch --track @funny origin/side &&
  22         git branch --track funny@ origin/side &&
  23         git remote add -t master master-only .. &&
  24         git fetch master-only &&
  25         git branch bad-upstream &&
  26         git config branch.bad-upstream.remote master-only &&
  27         git config branch.bad-upstream.merge refs/heads/side
  28        )
  29'
  30
  31full_name () {
  32        (cd clone &&
  33         git rev-parse --symbolic-full-name "$@")
  34}
  35
  36commit_subject () {
  37        (cd clone &&
  38         git show -s --pretty=format:%s "$@")
  39}
  40
  41error_message () {
  42        (cd clone &&
  43         test_must_fail git rev-parse --verify "$@" 2>../error)
  44}
  45
  46test_expect_success '@{upstream} resolves to correct full name' '
  47        test refs/remotes/origin/master = "$(full_name @{upstream})" &&
  48        test refs/remotes/origin/master = "$(full_name @{UPSTREAM})" &&
  49        test refs/remotes/origin/master = "$(full_name @{UpSTReam})"
  50'
  51
  52test_expect_success '@{u} resolves to correct full name' '
  53        test refs/remotes/origin/master = "$(full_name @{u})" &&
  54        test refs/remotes/origin/master = "$(full_name @{U})"
  55'
  56
  57test_expect_success 'my-side@{upstream} resolves to correct full name' '
  58        test refs/remotes/origin/side = "$(full_name my-side@{u})"
  59'
  60
  61test_expect_success 'upstream of branch with @ in middle' '
  62        full_name fun@ny@{u} >actual &&
  63        echo refs/remotes/origin/side >expect &&
  64        test_cmp expect actual &&
  65        full_name fun@ny@{U} >actual &&
  66        test_cmp expect actual
  67'
  68
  69test_expect_success 'upstream of branch with @ at start' '
  70        full_name @funny@{u} >actual &&
  71        echo refs/remotes/origin/side >expect &&
  72        test_cmp expect actual
  73'
  74
  75test_expect_success 'upstream of branch with @ at end' '
  76        full_name funny@@{u} >actual &&
  77        echo refs/remotes/origin/side >expect &&
  78        test_cmp expect actual
  79'
  80
  81test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
  82        test_must_fail full_name refs/heads/my-side@{upstream}
  83'
  84
  85test_expect_success 'my-side@{u} resolves to correct commit' '
  86        git checkout side &&
  87        test_commit 5 &&
  88        (cd clone && git fetch) &&
  89        test 2 = "$(commit_subject my-side)" &&
  90        test 5 = "$(commit_subject my-side@{u})"
  91'
  92
  93test_expect_success 'not-tracking@{u} fails' '
  94        test_must_fail full_name non-tracking@{u} &&
  95        (cd clone && git checkout --no-track -b non-tracking) &&
  96        test_must_fail full_name non-tracking@{u}
  97'
  98
  99test_expect_success '<branch>@{u}@{1} resolves correctly' '
 100        test_commit 6 &&
 101        (cd clone && git fetch) &&
 102        test 5 = $(commit_subject my-side@{u}@{1}) &&
 103        test 5 = $(commit_subject my-side@{U}@{1})
 104'
 105
 106test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
 107        git checkout HEAD^0 &&
 108        test_must_fail git rev-parse @{u} &&
 109        test_must_fail git rev-parse @{U}
 110'
 111
 112test_expect_success 'checkout -b new my-side@{u} forks from the same' '
 113(
 114        cd clone &&
 115        git checkout -b new my-side@{u} &&
 116        git rev-parse --symbolic-full-name my-side@{u} >expect &&
 117        git rev-parse --symbolic-full-name new@{u} >actual &&
 118        test_cmp expect actual
 119)
 120'
 121
 122test_expect_success 'merge my-side@{u} records the correct name' '
 123(
 124        cd clone &&
 125        git checkout master &&
 126        test_might_fail git branch -D new &&
 127        git branch -t new my-side@{u} &&
 128        git merge -s ours new@{u} &&
 129        git show -s --pretty=tformat:%s >actual &&
 130        echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect &&
 131        test_cmp expect actual
 132)
 133'
 134
 135test_expect_success 'branch -d other@{u}' '
 136        git checkout -t -b other master &&
 137        git branch -d @{u} &&
 138        git for-each-ref refs/heads/master >actual &&
 139        test_must_be_empty actual
 140'
 141
 142test_expect_success 'checkout other@{u}' '
 143        git branch -f master HEAD &&
 144        git checkout -t -b another master &&
 145        git checkout @{u} &&
 146        git symbolic-ref HEAD >actual &&
 147        echo refs/heads/master >expect &&
 148        test_cmp expect actual
 149'
 150
 151test_expect_success 'branch@{u} works when tracking a local branch' '
 152        test refs/heads/master = "$(full_name local-master@{u})"
 153'
 154
 155test_expect_success 'branch@{u} error message when no upstream' '
 156        cat >expect <<-EOF &&
 157        fatal: no upstream configured for branch ${SQ}non-tracking${SQ}
 158        EOF
 159        error_message non-tracking@{u} &&
 160        test_i18ncmp expect error
 161'
 162
 163test_expect_success '@{u} error message when no upstream' '
 164        cat >expect <<-EOF &&
 165        fatal: no upstream configured for branch ${SQ}master${SQ}
 166        EOF
 167        test_must_fail git rev-parse --verify @{u} 2>actual &&
 168        test_i18ncmp expect actual
 169'
 170
 171test_expect_success 'branch@{u} error message with misspelt branch' '
 172        cat >expect <<-EOF &&
 173        fatal: no such branch: ${SQ}no-such-branch${SQ}
 174        EOF
 175        error_message no-such-branch@{u} &&
 176        test_i18ncmp expect error
 177'
 178
 179test_expect_success '@{u} error message when not on a branch' '
 180        cat >expect <<-EOF &&
 181        fatal: HEAD does not point to a branch
 182        EOF
 183        git checkout HEAD^0 &&
 184        test_must_fail git rev-parse --verify @{u} 2>actual &&
 185        test_i18ncmp expect actual
 186'
 187
 188test_expect_success 'branch@{u} error message if upstream branch not fetched' '
 189        cat >expect <<-EOF &&
 190        fatal: upstream branch ${SQ}refs/heads/side${SQ} not stored as a remote-tracking branch
 191        EOF
 192        error_message bad-upstream@{u} &&
 193        test_i18ncmp expect error
 194'
 195
 196test_expect_success 'pull works when tracking a local branch' '
 197(
 198        cd clone &&
 199        git checkout local-master &&
 200        git pull
 201)
 202'
 203
 204# makes sense if the previous one succeeded
 205test_expect_success '@{u} works when tracking a local branch' '
 206        test refs/heads/master = "$(full_name @{u})"
 207'
 208
 209commit=$(git rev-parse HEAD)
 210cat >expect <<EOF
 211commit $commit
 212Reflog: master@{0} (C O Mitter <committer@example.com>)
 213Reflog message: branch: Created from HEAD
 214Author: A U Thor <author@example.com>
 215Date:   Thu Apr 7 15:15:13 2005 -0700
 216
 217    3
 218EOF
 219test_expect_success 'log -g other@{u}' '
 220        git log -1 -g other@{u} >actual &&
 221        test_cmp expect actual
 222'
 223
 224cat >expect <<EOF
 225commit $commit
 226Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
 227Reflog message: branch: Created from HEAD
 228Author: A U Thor <author@example.com>
 229Date:   Thu Apr 7 15:15:13 2005 -0700
 230
 231    3
 232EOF
 233
 234test_expect_success 'log -g other@{u}@{now}' '
 235        git log -1 -g other@{u}@{now} >actual &&
 236        test_cmp expect actual
 237'
 238
 239test_expect_success '@{reflog}-parsing does not look beyond colon' '
 240        echo content >@{yesterday} &&
 241        git add @{yesterday} &&
 242        git commit -m "funny reflog file" &&
 243        git hash-object @{yesterday} >expect &&
 244        git rev-parse HEAD:@{yesterday} >actual
 245'
 246
 247test_expect_success '@{upstream}-parsing does not look beyond colon' '
 248        echo content >@{upstream} &&
 249        git add @{upstream} &&
 250        git commit -m "funny upstream file" &&
 251        git hash-object @{upstream} >expect &&
 252        git rev-parse HEAD:@{upstream} >actual
 253'
 254
 255test_done