t / t3204-branch-name-interpretation.shon commit Merge branch 'dk/send-email-avoid-net-smtp-ssl-when-able' into maint (f381e42)
   1#!/bin/sh
   2
   3test_description='interpreting exotic branch name arguments
   4
   5Branch name arguments are usually names which are taken to be inside of
   6refs/heads/, but we interpret some magic syntax like @{-1}, @{upstream}, etc.
   7This script aims to check the behavior of those corner cases.
   8'
   9. ./test-lib.sh
  10
  11expect_branch() {
  12        git log -1 --format=%s "$1" >actual &&
  13        echo "$2" >expect &&
  14        test_cmp expect actual
  15}
  16
  17expect_deleted() {
  18        test_must_fail git rev-parse --verify "$1"
  19}
  20
  21test_expect_success 'set up repo' '
  22        test_commit one &&
  23        test_commit two &&
  24        git remote add origin foo.git
  25'
  26
  27test_expect_success 'update branch via @{-1}' '
  28        git branch previous one &&
  29
  30        git checkout previous &&
  31        git checkout master &&
  32
  33        git branch -f @{-1} two &&
  34        expect_branch previous two
  35'
  36
  37test_expect_success 'update branch via local @{upstream}' '
  38        git branch local one &&
  39        git branch --set-upstream-to=local &&
  40
  41        git branch -f @{upstream} two &&
  42        expect_branch local two
  43'
  44
  45test_expect_success 'disallow updating branch via remote @{upstream}' '
  46        git update-ref refs/remotes/origin/remote one &&
  47        git branch --set-upstream-to=origin/remote &&
  48
  49        test_must_fail git branch -f @{upstream} two
  50'
  51
  52test_expect_success 'create branch with pseudo-qualified name' '
  53        git branch refs/heads/qualified two &&
  54        expect_branch refs/heads/refs/heads/qualified two
  55'
  56
  57test_expect_success 'delete branch via @{-1}' '
  58        git branch previous-del &&
  59
  60        git checkout previous-del &&
  61        git checkout master &&
  62
  63        git branch -D @{-1} &&
  64        expect_deleted previous-del
  65'
  66
  67test_expect_success 'delete branch via local @{upstream}' '
  68        git branch local-del &&
  69        git branch --set-upstream-to=local-del &&
  70
  71        git branch -D @{upstream} &&
  72        expect_deleted local-del
  73'
  74
  75test_expect_success 'delete branch via remote @{upstream}' '
  76        git update-ref refs/remotes/origin/remote-del two &&
  77        git branch --set-upstream-to=origin/remote-del &&
  78
  79        git branch -r -D @{upstream} &&
  80        expect_deleted origin/remote-del
  81'
  82
  83# Note that we create two oddly named local branches here. We want to make
  84# sure that we do not accidentally delete either of them, even if
  85# shorten_unambiguous_ref() tweaks the name to avoid ambiguity.
  86test_expect_success 'delete @{upstream} expansion matches -r option' '
  87        git update-ref refs/remotes/origin/remote-del two &&
  88        git branch --set-upstream-to=origin/remote-del &&
  89        git update-ref refs/heads/origin/remote-del two &&
  90        git update-ref refs/heads/remotes/origin/remote-del two &&
  91
  92        test_must_fail git branch -D @{upstream} &&
  93        expect_branch refs/heads/origin/remote-del two &&
  94        expect_branch refs/heads/remotes/origin/remote-del two
  95'
  96
  97test_expect_success 'disallow deleting remote branch via @{-1}' '
  98        git update-ref refs/remotes/origin/previous one &&
  99
 100        git checkout -b origin/previous two &&
 101        git checkout master &&
 102
 103        test_must_fail git branch -r -D @{-1} &&
 104        expect_branch refs/remotes/origin/previous one &&
 105        expect_branch refs/heads/origin/previous two
 106'
 107
 108# The thing we are testing here is that "@" is the real branch refs/heads/@,
 109# and not refs/heads/HEAD. These tests should not imply that refs/heads/@ is a
 110# sane thing, but it _is_ technically allowed for now. If we disallow it, these
 111# can be switched to test_must_fail.
 112test_expect_success 'create branch named "@"' '
 113        git branch -f @ one &&
 114        expect_branch refs/heads/@ one
 115'
 116
 117test_expect_success 'delete branch named "@"' '
 118        git update-ref refs/heads/@ two &&
 119        git branch -D @ &&
 120        expect_deleted refs/heads/@
 121'
 122
 123test_expect_success 'checkout does not treat remote @{upstream} as a branch' '
 124        git update-ref refs/remotes/origin/checkout one &&
 125        git branch --set-upstream-to=origin/checkout &&
 126        git update-ref refs/heads/origin/checkout two &&
 127        git update-ref refs/heads/remotes/origin/checkout two &&
 128
 129        git checkout @{upstream} &&
 130        expect_branch HEAD one
 131'
 132
 133test_done