t / t1507-rev-parse-upstream.shon commit Merge branch 'rs/commit-m-no-edit' into maint (ee1a1dd)
   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 remote add -t master master-only .. &&
  21         git fetch master-only &&
  22         git branch bad-upstream &&
  23         git config branch.bad-upstream.remote master-only &&
  24         git config branch.bad-upstream.merge refs/heads/side
  25        )
  26'
  27
  28sq="'"
  29
  30full_name () {
  31        (cd clone &&
  32         git rev-parse --symbolic-full-name "$@")
  33}
  34
  35commit_subject () {
  36        (cd clone &&
  37         git show -s --pretty=format:%s "$@")
  38}
  39
  40error_message () {
  41        (cd clone &&
  42         test_must_fail git rev-parse --verify "$@")
  43}
  44
  45test_expect_success '@{upstream} resolves to correct full name' '
  46        test refs/remotes/origin/master = "$(full_name @{upstream})"
  47'
  48
  49test_expect_success '@{u} resolves to correct full name' '
  50        test refs/remotes/origin/master = "$(full_name @{u})"
  51'
  52
  53test_expect_success 'my-side@{upstream} resolves to correct full name' '
  54        test refs/remotes/origin/side = "$(full_name my-side@{u})"
  55'
  56
  57test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' '
  58        test_must_fail full_name refs/heads/my-side@{upstream}
  59'
  60
  61test_expect_success 'my-side@{u} resolves to correct commit' '
  62        git checkout side &&
  63        test_commit 5 &&
  64        (cd clone && git fetch) &&
  65        test 2 = "$(commit_subject my-side)" &&
  66        test 5 = "$(commit_subject my-side@{u})"
  67'
  68
  69test_expect_success 'not-tracking@{u} fails' '
  70        test_must_fail full_name non-tracking@{u} &&
  71        (cd clone && git checkout --no-track -b non-tracking) &&
  72        test_must_fail full_name non-tracking@{u}
  73'
  74
  75test_expect_success '<branch>@{u}@{1} resolves correctly' '
  76        test_commit 6 &&
  77        (cd clone && git fetch) &&
  78        test 5 = $(commit_subject my-side@{u}@{1})
  79'
  80
  81test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
  82        git checkout HEAD^0 &&
  83        test_must_fail git rev-parse @{u}
  84'
  85
  86test_expect_success 'checkout -b new my-side@{u} forks from the same' '
  87(
  88        cd clone &&
  89        git checkout -b new my-side@{u} &&
  90        git rev-parse --symbolic-full-name my-side@{u} >expect &&
  91        git rev-parse --symbolic-full-name new@{u} >actual &&
  92        test_cmp expect actual
  93)
  94'
  95
  96test_expect_success 'merge my-side@{u} records the correct name' '
  97(
  98        cd clone || exit
  99        git checkout master || exit
 100        git branch -D new ;# can fail but is ok
 101        git branch -t new my-side@{u} &&
 102        git merge -s ours new@{u} &&
 103        git show -s --pretty=format:%s >actual &&
 104        echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect &&
 105        test_cmp expect actual
 106)
 107'
 108
 109test_expect_success 'branch -d other@{u}' '
 110        git checkout -t -b other master &&
 111        git branch -d @{u} &&
 112        git for-each-ref refs/heads/master >actual &&
 113        >expect &&
 114        test_cmp expect actual
 115'
 116
 117test_expect_success 'checkout other@{u}' '
 118        git branch -f master HEAD &&
 119        git checkout -t -b another master &&
 120        git checkout @{u} &&
 121        git symbolic-ref HEAD >actual &&
 122        echo refs/heads/master >expect &&
 123        test_cmp expect actual
 124'
 125
 126test_expect_success 'branch@{u} works when tracking a local branch' '
 127        test refs/heads/master = "$(full_name local-master@{u})"
 128'
 129
 130test_expect_success 'branch@{u} error message when no upstream' '
 131        cat >expect <<-EOF &&
 132        error: No upstream configured for branch ${sq}non-tracking${sq}
 133        fatal: Needed a single revision
 134        EOF
 135        error_message non-tracking@{u} 2>actual &&
 136        test_i18ncmp expect actual
 137'
 138
 139test_expect_success '@{u} error message when no upstream' '
 140        cat >expect <<-EOF &&
 141        error: No upstream configured for branch ${sq}master${sq}
 142        fatal: Needed a single revision
 143        EOF
 144        test_must_fail git rev-parse --verify @{u} 2>actual &&
 145        test_i18ncmp expect actual
 146'
 147
 148test_expect_success 'branch@{u} error message with misspelt branch' '
 149        cat >expect <<-EOF &&
 150        error: No such branch: ${sq}no-such-branch${sq}
 151        fatal: Needed a single revision
 152        EOF
 153        error_message no-such-branch@{u} 2>actual &&
 154        test_i18ncmp expect actual
 155'
 156
 157test_expect_success '@{u} error message when not on a branch' '
 158        cat >expect <<-EOF &&
 159        error: HEAD does not point to a branch
 160        fatal: Needed a single revision
 161        EOF
 162        git checkout HEAD^0 &&
 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 if upstream branch not fetched' '
 168        cat >expect <<-EOF &&
 169        error: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
 170        fatal: Needed a single revision
 171        EOF
 172        error_message bad-upstream@{u} 2>actual &&
 173        test_i18ncmp expect actual
 174'
 175
 176test_expect_success 'pull works when tracking a local branch' '
 177(
 178        cd clone &&
 179        git checkout local-master &&
 180        git pull
 181)
 182'
 183
 184# makes sense if the previous one succeeded
 185test_expect_success '@{u} works when tracking a local branch' '
 186        test refs/heads/master = "$(full_name @{u})"
 187'
 188
 189cat >expect <<EOF
 190commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
 191Reflog: master@{0} (C O Mitter <committer@example.com>)
 192Reflog message: branch: Created from HEAD
 193Author: A U Thor <author@example.com>
 194Date:   Thu Apr 7 15:15:13 2005 -0700
 195
 196    3
 197EOF
 198test_expect_success 'log -g other@{u}' '
 199        git log -1 -g other@{u} >actual &&
 200        test_cmp expect actual
 201'
 202
 203cat >expect <<EOF
 204commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
 205Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
 206Reflog message: branch: Created from HEAD
 207Author: A U Thor <author@example.com>
 208Date:   Thu Apr 7 15:15:13 2005 -0700
 209
 210    3
 211EOF
 212
 213test_expect_success 'log -g other@{u}@{now}' '
 214        git log -1 -g other@{u}@{now} >actual &&
 215        test_cmp expect actual
 216'
 217
 218test_done