git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob e527e0b0c9c29b0cc4d6bd5680867d283b532e7b 3791 bytes (raw)
name: t/t3204-branch-name-interpretation.sh 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
#!/bin/sh

test_description='interpreting exotic branch name arguments

Branch name arguments are usually names which are taken to be inside of
refs/heads/, but we interpret some magic syntax like @{-1}, @{upstream}, etc.
This script aims to check the behavior of those corner cases.
'
. ./test-lib.sh

expect_branch() {
	git log -1 --format=%s "$1" >actual &&
	echo "$2" >expect &&
	test_cmp expect actual
}

expect_deleted() {
	test_must_fail git rev-parse --verify "$1"
}

test_expect_success 'set up repo' '
	test_commit one &&
	test_commit two &&
	git remote add origin foo.git
'

test_expect_success 'update branch via @{-1}' '
	git branch previous one &&

	git checkout previous &&
	git checkout main &&

	git branch -f @{-1} two &&
	expect_branch previous two
'

test_expect_success 'update branch via local @{upstream}' '
	git branch local one &&
	git branch --set-upstream-to=local &&

	git branch -f @{upstream} two &&
	expect_branch local two
'

test_expect_success 'disallow updating branch via remote @{upstream}' '
	git update-ref refs/remotes/origin/remote one &&
	git branch --set-upstream-to=origin/remote &&

	test_must_fail git branch -f @{upstream} two
'

test_expect_success 'create branch with pseudo-qualified name' '
	git branch refs/heads/qualified two &&
	expect_branch refs/heads/refs/heads/qualified two
'

test_expect_success 'delete branch via @{-1}' '
	git branch previous-del &&

	git checkout previous-del &&
	git checkout main &&

	git branch -D @{-1} &&
	expect_deleted previous-del
'

test_expect_success 'delete branch via local @{upstream}' '
	git branch local-del &&
	git branch --set-upstream-to=local-del &&

	git branch -D @{upstream} &&
	expect_deleted local-del
'

test_expect_success 'delete branch via remote @{upstream}' '
	git update-ref refs/remotes/origin/remote-del two &&
	git branch --set-upstream-to=origin/remote-del &&

	git branch -r -D @{upstream} &&
	expect_deleted origin/remote-del
'

# Note that we create two oddly named local branches here. We want to make
# sure that we do not accidentally delete either of them, even if
# shorten_unambiguous_ref() tweaks the name to avoid ambiguity.
test_expect_success 'delete @{upstream} expansion matches -r option' '
	git update-ref refs/remotes/origin/remote-del two &&
	git branch --set-upstream-to=origin/remote-del &&
	git update-ref refs/heads/origin/remote-del two &&
	git update-ref refs/heads/remotes/origin/remote-del two &&

	test_must_fail git branch -D @{upstream} &&
	expect_branch refs/heads/origin/remote-del two &&
	expect_branch refs/heads/remotes/origin/remote-del two
'

test_expect_success 'disallow deleting remote branch via @{-1}' '
	git update-ref refs/remotes/origin/previous one &&

	git checkout -b origin/previous two &&
	git checkout main &&

	test_must_fail git branch -r -D @{-1} &&
	expect_branch refs/remotes/origin/previous one &&
	expect_branch refs/heads/origin/previous two
'

# The thing we are testing here is that "@" is the real branch refs/heads/@,
# and not refs/heads/HEAD. These tests should not imply that refs/heads/@ is a
# sane thing, but it _is_ technically allowed for now. If we disallow it, these
# can be switched to test_must_fail.
test_expect_success 'create branch named "@"' '
	git branch -f @ one &&
	expect_branch refs/heads/@ one
'

test_expect_success 'delete branch named "@"' '
	git update-ref refs/heads/@ two &&
	git branch -D @ &&
	expect_deleted refs/heads/@
'

test_expect_success 'checkout does not treat remote @{upstream} as a branch' '
	git update-ref refs/remotes/origin/checkout one &&
	git branch --set-upstream-to=origin/checkout &&
	git update-ref refs/heads/origin/checkout two &&
	git update-ref refs/heads/remotes/origin/checkout two &&

	git checkout @{upstream} &&
	expect_branch HEAD one
'

test_done

debug log:

solving e527e0b0c9 ...
found e527e0b0c9 in https://public-inbox.org/git/0697ef9742af1ab15bd886990bbc0080bad6f41c.1605221039.git.gitgitgadget@gmail.com/ ||
	https://public-inbox.org/git/aee29a0528462137af6811d22da50dfcad585b84.1605629548.git.gitgitgadget@gmail.com/
found 698d9cc4f3 in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100755 698d9cc4f3d65754552b8ccdd46b0cb64aea09c5	t/t3204-branch-name-interpretation.sh

applying [1/1] https://public-inbox.org/git/0697ef9742af1ab15bd886990bbc0080bad6f41c.1605221039.git.gitgitgadget@gmail.com/
diff --git a/t/t3204-branch-name-interpretation.sh b/t/t3204-branch-name-interpretation.sh
index 698d9cc4f3..e527e0b0c9 100755

Checking patch t/t3204-branch-name-interpretation.sh...
Applied patch t/t3204-branch-name-interpretation.sh cleanly.

skipping https://public-inbox.org/git/aee29a0528462137af6811d22da50dfcad585b84.1605629548.git.gitgitgadget@gmail.com/ for e527e0b0c9
index at:
100755 e527e0b0c9c29b0cc4d6bd5680867d283b532e7b	t/t3204-branch-name-interpretation.sh

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).