disallow branch names that start with a hyphen
[git/dkf.git] / t / t1503-rev-parse-verify.sh
blob100f857b168b1d8b88ea1a1e7e31ba42a2beee6c
1 #!/bin/sh
3 # Copyright (c) 2008 Christian Couder
5 test_description='test git rev-parse --verify'
7 exec </dev/null
9 . ./test-lib.sh
11 add_line_into_file()
13 _line=$1
14 _file=$2
16 if [ -f "$_file" ]; then
17 echo "$_line" >> $_file || return $?
18 MSG="Add <$_line> into <$_file>."
19 else
20 echo "$_line" > $_file || return $?
21 git add $_file || return $?
22 MSG="Create file <$_file> with <$_line> inside."
25 test_tick
26 git commit --quiet -m "$MSG" $_file
29 HASH1=
30 HASH2=
31 HASH3=
32 HASH4=
34 test_expect_success 'set up basic repo with 1 file (hello) and 4 commits' '
35 add_line_into_file "1: Hello World" hello &&
36 HASH1=$(git rev-parse --verify HEAD) &&
37 add_line_into_file "2: A new day for git" hello &&
38 HASH2=$(git rev-parse --verify HEAD) &&
39 add_line_into_file "3: Another new day for git" hello &&
40 HASH3=$(git rev-parse --verify HEAD) &&
41 add_line_into_file "4: Ciao for now" hello &&
42 HASH4=$(git rev-parse --verify HEAD)
45 test_expect_success 'works with one good rev' '
46 rev_hash1=$(git rev-parse --verify $HASH1) &&
47 test "$rev_hash1" = "$HASH1" &&
48 rev_hash2=$(git rev-parse --verify $HASH2) &&
49 test "$rev_hash2" = "$HASH2" &&
50 rev_hash3=$(git rev-parse --verify $HASH3) &&
51 test "$rev_hash3" = "$HASH3" &&
52 rev_hash4=$(git rev-parse --verify $HASH4) &&
53 test "$rev_hash4" = "$HASH4" &&
54 rev_master=$(git rev-parse --verify master) &&
55 test "$rev_master" = "$HASH4" &&
56 rev_head=$(git rev-parse --verify HEAD) &&
57 test "$rev_head" = "$HASH4"
60 test_expect_success 'fails with any bad rev or many good revs' '
61 test_must_fail git rev-parse --verify 2>error &&
62 grep "single revision" error &&
63 test_must_fail git rev-parse --verify foo 2>error &&
64 grep "single revision" error &&
65 test_must_fail git rev-parse --verify HEAD bar 2>error &&
66 grep "single revision" error &&
67 test_must_fail git rev-parse --verify baz HEAD 2>error &&
68 grep "single revision" error &&
69 test_must_fail git rev-parse --verify $HASH2 HEAD 2>error &&
70 grep "single revision" error
73 test_expect_success 'fails silently when using -q' '
74 test_must_fail git rev-parse --verify --quiet 2>error &&
75 test -z "$(cat error)" &&
76 test_must_fail git rev-parse -q --verify foo 2>error &&
77 test -z "$(cat error)" &&
78 test_must_fail git rev-parse --verify -q HEAD bar 2>error &&
79 test -z "$(cat error)" &&
80 test_must_fail git rev-parse --quiet --verify baz HEAD 2>error &&
81 test -z "$(cat error)" &&
82 test_must_fail git rev-parse -q --verify $HASH2 HEAD 2>error &&
83 test -z "$(cat error)"
86 test_expect_success 'no stdout output on error' '
87 test -z "$(git rev-parse --verify)" &&
88 test -z "$(git rev-parse --verify foo)" &&
89 test -z "$(git rev-parse --verify baz HEAD)" &&
90 test -z "$(git rev-parse --verify HEAD bar)" &&
91 test -z "$(git rev-parse --verify $HASH2 HEAD)"
94 test_expect_success 'use --default' '
95 git rev-parse --verify --default master &&
96 git rev-parse --verify --default master HEAD &&
97 git rev-parse --default master --verify &&
98 git rev-parse --default master --verify HEAD &&
99 git rev-parse --verify HEAD --default master &&
100 test_must_fail git rev-parse --verify foo --default master &&
101 test_must_fail git rev-parse --default HEAD --verify bar &&
102 test_must_fail git rev-parse --verify --default HEAD baz &&
103 test_must_fail git rev-parse --default foo --verify &&
104 test_must_fail git rev-parse --verify --default bar
107 test_expect_success 'master@{n} for various n' '
108 N=$(git reflog | wc -l) &&
109 Nm1=$((N-1)) &&
110 Np1=$((N+1)) &&
111 git rev-parse --verify master@{0} &&
112 git rev-parse --verify master@{1} &&
113 git rev-parse --verify master@{$Nm1} &&
114 test_must_fail git rev-parse --verify master@{$N} &&
115 test_must_fail git rev-parse --verify master@{$Np1}
118 test_done