1#!/bin/sh
23
test_description='Test git check-ref-format'
45
. ./test-lib.sh
67
valid_ref() {
8test_expect_success "ref name '$1' is valid" \
9"git check-ref-format '$1'"
10}
11invalid_ref() {
12test_expect_success "ref name '$1' is not valid" \
13"test_must_fail git check-ref-format '$1'"
14}
1516
valid_ref 'heads/foo'
17invalid_ref 'foo'
18valid_ref 'foo/bar/baz'
19valid_ref 'refs///heads/foo'
20invalid_ref 'heads/foo/'
21valid_ref '/heads/foo'
22valid_ref '///heads/foo'
23invalid_ref '/foo'
24invalid_ref './foo'
25invalid_ref '.refs/foo'
26invalid_ref 'heads/foo..bar'
27invalid_ref 'heads/foo?bar'
28valid_ref 'foo./bar'
29invalid_ref 'heads/foo.lock'
30valid_ref 'heads/foo@bar'
31invalid_ref 'heads/v@{ation'
32invalid_ref 'heads/foo\bar'
3334
test_expect_success "check-ref-format --branch @{-1}" '
35T=$(git write-tree) &&
36sha1=$(echo A | git commit-tree $T) &&
37git update-ref refs/heads/master $sha1 &&
38git update-ref refs/remotes/origin/master $sha1 &&
39git checkout master &&
40git checkout origin/master &&
41git checkout master &&
42refname=$(git check-ref-format --branch @{-1}) &&
43test "$refname" = "$sha1" &&
44refname2=$(git check-ref-format --branch @{-2}) &&
45test "$refname2" = master'
4647
test_expect_success 'check-ref-format --branch from subdir' '
48mkdir subdir &&
4950
T=$(git write-tree) &&
51sha1=$(echo A | git commit-tree $T) &&
52git update-ref refs/heads/master $sha1 &&
53git update-ref refs/remotes/origin/master $sha1 &&
54git checkout master &&
55git checkout origin/master &&
56git checkout master &&
57refname=$(
58cd subdir &&
59git check-ref-format --branch @{-1}
60) &&
61test "$refname" = "$sha1"
62'
6364
valid_ref_normalized() {
65test_expect_success "ref name '$1' simplifies to '$2'" "
66refname=\$(git check-ref-format --print '$1') &&
67test \"\$refname\" = '$2'"
68}
69invalid_ref_normalized() {
70test_expect_success "check-ref-format --print rejects '$1'" "
71test_must_fail git check-ref-format --print '$1'"
72}
7374
valid_ref_normalized 'heads/foo' 'heads/foo'
75valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
76valid_ref_normalized '/heads/foo' 'heads/foo'
77valid_ref_normalized '///heads/foo' 'heads/foo'
78invalid_ref_normalized 'foo'
79invalid_ref_normalized '/foo'
80invalid_ref_normalized 'heads/foo/../bar'
81invalid_ref_normalized 'heads/./foo'
82invalid_ref_normalized 'heads\foo'
8384
test_done