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