git-svn: teach git-svn to populate svn:mergeinfo
[git.git] / t / t1402-check-ref-format.sh
blobed4275afe3100491ea57025632665182127f33cf
1 #!/bin/sh
3 test_description='Test git check-ref-format'
5 . ./test-lib.sh
7 valid_ref() {
8 test_expect_success "ref name '$1' is valid" \
9 "git check-ref-format '$1'"
11 invalid_ref() {
12 test_expect_success "ref name '$1' is not valid" \
13 "test_must_fail git check-ref-format '$1'"
16 valid_ref 'heads/foo'
17 invalid_ref 'foo'
18 valid_ref 'foo/bar/baz'
19 valid_ref 'refs///heads/foo'
20 invalid_ref 'heads/foo/'
21 valid_ref '/heads/foo'
22 valid_ref '///heads/foo'
23 invalid_ref '/foo'
24 invalid_ref './foo'
25 invalid_ref '.refs/foo'
26 invalid_ref 'heads/foo..bar'
27 invalid_ref 'heads/foo?bar'
28 valid_ref 'foo./bar'
29 invalid_ref 'heads/foo.lock'
30 valid_ref 'heads/foo@bar'
31 invalid_ref 'heads/v@{ation'
32 invalid_ref 'heads/foo\bar'
33 invalid_ref "$(printf 'heads/foo\t')"
34 invalid_ref "$(printf 'heads/foo\177')"
35 valid_ref "$(printf 'heads/fu\303\237')"
37 test_expect_success "check-ref-format --branch @{-1}" '
38 T=$(git write-tree) &&
39 sha1=$(echo A | git commit-tree $T) &&
40 git update-ref refs/heads/master $sha1 &&
41 git update-ref refs/remotes/origin/master $sha1 &&
42 git checkout master &&
43 git checkout origin/master &&
44 git checkout master &&
45 refname=$(git check-ref-format --branch @{-1}) &&
46 test "$refname" = "$sha1" &&
47 refname2=$(git check-ref-format --branch @{-2}) &&
48 test "$refname2" = master'
50 test_expect_success 'check-ref-format --branch from subdir' '
51 mkdir subdir &&
53 T=$(git write-tree) &&
54 sha1=$(echo A | git commit-tree $T) &&
55 git update-ref refs/heads/master $sha1 &&
56 git update-ref refs/remotes/origin/master $sha1 &&
57 git checkout master &&
58 git checkout origin/master &&
59 git checkout master &&
60 refname=$(
61 cd subdir &&
62 git check-ref-format --branch @{-1}
63 ) &&
64 test "$refname" = "$sha1"
67 valid_ref_normalized() {
68 test_expect_success "ref name '$1' simplifies to '$2'" "
69 refname=\$(git check-ref-format --print '$1') &&
70 test \"\$refname\" = '$2'"
72 invalid_ref_normalized() {
73 test_expect_success "check-ref-format --print rejects '$1'" "
74 test_must_fail git check-ref-format --print '$1'"
77 valid_ref_normalized 'heads/foo' 'heads/foo'
78 valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
79 valid_ref_normalized '/heads/foo' 'heads/foo'
80 valid_ref_normalized '///heads/foo' 'heads/foo'
81 invalid_ref_normalized 'foo'
82 invalid_ref_normalized '/foo'
83 invalid_ref_normalized 'heads/foo/../bar'
84 invalid_ref_normalized 'heads/./foo'
85 invalid_ref_normalized 'heads\foo'
87 test_done