Add support for creating detached heads
[jgit.git] / org.eclipse.jgit.test / tst / org / eclipse / jgit / lib / ValidRefNameTest.java
blob79e2eba701aae56e6a2bc6da19dd04562fff0e48
1 /*
2 * Copyright (C) 2009, Google Inc.
3 * and other copyright owners as documented in the project's IP log.
5 * This program and the accompanying materials are made available
6 * under the terms of the Eclipse Distribution License v1.0 which
7 * accompanies this distribution, is reproduced below, and is
8 * available at http://www.eclipse.org/org/documents/edl-v10.php
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
16 * - Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials provided
22 * with the distribution.
24 * - Neither the name of the Eclipse Foundation, Inc. nor the
25 * names of its contributors may be used to endorse or promote
26 * products derived from this software without specific prior
27 * written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 package org.eclipse.jgit.lib;
46 import junit.framework.TestCase;
48 public class ValidRefNameTest extends TestCase {
49 private static void assertValid(final boolean exp, final String name) {
50 assertEquals("\"" + name + "\"", exp, Repository.isValidRefName(name));
53 public void testEmptyString() {
54 assertValid(false, "");
55 assertValid(false, "/");
58 public void testMustHaveTwoComponents() {
59 assertValid(false, "master");
60 assertValid(true, "heads/master");
63 public void testValidHead() {
64 assertValid(true, "refs/heads/master");
65 assertValid(true, "refs/heads/pu");
66 assertValid(true, "refs/heads/z");
67 assertValid(true, "refs/heads/FoO");
70 public void testValidTag() {
71 assertValid(true, "refs/tags/v1.0");
74 public void testNoLockSuffix() {
75 assertValid(false, "refs/heads/master.lock");
78 public void testNoDirectorySuffix() {
79 assertValid(false, "refs/heads/master/");
82 public void testNoSpace() {
83 assertValid(false, "refs/heads/i haz space");
86 public void testNoAsciiControlCharacters() {
87 for (char c = '\0'; c < ' '; c++)
88 assertValid(false, "refs/heads/mast" + c + "er");
91 public void testNoBareDot() {
92 assertValid(false, "refs/heads/.");
93 assertValid(false, "refs/heads/..");
94 assertValid(false, "refs/heads/./master");
95 assertValid(false, "refs/heads/../master");
98 public void testNoLeadingOrTrailingDot() {
99 assertValid(false, ".");
100 assertValid(false, "refs/heads/.bar");
101 assertValid(false, "refs/heads/..bar");
102 assertValid(false, "refs/heads/bar.");
105 public void testContainsDot() {
106 assertValid(true, "refs/heads/m.a.s.t.e.r");
107 assertValid(false, "refs/heads/master..pu");
110 public void testNoMagicRefCharacters() {
111 assertValid(false, "refs/heads/master^");
112 assertValid(false, "refs/heads/^master");
113 assertValid(false, "^refs/heads/master");
115 assertValid(false, "refs/heads/master~");
116 assertValid(false, "refs/heads/~master");
117 assertValid(false, "~refs/heads/master");
119 assertValid(false, "refs/heads/master:");
120 assertValid(false, "refs/heads/:master");
121 assertValid(false, ":refs/heads/master");
124 public void testShellGlob() {
125 assertValid(false, "refs/heads/master?");
126 assertValid(false, "refs/heads/?master");
127 assertValid(false, "?refs/heads/master");
129 assertValid(false, "refs/heads/master[");
130 assertValid(false, "refs/heads/[master");
131 assertValid(false, "[refs/heads/master");
133 assertValid(false, "refs/heads/master*");
134 assertValid(false, "refs/heads/*master");
135 assertValid(false, "*refs/heads/master");
138 public void testValidSpecialCharacters() {
139 assertValid(true, "refs/heads/!");
140 assertValid(true, "refs/heads/\"");
141 assertValid(true, "refs/heads/#");
142 assertValid(true, "refs/heads/$");
143 assertValid(true, "refs/heads/%");
144 assertValid(true, "refs/heads/&");
145 assertValid(true, "refs/heads/'");
146 assertValid(true, "refs/heads/(");
147 assertValid(true, "refs/heads/)");
148 assertValid(true, "refs/heads/+");
149 assertValid(true, "refs/heads/,");
150 assertValid(true, "refs/heads/-");
151 assertValid(true, "refs/heads/;");
152 assertValid(true, "refs/heads/<");
153 assertValid(true, "refs/heads/=");
154 assertValid(true, "refs/heads/>");
155 assertValid(true, "refs/heads/@");
156 assertValid(true, "refs/heads/]");
157 assertValid(true, "refs/heads/_");
158 assertValid(true, "refs/heads/`");
159 assertValid(true, "refs/heads/{");
160 assertValid(true, "refs/heads/|");
161 assertValid(true, "refs/heads/}");
163 // This is valid on UNIX, but not on Windows
164 // hence we make in invalid due to non-portability
166 assertValid(false, "refs/heads/\\");
169 public void testUnicodeNames() {
170 assertValid(true, "refs/heads/\u00e5ngstr\u00f6m");
173 public void testRefLogQueryIsValidRef() {
174 assertValid(false, "refs/heads/master@{1}");
175 assertValid(false, "refs/heads/master@{1.hour.ago}");