summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-12-08 14:52:00 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2020-12-08 22:20:45 +0100
commit29e1270768f217f7c8471d771d90ff43135d7c26 (patch)
tree35ab0c407f764de747b6f522d975f0659fc8802d /org.eclipse.jgit.test
parentdc8a927ce40c801a0c777cfb477cfad4aab5c1c3 (diff)
downloadjgit-29e1270768f217f7c8471d771d90ff43135d7c26.tar.gz
jgit-29e1270768f217f7c8471d771d90ff43135d7c26.zip
TagCommand: make -f work with lightweight tags for NO_CHANGE
JGit treated a NO_CHANGE RefUpdate as an error in all cases. But when updating a lightweight tag, this is a successful result if -f was specified. Change-Id: Iddfa6d6a6dc8bf8fed81138a008ebc32d5f960bd Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
index 9630474b87..21de1d4517 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
@@ -12,6 +12,7 @@ package org.eclipse.jgit.api;
import static org.eclipse.jgit.lib.Constants.R_TAGS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -21,6 +22,7 @@ import java.util.List;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidTagNameException;
import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -122,6 +124,27 @@ public class TagCommandTest extends RepositoryTestCase {
}
@Test
+ public void testForceNoChangeLightweight() throws GitAPIException {
+ try (Git git = new Git(db)) {
+ git.commit().setMessage("initial commit").call();
+ RevCommit commit = git.commit().setMessage("second commit").call();
+ git.commit().setMessage("third commit").call();
+ Ref tagRef = git.tag().setObjectId(commit).setName("tag")
+ .setAnnotated(false).call();
+ assertEquals(commit.getId(), tagRef.getObjectId());
+ // Without force, we want to get a RefAlreadyExistsException
+ assertThrows(RefAlreadyExistsException.class,
+ () -> git.tag().setObjectId(commit).setName("tag")
+ .setAnnotated(false).call());
+ // With force the call should work
+ assertEquals(commit.getId(),
+ git.tag().setObjectId(commit).setName("tag")
+ .setAnnotated(false).setForceUpdate(true).call()
+ .getObjectId());
+ }
+ }
+
+ @Test
public void testEmptyTagName() throws GitAPIException {
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();