import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
import java.util.List;
- allBefore);
}
+ @Test
+ public void testExistingNameInBothBranchesAndTags() throws Exception {
+ git.branchCreate().setName("test").call();
+ git.tag().setName("test").call();
+
+ // existing name not allowed w/o force
+ assertThrows("Create branch with existing ref name should fail",
+ RefAlreadyExistsException.class,
+ () -> git.branchCreate().setName("test").call());
+
+ // existing name allowed with force option
+ git.branchCreate().setName("test").setForce(true).call();
+ }
+
@Test(expected = InvalidRefNameException.class)
public void testInvalidBranchHEAD() throws Exception {
git.branchCreate().setName("HEAD").call();
checkCallable();
processOptions();
try (RevWalk revWalk = new RevWalk(repo)) {
- Ref refToCheck = repo.findRef(name);
- boolean exists = refToCheck != null
- && refToCheck.getName().startsWith(R_HEADS);
+ boolean exists = repo.findRef(R_HEADS + name) != null;
if (!force && exists)
throw new RefAlreadyExistsException(MessageFormat.format(
JGitText.get().refAlreadyExists1, name));