diff options
author | florian.signoret <florian.signoret@ibm.com> | 2023-10-16 16:08:14 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2023-11-18 00:05:35 +0100 |
commit | e4a341db43d5d8a1e6e9c828e3b3e5ddd52b9186 (patch) | |
tree | 0d1dc9118c9e165222cea4cda8cfd122c82cbc87 /org.eclipse.jgit.test/tst/org/eclipse | |
parent | 52af8dbaff46191203b033f05a9fbc1ff0a46886 (diff) | |
download | jgit-e4a341db43d5d8a1e6e9c828e3b3e5ddd52b9186.tar.gz jgit-e4a341db43d5d8a1e6e9c828e3b3e5ddd52b9186.zip |
Fix branch ref exist check
When a tag with the same name as the branch exists, the branch creation
process should work too. We should detect that the branch already
exists, and allow to force create it when the force option is used.
Bug: 582538
Change-Id: I3b350d03be8edcde10e97b2318343240ca896cb0
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index 87be813c85..7c1cbc37d6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java @@ -12,6 +12,7 @@ package org.eclipse.jgit.api; 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; @@ -160,6 +161,20 @@ public class BranchCommandTest extends RepositoryTestCase { - 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(); |