summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2012-08-21 17:34:45 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2012-08-21 17:34:45 -0400
commit5e21a8916cd823979613c0b3e49b4b3d0995c0e3 (patch)
tree81879d4379d46f336fc5972d8038d606d3687134 /org.eclipse.jgit.test
parent1c1fc6814c44ec0af43b1788451339462821088d (diff)
parentc010c93694eb76e90f60de01b5a6b946c2472e9d (diff)
downloadjgit-5e21a8916cd823979613c0b3e49b4b3d0995c0e3.tar.gz
jgit-5e21a8916cd823979613c0b3e49b4b3d0995c0e3.zip
Merge changes I98df46ce,Ifb815a12,I051a1724
* changes: Support [<ref>]@{upstream} revision syntax Support parsing previous checkout as a revision expresion. Allow a @ without branch in revision syntax
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogResolveTest.java61
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java35
2 files changed, 91 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogResolveTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogResolveTest.java
index c3de79b6c4..fe28b47bba 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogResolveTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogResolveTest.java
@@ -72,6 +72,38 @@ public class ReflogResolveTest extends RepositoryTestCase {
}
@Test
+ public void resolveUnnamedCurrentBranchCommits() throws Exception {
+ Git git = new Git(db);
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit c1 = git.commit().setMessage("create file").call();
+ writeTrashFile("file.txt", "content2");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit c2 = git.commit().setMessage("edit file").call();
+
+ assertEquals(c2, db.resolve("master@{0}"));
+ assertEquals(c1, db.resolve("master@{1}"));
+
+ git.checkout().setCreateBranch(true).setName("newbranch")
+ .setStartPoint(c1).call();
+
+ // same as current branch, e.g. master
+ assertEquals(c1, db.resolve("@{0}"));
+ try {
+ assertEquals(c1, db.resolve("@{1}"));
+ fail(); // Looking at wrong ref, e.g HEAD
+ } catch (RevisionSyntaxException e) {
+ assertNotNull(e);
+ }
+
+ // detached head, read HEAD reflog
+ git.checkout().setName(c2.getName()).call();
+ assertEquals(c2, db.resolve("@{0}"));
+ assertEquals(c1, db.resolve("@{1}"));
+ assertEquals(c2, db.resolve("@{2}"));
+ }
+
+ @Test
public void resolveReflogParent() throws Exception {
Git git = new Git(db);
writeTrashFile("file.txt", "content");
@@ -94,17 +126,36 @@ public class ReflogResolveTest extends RepositoryTestCase {
}
@Test
- public void resolveNegativeEntryNumber() throws Exception {
+ public void resolvePreviousBranch() throws Exception {
Git git = new Git(db);
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
- git.commit().setMessage("create file").call();
+ RevCommit c1 = git.commit().setMessage("create file").call();
+ writeTrashFile("file.txt", "content2");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit c2 = git.commit().setMessage("edit file").call();
+
+ git.checkout().setCreateBranch(true).setName("newbranch")
+ .setStartPoint(c1).call();
+
+ git.checkout().setName(c1.getName()).call();
+
+ git.checkout().setName("master").call();
+
+ assertEquals(c1.getName(), db.simplify("@{-1}"));
+ assertEquals("newbranch", db.simplify("@{-2}"));
+ assertEquals("master", db.simplify("@{-3}"));
+
+ // chained expression
try {
- db.resolve("master@{-12}");
- fail("Exception not thrown");
+ // Cannot refer to reflog of detached head
+ db.resolve("@{-1}@{0}");
+ fail();
} catch (RevisionSyntaxException e) {
- assertNotNull(e);
}
+ assertEquals(c1.getName(), db.resolve("@{-2}@{0}").getName());
+
+ assertEquals(c2.getName(), db.resolve("@{-3}@{0}").getName());
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
index f975a87736..deb830ff5b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
@@ -53,7 +53,9 @@ import static org.junit.Assert.fail;
import java.io.IOException;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
@@ -231,6 +233,39 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertNull("no not-a-branch:", db.resolve("not-a-branch:"));
}
+ @Test
+ public void resolveExprSimple() throws Exception {
+ Git git = new Git(db);
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ git.commit().setMessage("create file").call();
+ assertEquals("master", db.simplify("master"));
+ assertEquals("refs/heads/master", db.simplify("refs/heads/master"));
+ assertEquals("HEAD", db.simplify("HEAD"));
+ }
+
+ @Test
+ public void resolveUpstream() throws Exception {
+ Git git = new Git(db);
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit c1 = git.commit().setMessage("create file").call();
+ writeTrashFile("file2.txt", "content");
+ RefUpdate updateRemoteRef = db.updateRef("refs/remotes/origin/main");
+ updateRemoteRef.setNewObjectId(c1);
+ updateRemoteRef.update();
+ db.getConfig().setString("branch", "master", "remote", "origin");
+ db.getConfig()
+ .setString("branch", "master", "merge", "refs/heads/main");
+ db.getConfig().setString("remote", "origin", "url",
+ "git://example.com/here");
+ db.getConfig().setString("remote", "origin", "fetch",
+ "+refs/heads/*:refs/remotes/origin/*");
+ git.add().addFilepattern("file2.txt").call();
+ git.commit().setMessage("create file").call();
+ assertEquals("refs/remotes/origin/main", db.simplify("@{upstream}"));
+ }
+
private static ObjectId id(String name) {
return ObjectId.fromString(name);
}