summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorRobin Stocker <robin@nibor.org>2013-04-27 16:46:29 +0200
committerRobin Stocker <robin@nibor.org>2013-05-01 16:02:01 +0200
commitf448d62d29acc996a97ffbbdec955d14fde5c254 (patch)
treeea158d4a6aa7f6c4ae8ffda1344f4e7f0ae69bb8 /org.eclipse.jgit.test/tst
parent68b378a4b5e08b80c35e6ad91df25b1034c379a3 (diff)
downloadjgit-f448d62d29acc996a97ffbbdec955d14fde5c254.tar.gz
jgit-f448d62d29acc996a97ffbbdec955d14fde5c254.zip
Update tags on fetch if --tags or tag refspec specified
When either --tags or a tag ref is explicitly specified on fetch, C Git updates existing local tags if they are different. Before this change, JGit returned REJECTED in such a case. Now it updates it and returns FORCED. Example: % mkdir a % cd a % git init -q % touch test.txt % git add test.txt % git commit -q -m 'Initial' % git tag v1 % cd .. % git clone -q a b % cd a % echo Test > test.txt % git commit -q -a -m 'Second' % git tag -f v1 Updated tag 'v1' (was bc85c08) % cd ../b % git fetch --tags - [tag update] v1 -> v1 Bug: 388095 Change-Id: I5d5494c2ad1a2cdb8e9e614d3de445289734edfe
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
index c30f9a2460..56a1f38013 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
@@ -52,8 +52,10 @@ import java.util.Collection;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -168,4 +170,27 @@ public class FetchCommandTest extends RepositoryTestCase {
assertEquals(originalId, db.resolve(tagName));
}
+
+ @Test
+ public void fetchWithExplicitTagsShouldUpdateLocal() throws Exception {
+ final String tagName = "foo";
+ remoteGit.commit().setMessage("commit").call();
+ Ref tagRef1 = remoteGit.tag().setName(tagName).call();
+
+ RefSpec spec = new RefSpec("refs/heads/*:refs/remotes/origin/*");
+ git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.AUTO_FOLLOW).call();
+ assertEquals(tagRef1.getObjectId(), db.resolve(tagName));
+
+ remoteGit.commit().setMessage("commit 2").call();
+ Ref tagRef2 = remoteGit.tag().setName(tagName).setForceUpdate(true)
+ .call();
+
+ FetchResult result = git.fetch().setRemote("test").setRefSpecs(spec)
+ .setTagOpt(TagOpt.FETCH_TAGS).call();
+ TrackingRefUpdate update = result.getTrackingRefUpdate(Constants.R_TAGS
+ + tagName);
+ assertEquals(RefUpdate.Result.FORCED, update.getResult());
+ assertEquals(tagRef2.getObjectId(), db.resolve(tagName));
+ }
}