t / t1507-rev-parse-upstream.shon commit Emit a whole line in one go (2efcc97)
   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
  20'
  21
  22full_name () {
  23        (cd clone &&
  24         git rev-parse --symbolic-full-name "$@")
  25}
  26
  27commit_subject () {
  28        (cd clone &&
  29         git show -s --pretty=format:%s "$@")
  30}
  31
  32test_expect_success '@{upstream} resolves to correct full name' '
  33        test refs/remotes/origin/master = "$(full_name @{upstream})"
  34'
  35
  36test_expect_success '@{u} resolves to correct full name' '
  37        test refs/remotes/origin/master = "$(full_name @{u})"
  38'
  39
  40test_expect_success 'my-side@{upstream} resolves to correct full name' '
  41        test refs/remotes/origin/side = "$(full_name my-side@{u})"
  42'
  43
  44test_expect_success 'my-side@{u} resolves to correct commit' '
  45        git checkout side &&
  46        test_commit 5 &&
  47        (cd clone && git fetch) &&
  48        test 2 = "$(commit_subject my-side)" &&
  49        test 5 = "$(commit_subject my-side@{u})"
  50'
  51
  52test_expect_success 'not-tracking@{u} fails' '
  53        test_must_fail full_name non-tracking@{u} &&
  54        (cd clone && git checkout --no-track -b non-tracking) &&
  55        test_must_fail full_name non-tracking@{u}
  56'
  57
  58test_expect_success '<branch>@{u}@{1} resolves correctly' '
  59        test_commit 6 &&
  60        (cd clone && git fetch) &&
  61        test 5 = $(commit_subject my-side@{u}@{1})
  62'
  63
  64test_expect_success '@{u} without specifying branch fails on a detached HEAD' '
  65        git checkout HEAD^0 &&
  66        test_must_fail git rev-parse @{u}
  67'
  68
  69test_expect_success 'checkout -b new my-side@{u} forks from the same' '
  70(
  71        cd clone &&
  72        git checkout -b new my-side@{u} &&
  73        git rev-parse --symbolic-full-name my-side@{u} >expect &&
  74        git rev-parse --symbolic-full-name new@{u} >actual &&
  75        test_cmp expect actual
  76)
  77'
  78
  79test_expect_success 'merge my-side@{u} records the correct name' '
  80(
  81        sq="'\''" &&
  82        cd clone || exit
  83        git checkout master || exit
  84        git branch -D new ;# can fail but is ok
  85        git branch -t new my-side@{u} &&
  86        git merge -s ours new@{u} &&
  87        git show -s --pretty=format:%s >actual &&
  88        echo "Merge remote branch ${sq}origin/side${sq}" >expect &&
  89        test_cmp expect actual
  90)
  91'
  92
  93test_expect_success 'branch -d other@{u}' '
  94        git checkout -t -b other master &&
  95        git branch -d @{u} &&
  96        git for-each-ref refs/heads/master >actual &&
  97        >expect &&
  98        test_cmp expect actual
  99'
 100
 101test_expect_success 'checkout other@{u}' '
 102        git branch -f master HEAD &&
 103        git checkout -t -b another master &&
 104        git checkout @{u} &&
 105        git symbolic-ref HEAD >actual &&
 106        echo refs/heads/master >expect &&
 107        test_cmp expect actual
 108'
 109
 110cat >expect <<EOF
 111commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
 112Reflog: master@{0} (C O Mitter <committer@example.com>)
 113Reflog message: branch: Created from HEAD
 114Author: A U Thor <author@example.com>
 115Date:   Thu Apr 7 15:15:13 2005 -0700
 116
 117    3
 118EOF
 119test_expect_success 'log -g other@{u}' '
 120        git log -1 -g other@{u} >actual &&
 121        test_cmp expect actual
 122'
 123
 124cat >expect <<EOF
 125commit 8f489d01d0cc65c3b0f09504ec50b5ed02a70bd5
 126Reflog: master@{Thu Apr 7 15:17:13 2005 -0700} (C O Mitter <committer@example.com>)
 127Reflog message: branch: Created from HEAD
 128Author: A U Thor <author@example.com>
 129Date:   Thu Apr 7 15:15:13 2005 -0700
 130
 131    3
 132EOF
 133
 134test_expect_success 'log -g other@{u}@{now}' '
 135        git log -1 -g other@{u}@{now} >actual &&
 136        test_cmp expect actual
 137'
 138
 139test_done