@matheusbsbs / matheus-bagliano / commits / 58a05c74e7
Fork 0

Add tests for git check-ref-format

The "git check-ref-format" command is a basic command various porcelains rely on. Test its functionality to make sure it does not unintentionally change. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Oct 12, 2009 at 00:27 UTC 58a05c74e7a9341af80eb98731d6b0dafe1b5c29
1 file changed +44
t/t1402-check-ref-format.sh new
+44
@@ -0,0 +1,44 @@
1 +#!/bin/sh
2 +
3 +test_description='Test git check-ref-format'
4 +
5 +. ./test-lib.sh
6 +
7 +valid_ref() {
8 + test_expect_success "ref name '$1' is valid" \
9 + "git check-ref-format '$1'"
10 +}
11 +invalid_ref() {
12 + test_expect_success "ref name '$1' is not valid" \
13 + "test_must_fail git check-ref-format '$1'"
14 +}
15 +
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 +invalid_ref './foo'
22 +invalid_ref '.refs/foo'
23 +invalid_ref 'heads/foo..bar'
24 +invalid_ref 'heads/foo?bar'
25 +valid_ref 'foo./bar'
26 +invalid_ref 'heads/foo.lock'
27 +valid_ref 'heads/foo@bar'
28 +invalid_ref 'heads/v@{ation'
29 +invalid_ref 'heads/foo\bar'
30 +
31 +test_expect_success "check-ref-format --branch @{-1}" '
32 + T=$(git write-tree) &&
33 + sha1=$(echo A | git commit-tree $T) &&
34 + git update-ref refs/heads/master $sha1 &&
35 + git update-ref refs/remotes/origin/master $sha1
36 + git checkout master &&
37 + git checkout origin/master &&
38 + git checkout master &&
39 + refname=$(git check-ref-format --branch @{-1}) &&
40 + test "$refname" = "$sha1" &&
41 + refname2=$(git check-ref-format --branch @{-2}) &&
42 + test "$refname2" = master'
43 +
44 +test_done