diff options
author | Jonathan Nieder <jrn@google.com> | 2015-06-05 15:20:24 -0700 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2015-11-25 14:05:20 -0800 |
commit | 5be4814e38f2c3983dc27ac6d74f95f2d73ed400 (patch) | |
tree | 33847b9f7f772f397a7855000c972db652c9c699 | |
parent | 830117e761bddc182e4dc57150ca661976868203 (diff) | |
download | jgit-5be4814e38f2c3983dc27ac6d74f95f2d73ed400.tar.gz jgit-5be4814e38f2c3983dc27ac6d74f95f2d73ed400.zip |
Repository: Introduce exactRef and findRef, deprecate getRef
The Repository class provides only one method to look up a ref by
name, getRef. If I request refs/heads/master and that ref does not
exist, getRef will look further in the search path:
ref/refs/heads/master
refs/heads/refs/heads/master
refs/remotes/refs/heads/master
This behavior is counterintuitive, needlessly inexpensive, and usually
not what the caller expects.
Allow callers to specify whether to use the search path by providing
two separate methods:
- exactRef, which looks up a ref when its exact name is known
- findRef, which looks for a ref along the search path
For backward compatibility, keep getRef as a deprecated synonym for
findRef.
This change introduces findRef and exactRef but does not update
callers outside tests to use them yet.
Change-Id: I35375d942baeb3ded15520388f8ebb9c0cc86f8c
Signed-off-by: Jonathan Nieder <jrn@google.com>
23 files changed, 246 insertions, 195 deletions
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java index dec9b59f2d..362a09d64f 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java @@ -209,7 +209,7 @@ public class DumbClientDumbServerTest extends HttpTestCase { } assertTrue(dst.hasObject(A_txt)); - assertEquals(B, dst.getRef(master).getObjectId()); + assertEquals(B, dst.exactRef(master).getObjectId()); fsck(dst, B); List<AccessEvent> loose = getRequests(loose(remoteURI, A_txt)); @@ -234,7 +234,7 @@ public class DumbClientDumbServerTest extends HttpTestCase { } assertTrue(dst.hasObject(A_txt)); - assertEquals(B, dst.getRef(master).getObjectId()); + assertEquals(B, dst.exactRef(master).getObjectId()); fsck(dst, B); List<AccessEvent> req; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java index e385b9538d..da3a09809b 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java @@ -225,7 +225,7 @@ public class DumbClientSmartServerTest extends HttpTestCase { } assertTrue(dst.hasObject(A_txt)); - assertEquals(B, dst.getRef(master).getObjectId()); + assertEquals(B, dst.exactRef(master).getObjectId()); fsck(dst, B); List<AccessEvent> loose = getRequests(loose(remoteURI, A_txt)); @@ -253,7 +253,7 @@ public class DumbClientSmartServerTest extends HttpTestCase { } assertTrue(dst.hasObject(A_txt)); - assertEquals(B, dst.getRef(master).getObjectId()); + assertEquals(B, dst.exactRef(master).getObjectId()); fsck(dst, B); List<AccessEvent> req; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java index f1056f2d6a..d67c8173cb 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java @@ -164,8 +164,8 @@ public class HookMessageTest extends HttpTestCase { } assertTrue(remoteRepository.hasObject(Q_txt)); - assertNotNull("has " + dstName, remoteRepository.getRef(dstName)); - assertEquals(Q, remoteRepository.getRef(dstName).getObjectId()); + assertNotNull("has " + dstName, remoteRepository.exactRef(dstName)); + assertEquals(Q, remoteRepository.exactRef(dstName).getObjectId()); fsck(remoteRepository, Q); List<AccessEvent> requests = getRequests(); diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java index 1b6c552cef..9ca0789e29 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java @@ -296,7 +296,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { } assertTrue(dst.hasObject(A_txt)); - assertEquals(B, dst.getRef(master).getObjectId()); + assertEquals(B, dst.exactRef(master).getObjectId()); fsck(dst, B); List<AccessEvent> requests = getRequests(); @@ -337,7 +337,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { } finally { t.close(); } - assertEquals(B, dst.getRepository().getRef(master).getObjectId()); + assertEquals(B, dst.getRepository().exactRef(master).getObjectId()); List<AccessEvent> cloneRequests = getRequests(); // Only create a few new commits. @@ -358,7 +358,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { } finally { t.close(); } - assertEquals(Z, dst.getRepository().getRef(master).getObjectId()); + assertEquals(Z, dst.getRepository().exactRef(master).getObjectId()); List<AccessEvent> requests = getRequests(); requests.removeAll(cloneRequests); @@ -400,7 +400,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { } finally { t.close(); } - assertEquals(B, dst.getRepository().getRef(master).getObjectId()); + assertEquals(B, dst.getRepository().exactRef(master).getObjectId()); List<AccessEvent> cloneRequests = getRequests(); // Force enough into the local client that enumeration will @@ -424,7 +424,7 @@ public class SmartClientSmartServerTest extends HttpTestCase { } finally { t.close(); } - assertEquals(Z, dst.getRepository().getRef(master).getObjectId()); + assertEquals(Z, dst.getRepository().exactRef(master).getObjectId()); List<AccessEvent> requests = getRequests(); requests.removeAll(cloneRequests); @@ -579,8 +579,8 @@ public class SmartClientSmartServerTest extends HttpTestCase { } assertTrue(remoteRepository.hasObject(Q_txt)); - assertNotNull("has " + dstName, remoteRepository.getRef(dstName)); - assertEquals(Q, remoteRepository.getRef(dstName).getObjectId()); + assertNotNull("has " + dstName, remoteRepository.exactRef(dstName)); + assertEquals(Q, remoteRepository.exactRef(dstName).getObjectId()); fsck(remoteRepository, Q); final ReflogReader log = remoteRepository.getReflogReader(dstName); @@ -657,8 +657,8 @@ public class SmartClientSmartServerTest extends HttpTestCase { } assertTrue(remoteRepository.hasObject(Q_bin)); - assertNotNull("has " + dstName, remoteRepository.getRef(dstName)); - assertEquals(Q, remoteRepository.getRef(dstName).getObjectId()); + assertNotNull("has " + dstName, remoteRepository.exactRef(dstName)); + assertEquals(Q, remoteRepository.exactRef(dstName).getObjectId()); fsck(remoteRepository, Q); List<AccessEvent> requests = getRequests(); diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java index 7bf4c26c38..939a9f6fdd 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java @@ -198,7 +198,8 @@ public class CheckoutTest extends CLIRepositoryTestCase { assertStringArrayEquals("Switched to a new branch 'new_branch'", execute("git checkout --orphan new_branch")); - assertEquals("refs/heads/new_branch", db.getRef("HEAD").getTarget().getName()); + assertEquals("refs/heads/new_branch", + db.exactRef("HEAD").getTarget().getName()); RevCommit commit = git.commit().setMessage("orphan commit").call(); assertEquals(0, commit.getParentCount()); } diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java index 0785c5c5ff..dae477928b 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java @@ -67,7 +67,7 @@ public class ResetTest extends CLIRepositoryTestCase { assertStringArrayEquals("", execute("git reset --hard " + commit.getId().name())); assertEquals(commit.getId(), - git.getRepository().getRef("HEAD").getObjectId()); + git.getRepository().exactRef("HEAD").getObjectId()); } @Test @@ -77,7 +77,7 @@ public class ResetTest extends CLIRepositoryTestCase { assertStringArrayEquals("", execute("git reset --hard " + commit.getId().name())); assertEquals(commit.getId(), - git.getRepository().getRef("HEAD").getObjectId()); + git.getRepository().exactRef("HEAD").getObjectId()); } @Test @@ -86,7 +86,7 @@ public class ResetTest extends CLIRepositoryTestCase { assertStringArrayEquals("", execute("git reset --hard " + commit.getId().name() + " --")); assertEquals(commit.getId(), - git.getRepository().getRef("HEAD").getObjectId()); + git.getRepository().exactRef("HEAD").getObjectId()); } @Test @@ -119,7 +119,7 @@ public class ResetTest extends CLIRepositoryTestCase { (useDoubleDash) ? " --" : ""); assertStringArrayEquals("", execute(cmd)); assertEquals(commit.getId(), - git.getRepository().getRef("HEAD").getObjectId()); + git.getRepository().exactRef("HEAD").getObjectId()); org.eclipse.jgit.api.Status status = git.status().call(); // assert that file a is unstaged diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java index 793fc7daf6..854c52d88b 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java @@ -42,13 +42,14 @@ */ package org.eclipse.jgit.pgm; +import static org.eclipse.jgit.lib.Constants.MASTER; +import static org.eclipse.jgit.lib.Constants.R_HEADS; import java.io.IOException; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.CLIRepositoryTestCase; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Test; @@ -254,7 +255,7 @@ public class StatusTest extends CLIRepositoryTestCase { } private void detachHead(Git git) throws IOException, GitAPIException { - String commitId = db.getRef(Constants.MASTER).getObjectId().name(); + String commitId = db.exactRef(R_HEADS + MASTER).getObjectId().name(); git.checkout().setName(commitId).call(); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index f7a50dffcb..82d509f6f3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -43,6 +43,8 @@ */ package org.eclipse.jgit.api; +import static org.eclipse.jgit.lib.Constants.MASTER; +import static org.eclipse.jgit.lib.Constants.R_HEADS; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; @@ -134,7 +136,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { @Test public void testCreateBranchOnCheckout() throws Exception { git.checkout().setCreateBranch(true).setName("test2").call(); - assertNotNull(db.getRef("test2")); + assertNotNull(db.exactRef("refs/heads/test2")); } @Test @@ -237,8 +239,8 @@ public class CheckoutCommandTest extends RepositoryTestCase { .setStartPoint("origin/test") .setUpstreamMode(SetupUpstreamMode.TRACK).call(); - assertEquals("refs/heads/test", db2.getRef(Constants.HEAD).getTarget() - .getName()); + assertEquals("refs/heads/test", + db2.exactRef(Constants.HEAD).getTarget().getName()); StoredConfig config = db2.getConfig(); assertEquals("origin", config.getString( ConfigConstants.CONFIG_BRANCH_SECTION, "test", @@ -345,7 +347,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { CheckoutCommand co = git.checkout(); co.setName("master").call(); - String commitId = db.getRef(Constants.MASTER).getObjectId().name(); + String commitId = db.exactRef(R_HEADS + MASTER).getObjectId().name(); co = git.checkout(); co.setName(commitId).call(); @@ -443,7 +445,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } private void assertHeadDetached() throws IOException { - Ref head = db.getRef(Constants.HEAD); + Ref head = db.exactRef(Constants.HEAD); assertFalse(head.isSymbolic()); assertSame(head, head.getTarget()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java index 060a5b65c6..0d03047d53 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java @@ -408,8 +408,10 @@ public class CommitCommandTest extends RepositoryTestCase { checkoutBranch("refs/heads/master"); - MergeResult result = git.merge().include(db.getRef("branch1")) - .setSquash(true).call(); + MergeResult result = git.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java index 0c0c6e5b55..cea8393ff7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java @@ -43,6 +43,8 @@ */ package org.eclipse.jgit.api; +import static org.eclipse.jgit.lib.Constants.MASTER; +import static org.eclipse.jgit.lib.Constants.R_HEADS; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -97,7 +99,7 @@ public class MergeCommandTest extends RepositoryTestCase { Git git = new Git(db); git.commit().setMessage("initial commit").call(); - MergeResult result = git.merge().include(db.getRef(Constants.HEAD)).call(); + MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call(); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); // no reflog entry written by merge assertEquals("commit (initial): initial commit", @@ -115,7 +117,7 @@ public class MergeCommandTest extends RepositoryTestCase { createBranch(first, "refs/heads/branch1"); RevCommit second = git.commit().setMessage("second commit").call(); - MergeResult result = git.merge().include(db.getRef("refs/heads/branch1")).call(); + MergeResult result = git.merge().include(db.exactRef("refs/heads/branch1")).call(); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); assertEquals(second, result.getNewHead()); // no reflog entry written by merge @@ -135,7 +137,7 @@ public class MergeCommandTest extends RepositoryTestCase { checkoutBranch("refs/heads/branch1"); - MergeResult result = git.merge().include(db.getRef(Constants.MASTER)).call(); + MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)).call(); assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(second, result.getNewHead()); @@ -155,7 +157,7 @@ public class MergeCommandTest extends RepositoryTestCase { checkoutBranch("refs/heads/branch1"); - MergeResult result = git.merge().include(db.getRef(Constants.MASTER)) + MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)) .setCommit(false).call(); assertEquals(MergeResult.MergeStatus.FAST_FORWARD, @@ -186,7 +188,7 @@ public class MergeCommandTest extends RepositoryTestCase { checkoutBranch("refs/heads/branch1"); assertFalse(new File(db.getWorkTree(), "file2").exists()); - MergeResult result = git.merge().include(db.getRef(Constants.MASTER)).call(); + MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)).call(); assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists()); @@ -221,7 +223,7 @@ public class MergeCommandTest extends RepositoryTestCase { MergeCommand merge = git.merge(); merge.include(second.getId()); - merge.include(db.getRef(Constants.MASTER)); + merge.include(db.exactRef(R_HEADS + MASTER)); try { merge.call(); fail("Expected exception not thrown when merging multiple heads"); @@ -248,7 +250,7 @@ public class MergeCommandTest extends RepositoryTestCase { git.commit().setMessage("third").call(); MergeResult result = git.merge().setStrategy(mergeStrategy) - .include(db.getRef(Constants.MASTER)).call(); + .include(db.exactRef(R_HEADS + MASTER)).call(); assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals( "merge refs/heads/master: Merge made by " @@ -279,9 +281,9 @@ public class MergeCommandTest extends RepositoryTestCase { MergeResult result = git.merge().setStrategy(mergeStrategy) .setCommit(false) - .include(db.getRef(Constants.MASTER)).call(); + .include(db.exactRef(R_HEADS + MASTER)).call(); assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); - assertEquals(db.getRef(Constants.HEAD).getTarget().getObjectId(), + assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), thirdCommit.getId()); } @@ -378,7 +380,7 @@ public class MergeCommandTest extends RepositoryTestCase { git.add().addFilepattern("a").call(); git.commit().setMessage("main").call(); - Ref sideBranch = db.getRef("side"); + Ref sideBranch = db.exactRef("refs/heads/side"); git.merge().include(sideBranch) .setStrategy(MergeStrategy.RESOLVE).call(); @@ -590,7 +592,7 @@ public class MergeCommandTest extends RepositoryTestCase { .setCommit(false) .setStrategy(MergeStrategy.RESOLVE).call(); assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); - assertEquals(db.getRef(Constants.HEAD).getTarget().getObjectId(), + assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), thirdCommit.getId()); assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), @@ -1310,8 +1312,10 @@ public class MergeCommandTest extends RepositoryTestCase { assertFalse(new File(db.getWorkTree(), "file2").exists()); assertFalse(new File(db.getWorkTree(), "file3").exists()); - MergeResult result = git.merge().include(db.getRef("branch1")) - .setSquash(true).call(); + MergeResult result = git.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists()); @@ -1375,8 +1379,10 @@ public class MergeCommandTest extends RepositoryTestCase { assertTrue(new File(db.getWorkTree(), "file2").exists()); assertFalse(new File(db.getWorkTree(), "file3").exists()); - MergeResult result = git.merge().include(db.getRef("branch1")) - .setSquash(true).call(); + MergeResult result = git.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists()); @@ -1430,8 +1436,10 @@ public class MergeCommandTest extends RepositoryTestCase { assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists()); - MergeResult result = git.merge().include(db.getRef("branch1")) - .setSquash(true).call(); + MergeResult result = git.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists()); @@ -1468,7 +1476,7 @@ public class MergeCommandTest extends RepositoryTestCase { MergeCommand merge = git.merge(); merge.setFastForward(FastForwardMode.FF_ONLY); - merge.include(db.getRef(Constants.MASTER)); + merge.include(db.exactRef(R_HEADS + MASTER)); MergeResult result = merge.call(); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); @@ -1485,7 +1493,7 @@ public class MergeCommandTest extends RepositoryTestCase { MergeCommand merge = git.merge(); merge.setFastForward(FastForwardMode.NO_FF); - merge.include(db.getRef(Constants.MASTER)); + merge.include(db.exactRef(R_HEADS + MASTER)); MergeResult result = merge.call(); assertEquals(MergeStatus.MERGED, result.getMergeStatus()); @@ -1505,7 +1513,7 @@ public class MergeCommandTest extends RepositoryTestCase { // when MergeCommand merge = git.merge(); merge.setFastForward(FastForwardMode.NO_FF); - merge.include(db.getRef(Constants.MASTER)); + merge.include(db.exactRef(R_HEADS + MASTER)); merge.setCommit(false); MergeResult result = merge.call(); @@ -1531,7 +1539,7 @@ public class MergeCommandTest extends RepositoryTestCase { git.commit().setMessage("second commit on branch1").call(); MergeCommand merge = git.merge(); merge.setFastForward(FastForwardMode.FF_ONLY); - merge.include(db.getRef(Constants.MASTER)); + merge.include(db.exactRef(R_HEADS + MASTER)); MergeResult result = merge.call(); assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); @@ -1588,7 +1596,7 @@ public class MergeCommandTest extends RepositoryTestCase { git.add().addFilepattern("c").call(); git.commit().setMessage("main").call(); - Ref sideBranch = db.getRef("side"); + Ref sideBranch = db.exactRef("refs/heads/side"); git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) .setMessage("user message").call(); @@ -1621,7 +1629,7 @@ public class MergeCommandTest extends RepositoryTestCase { git.add().addFilepattern("a").call(); git.commit().setMessage("main").call(); - Ref sideBranch = db.getRef("side"); + Ref sideBranch = db.exactRef("refs/heads/side"); git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) .setMessage("user message").call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java index 491595498e..bd62200fce 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java @@ -95,9 +95,9 @@ public class NameRevCommandTest extends RepositoryTestCase { tr.update("refs/heads/master", c); tr.update("refs/tags/tag", c); assertOneResult("master", - git.nameRev().addRef(db.getRef("refs/heads/master")), c); + git.nameRev().addRef(db.exactRef("refs/heads/master")), c); assertOneResult("tag", - git.nameRev().addRef(db.getRef("refs/tags/tag")), c); + git.nameRev().addRef(db.exactRef("refs/tags/tag")), c); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java index 9997c8c426..a67f2b912a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java @@ -477,8 +477,10 @@ public class ResetCommandTest extends RepositoryTestCase { checkoutBranch("refs/heads/master"); - MergeResult result = g.merge().include(db.getRef("branch1")) - .setSquash(true).call(); + MergeResult result = g.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED, result.getMergeStatus()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java index c317e3beef..ae8551e641 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java @@ -110,7 +110,7 @@ public class StashCreateCommandTest extends RepositoryTestCase { int parentCount) throws IOException { assertNotNull(commit); - Ref stashRef = db.getRef(Constants.R_STASH); + Ref stashRef = db.exactRef(Constants.R_STASH); assertNotNull(stashRef); assertEquals(commit, stashRef.getObjectId()); assertNotNull(commit.getAuthorIdent()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java index cfad817d23..859277e93f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java @@ -96,13 +96,13 @@ public class StashDropCommandTest extends RepositoryTestCase { @Test public void dropWithInvalidLogIndex() throws Exception { write(committedFile, "content2"); - Ref stashRef = git.getRepository().getRef(Constants.R_STASH); + Ref stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); RevCommit stashed = git.stashCreate().call(); assertNotNull(stashed); - stashRef = git.getRepository().getRef(Constants.R_STASH); - assertEquals(stashed, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + stashRef = git.getRepository().exactRef(Constants.R_STASH); + assertEquals(stashed, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); try { assertNull(git.stashDrop().setStashRef(100).call()); fail("Exception not thrown"); @@ -115,15 +115,15 @@ public class StashDropCommandTest extends RepositoryTestCase { @Test public void dropSingleStashedCommit() throws Exception { write(committedFile, "content2"); - Ref stashRef = git.getRepository().getRef(Constants.R_STASH); + Ref stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); RevCommit stashed = git.stashCreate().call(); assertNotNull(stashed); - stashRef = git.getRepository().getRef(Constants.R_STASH); - assertEquals(stashed, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + stashRef = git.getRepository().exactRef(Constants.R_STASH); + assertEquals(stashed, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); assertNull(git.stashDrop().call()); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); ReflogReader reader = git.getRepository().getReflogReader( @@ -134,25 +134,25 @@ public class StashDropCommandTest extends RepositoryTestCase { @Test public void dropAll() throws Exception { write(committedFile, "content2"); - Ref stashRef = git.getRepository().getRef(Constants.R_STASH); + Ref stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); RevCommit firstStash = git.stashCreate().call(); assertNotNull(firstStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(firstStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); write(committedFile, "content3"); RevCommit secondStash = git.stashCreate().call(); assertNotNull(secondStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(secondStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); assertNull(git.stashDrop().setAll(true).call()); - assertNull(git.getRepository().getRef(Constants.R_STASH)); + assertNull(git.getRepository().exactRef(Constants.R_STASH)); ReflogReader reader = git.getRepository().getReflogReader( Constants.R_STASH); @@ -162,25 +162,25 @@ public class StashDropCommandTest extends RepositoryTestCase { @Test public void dropFirstStashedCommit() throws Exception { write(committedFile, "content2"); - Ref stashRef = git.getRepository().getRef(Constants.R_STASH); + Ref stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); RevCommit firstStash = git.stashCreate().call(); assertNotNull(firstStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(firstStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); write(committedFile, "content3"); RevCommit secondStash = git.stashCreate().call(); assertNotNull(secondStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(secondStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); assertEquals(firstStash, git.stashDrop().call()); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); assertEquals(firstStash, stashRef.getObjectId()); @@ -196,33 +196,33 @@ public class StashDropCommandTest extends RepositoryTestCase { @Test public void dropMiddleStashCommit() throws Exception { write(committedFile, "content2"); - Ref stashRef = git.getRepository().getRef(Constants.R_STASH); + Ref stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); RevCommit firstStash = git.stashCreate().call(); assertNotNull(firstStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(firstStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); write(committedFile, "content3"); RevCommit secondStash = git.stashCreate().call(); assertNotNull(secondStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(secondStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); write(committedFile, "content4"); RevCommit thirdStash = git.stashCreate().call(); assertNotNull(thirdStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(thirdStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(thirdStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); assertEquals(thirdStash, git.stashDrop().setStashRef(1).call()); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); assertEquals(thirdStash, stashRef.getObjectId()); @@ -241,46 +241,46 @@ public class StashDropCommandTest extends RepositoryTestCase { @Test public void dropBoundaryStashedCommits() throws Exception { write(committedFile, "content2"); - Ref stashRef = git.getRepository().getRef(Constants.R_STASH); + Ref stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNull(stashRef); RevCommit firstStash = git.stashCreate().call(); assertNotNull(firstStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(firstStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); write(committedFile, "content3"); RevCommit secondStash = git.stashCreate().call(); assertNotNull(secondStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(secondStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); write(committedFile, "content4"); RevCommit thirdStash = git.stashCreate().call(); assertNotNull(thirdStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(thirdStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(thirdStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); write(committedFile, "content5"); RevCommit fourthStash = git.stashCreate().call(); assertNotNull(fourthStash); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); - assertEquals(fourthStash, git.getRepository().getRef(Constants.R_STASH) - .getObjectId()); + assertEquals(fourthStash, + git.getRepository().exactRef(Constants.R_STASH).getObjectId()); assertEquals(thirdStash, git.stashDrop().call()); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); assertEquals(thirdStash, stashRef.getObjectId()); assertEquals(thirdStash, git.stashDrop().setStashRef(2).call()); - stashRef = git.getRepository().getRef(Constants.R_STASH); + stashRef = git.getRepository().exactRef(Constants.R_STASH); assertNotNull(stashRef); assertEquals(thirdStash, stashRef.getObjectId()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java index c7336da408..fa40458f34 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java @@ -77,7 +77,7 @@ public class GcPackRefsTest extends GcTestCase { tr.lightweightTag("t", a); gc.packRefs(); - assertSame(repo.getRef("t").getStorage(), Storage.PACKED); + assertSame(repo.exactRef("refs/tags/t").getStorage(), Storage.PACKED); } @Test @@ -126,8 +126,8 @@ public class GcPackRefsTest extends GcTestCase { refLock.unlock(); } - assertSame(repo.getRef("refs/tags/t1").getStorage(), Storage.LOOSE); - assertSame(repo.getRef("refs/tags/t2").getStorage(), Storage.PACKED); + assertSame(repo.exactRef("refs/tags/t1").getStorage(), Storage.LOOSE); + assertSame(repo.exactRef("refs/tags/t2").getStorage(), Storage.PACKED); } @Test @@ -146,7 +146,7 @@ public class GcPackRefsTest extends GcTestCase { public Result call() throws Exception { RefUpdate update = new RefDirectoryUpdate( (RefDirectory) repo.getRefDatabase(), - repo.getRef("refs/tags/t")) { + repo.exactRef("refs/tags/t")) { @Override public boolean isForceUpdate() { try { @@ -182,7 +182,7 @@ public class GcPackRefsTest extends GcTestCase { pool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); } - assertEquals(repo.getRef("refs/tags/t").getObjectId(), b); + assertEquals(repo.exactRef("refs/tags/t").getObjectId(), b); } @Test @@ -194,23 +194,23 @@ public class GcPackRefsTest extends GcTestCase { // check for the unborn branch master. HEAD should point to master and // master doesn't exist. - assertEquals(repo.getRef("HEAD").getTarget().getName(), + assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master"); - assertNull(repo.getRef("HEAD").getTarget().getObjectId()); + assertNull(repo.exactRef("HEAD").getTarget().getObjectId()); gc.packRefs(); - assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); - assertEquals(repo.getRef("HEAD").getTarget().getName(), + assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE); + assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master"); - assertNull(repo.getRef("HEAD").getTarget().getObjectId()); + assertNull(repo.exactRef("HEAD").getTarget().getObjectId()); git.checkout().setName("refs/heads/side").call(); gc.packRefs(); - assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); + assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE); // check for detached HEAD git.checkout().setName(first.getName()).call(); gc.packRefs(); - assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); + assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE); } @Test @@ -229,20 +229,20 @@ public class GcPackRefsTest extends GcTestCase { // check for the unborn branch master. HEAD should point to master and // master doesn't exist. - assertEquals(repo.getRef("HEAD").getTarget().getName(), + assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master"); - assertNull(repo.getRef("HEAD").getTarget().getObjectId()); + assertNull(repo.exactRef("HEAD").getTarget().getObjectId()); gc.packRefs(); - assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); - assertEquals(repo.getRef("HEAD").getTarget().getName(), + assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE); + assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master"); - assertNull(repo.getRef("HEAD").getTarget().getObjectId()); + assertNull(repo.exactRef("HEAD").getTarget().getObjectId()); // check for non-detached HEAD repo.updateRef(Constants.HEAD).link("refs/heads/side"); gc.packRefs(); - assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); - assertEquals(repo.getRef("HEAD").getTarget().getObjectId(), + assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE); + assertEquals(repo.exactRef("HEAD").getTarget().getObjectId(), second.getId()); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java index 098b31fccf..8744ed1bd6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java @@ -347,7 +347,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { Result update = updateRef.update(); assertEquals(Result.FORCED, update); assertEquals(ppid, db.resolve("HEAD")); - Ref ref = db.getRef("HEAD"); + Ref ref = db.exactRef("HEAD"); assertEquals("HEAD", ref.getName()); assertTrue("is detached", !ref.isSymbolic()); @@ -377,7 +377,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { Result update = updateRef.update(); assertEquals(Result.NEW, update); assertEquals(ppid, db.resolve("HEAD")); - Ref ref = db.getRef("HEAD"); + Ref ref = db.exactRef("HEAD"); assertEquals("HEAD", ref.getName()); assertTrue("is detached", !ref.isSymbolic()); @@ -681,13 +681,13 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { public void testRenameBranchAlsoInPack() throws IOException { ObjectId rb = db.resolve("refs/heads/b"); ObjectId rb2 = db.resolve("refs/heads/b~1"); - assertEquals(Ref.Storage.PACKED, db.getRef("refs/heads/b").getStorage()); + assertEquals(Ref.Storage.PACKED, db.exactRef("refs/heads/b").getStorage()); RefUpdate updateRef = db.updateRef("refs/heads/b"); updateRef.setNewObjectId(rb2); updateRef.setForceUpdate(true); Result update = updateRef.update(); assertEquals("internal check new ref is loose", Result.FORCED, update); - assertEquals(Ref.Storage.LOOSE, db.getRef("refs/heads/b").getStorage()); + assertEquals(Ref.Storage.LOOSE, db.exactRef("refs/heads/b").getStorage()); writeReflog(db, rb, "Just a message", "refs/heads/b"); assertTrue("log on old branch", new File(db.getDirectory(), "logs/refs/heads/b").exists()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java index b69b8e01e0..8b54dabce3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java @@ -127,25 +127,25 @@ public class TestRepositoryTest { @Test public void resetFromSymref() throws Exception { repo.updateRef("HEAD").link("refs/heads/master"); - Ref head = repo.getRef("HEAD"); + Ref head = repo.exactRef("HEAD"); RevCommit master = tr.branch("master").commit().create(); RevCommit branch = tr.branch("branch").commit().create(); RevCommit detached = tr.commit().create(); assertTrue(head.isSymbolic()); assertEquals("refs/heads/master", head.getTarget().getName()); - assertEquals(master, repo.getRef("refs/heads/master").getObjectId()); - assertEquals(branch, repo.getRef("refs/heads/branch").getObjectId()); + assertEquals(master, repo.exactRef("refs/heads/master").getObjectId()); + assertEquals(branch, repo.exactRef("refs/heads/branch").getObjectId()); // Reset to branches preserves symref. tr.reset("master"); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(master, head.getObjectId()); assertTrue(head.isSymbolic()); assertEquals("refs/heads/master", head.getTarget().getName()); tr.reset("branch"); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(branch, head.getObjectId()); assertTrue(head.isSymbolic()); assertEquals("refs/heads/master", head.getTarget().getName()); @@ -153,50 +153,50 @@ public class TestRepositoryTest { // Reset to a SHA-1 detaches. tr.reset(detached); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(detached, head.getObjectId()); assertFalse(head.isSymbolic()); tr.reset(detached.name()); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(detached, head.getObjectId()); assertFalse(head.isSymbolic()); // Reset back to a branch remains detached. tr.reset("master"); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(lastHeadBeforeDetach, head.getObjectId()); assertFalse(head.isSymbolic()); } @Test public void resetFromDetachedHead() throws Exception { - Ref head = repo.getRef("HEAD"); + Ref head = repo.exactRef("HEAD"); RevCommit master = tr.branch("master").commit().create(); RevCommit branch = tr.branch("branch").commit().create(); RevCommit detached = tr.commit().create(); assertNull(head); - assertEquals(master, repo.getRef("refs/heads/master").getObjectId()); - assertEquals(branch, repo.getRef("refs/heads/branch").getObjectId()); + assertEquals(master, repo.exactRef("refs/heads/master").getObjectId()); + assertEquals(branch, repo.exactRef("refs/heads/branch").getObjectId()); tr.reset("master"); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(master, head.getObjectId()); assertFalse(head.isSymbolic()); tr.reset("branch"); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(branch, head.getObjectId()); assertFalse(head.isSymbolic()); tr.reset(detached); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(detached, head.getObjectId()); assertFalse(head.isSymbolic()); tr.reset(detached.name()); - head = repo.getRef("HEAD"); + head = repo.exactRef("HEAD"); assertEquals(detached, head.getObjectId()); assertFalse(head.isSymbolic()); } @@ -222,7 +222,7 @@ public class TestRepositoryTest { .tick(3) .add("bar", "fixed bar contents") .create(); - assertEquals(amended, repo.getRef("refs/heads/master").getObjectId()); + assertEquals(amended, repo.exactRef("refs/heads/master").getObjectId()); rw.parseBody(amended); assertEquals(1, amended.getParentCount()); @@ -257,7 +257,7 @@ public class TestRepositoryTest { .add("foo", "fixed foo contents") .create(); - Ref head = repo.getRef(Constants.HEAD); + Ref head = repo.exactRef(Constants.HEAD); assertEquals(amended, head.getObjectId()); assertTrue(head.isSymbolic()); assertEquals("refs/heads/master", head.getTarget().getName()); @@ -291,7 +291,7 @@ public class TestRepositoryTest { public void commitToUnbornHead() throws Exception { repo.updateRef("HEAD").link("refs/heads/master"); RevCommit root = tr.branch("HEAD").commit().create(); - Ref ref = repo.getRef(Constants.HEAD); + Ref ref = repo.exactRef(Constants.HEAD); assertEquals(root, ref.getObjectId()); assertTrue(ref.isSymbolic()); assertEquals("refs/heads/master", ref.getTarget().getName()); @@ -316,7 +316,7 @@ public class TestRepositoryTest { RevCommit result = tr.cherryPick(toPick); rw.parseBody(result); - Ref headRef = tr.getRepository().getRef("HEAD"); + Ref headRef = tr.getRepository().exactRef("HEAD"); assertEquals(result, headRef.getObjectId()); assertTrue(headRef.isSymbolic()); assertEquals("refs/heads/master", headRef.getLeaf().getName()); @@ -371,7 +371,7 @@ public class TestRepositoryTest { .create(); assertNotEquals(head, toPick); assertNull(tr.cherryPick(toPick)); - assertEquals(head, repo.getRef("HEAD").getObjectId()); + assertEquals(head, repo.exactRef("HEAD").getObjectId()); } private String blobAsString(AnyObjectId treeish, String path) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java index 109f401898..707757b343 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java @@ -163,7 +163,7 @@ public class RefTest extends SampleDataRepositoryTestCase { @Test public void testReadSymRefToPacked() throws IOException { writeSymref("HEAD", "refs/heads/b"); - Ref ref = db.getRef("HEAD"); + Ref ref = db.exactRef("HEAD"); assertEquals(Ref.Storage.LOOSE, ref.getStorage()); assertTrue("is symref", ref.isSymbolic()); ref = ref.getTarget(); @@ -181,7 +181,7 @@ public class RefTest extends SampleDataRepositoryTestCase { assertEquals(Result.FORCED, update); // internal writeSymref("HEAD", "refs/heads/master"); - Ref ref = db.getRef("HEAD"); + Ref ref = db.exactRef("HEAD"); assertEquals(Ref.Storage.LOOSE, ref.getStorage()); ref = ref.getTarget(); assertEquals("refs/heads/master", ref.getName()); @@ -194,13 +194,13 @@ public class RefTest extends SampleDataRepositoryTestCase { updateRef.setNewObjectId(db.resolve("refs/heads/master")); Result update = updateRef.update(); assertEquals(Result.NEW, update); - Ref ref = db.getRef("ref/heads/new"); + Ref ref = db.exactRef("ref/heads/new"); assertEquals(Storage.LOOSE, ref.getStorage()); } @Test public void testGetShortRef() throws IOException { - Ref ref = db.getRef("master"); + Ref ref = db.exactRef("refs/heads/master"); assertEquals("refs/heads/master", ref.getName()); assertEquals(db.resolve("refs/heads/master"), ref.getObjectId()); } @@ -222,7 +222,7 @@ public class RefTest extends SampleDataRepositoryTestCase { assertNull(db.getRefDatabase().exactRef("refs/foo/bar")); - Ref ref = db.getRef("refs/foo/bar"); + Ref ref = db.findRef("refs/foo/bar"); assertEquals("refs/heads/refs/foo/bar", ref.getName()); assertEquals(db.resolve("refs/heads/master"), ref.getObjectId()); } @@ -237,7 +237,7 @@ public class RefTest extends SampleDataRepositoryTestCase { assertEquals("refs/foo/bar", exactRef.getName()); assertEquals(masterId, exactRef.getObjectId()); - Ref ref = db.getRef("refs/foo/bar"); + Ref ref = db.findRef("refs/foo/bar"); assertEquals("refs/foo/bar", ref.getName()); assertEquals(masterId, ref.getObjectId()); } @@ -251,7 +251,7 @@ public class RefTest extends SampleDataRepositoryTestCase { @Test public void testReadLoosePackedRef() throws IOException, InterruptedException { - Ref ref = db.getRef("refs/heads/master"); + Ref ref = db.exactRef("refs/heads/master"); assertEquals(Storage.PACKED, ref.getStorage()); FileOutputStream os = new FileOutputStream(new File(db.getDirectory(), "refs/heads/master")); @@ -259,7 +259,7 @@ public class RefTest extends SampleDataRepositoryTestCase { os.write('\n'); os.close(); - ref = db.getRef("refs/heads/master"); + ref = db.exactRef("refs/heads/master"); assertEquals(Storage.LOOSE, ref.getStorage()); } @@ -271,7 +271,7 @@ public class RefTest extends SampleDataRepositoryTestCase { */ @Test public void testReadSimplePackedRefSameRepo() throws IOException { - Ref ref = db.getRef("refs/heads/master"); + Ref ref = db.exactRef("refs/heads/master"); ObjectId pid = db.resolve("refs/heads/master^"); assertEquals(Storage.PACKED, ref.getStorage()); RefUpdate updateRef = db.updateRef("refs/heads/master"); @@ -280,19 +280,19 @@ public class RefTest extends SampleDataRepositoryTestCase { Result update = updateRef.update(); assertEquals(Result.FORCED, update); - ref = db.getRef("refs/heads/master"); + ref = db.exactRef("refs/heads/master"); assertEquals(Storage.LOOSE, ref.getStorage()); } @Test public void testResolvedNamesBranch() throws IOException { - Ref ref = db.getRef("a"); + Ref ref = db.findRef("a"); assertEquals("refs/heads/a", ref.getName()); } @Test public void testResolvedSymRef() throws IOException { - Ref ref = db.getRef(Constants.HEAD); + Ref ref = db.exactRef(Constants.HEAD); assertEquals(Constants.HEAD, ref.getName()); assertTrue("is symbolic ref", ref.isSymbolic()); assertSame(Ref.Storage.LOOSE, ref.getStorage()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java index 21ef7479a2..6c90f7d44b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java @@ -84,44 +84,44 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { @Test public void testOneBranch() throws IOException { - Ref a = db.getRef("refs/heads/a"); - Ref master = db.getRef("refs/heads/master"); + Ref a = db.exactRef("refs/heads/a"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(a), master); assertEquals("Merge branch 'a'", message); } @Test public void testTwoBranches() throws IOException { - Ref a = db.getRef("refs/heads/a"); - Ref b = db.getRef("refs/heads/b"); - Ref master = db.getRef("refs/heads/master"); + Ref a = db.exactRef("refs/heads/a"); + Ref b = db.exactRef("refs/heads/b"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(a, b), master); assertEquals("Merge branches 'a' and 'b'", message); } @Test public void testThreeBranches() throws IOException { - Ref c = db.getRef("refs/heads/c"); - Ref b = db.getRef("refs/heads/b"); - Ref a = db.getRef("refs/heads/a"); - Ref master = db.getRef("refs/heads/master"); + Ref c = db.exactRef("refs/heads/c"); + Ref b = db.exactRef("refs/heads/b"); + Ref a = db.exactRef("refs/heads/a"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(c, b, a), master); assertEquals("Merge branches 'c', 'b' and 'a'", message); } @Test public void testRemoteBranch() throws Exception { - Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); - Ref master = db.getRef("refs/heads/master"); + Ref remoteA = db.exactRef("refs/remotes/origin/remote-a"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(remoteA), master); assertEquals("Merge remote-tracking branch 'origin/remote-a'", message); } @Test public void testMixed() throws IOException { - Ref c = db.getRef("refs/heads/c"); - Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); - Ref master = db.getRef("refs/heads/master"); + Ref c = db.exactRef("refs/heads/c"); + Ref remoteA = db.exactRef("refs/remotes/origin/remote-a"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(c, remoteA), master); assertEquals("Merge branch 'c', remote-tracking branch 'origin/remote-a'", message); @@ -129,8 +129,8 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { @Test public void testTag() throws IOException { - Ref tagA = db.getRef("refs/tags/A"); - Ref master = db.getRef("refs/heads/master"); + Ref tagA = db.exactRef("refs/tags/A"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(tagA), master); assertEquals("Merge tag 'A'", message); } @@ -141,7 +141,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4"); Ref commit = new ObjectIdRef.Unpeeled(Storage.LOOSE, objectId.getName(), objectId); - Ref master = db.getRef("refs/heads/master"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(commit), master); assertEquals("Merge commit '6db9c2ebf75590eef973081736730a9ea169a0c4'", message); @@ -154,7 +154,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4"); Ref remoteBranch = new ObjectIdRef.Unpeeled(Storage.LOOSE, name, objectId); - Ref master = db.getRef("refs/heads/master"); + Ref master = db.exactRef("refs/heads/master"); String message = formatter.format(Arrays.asList(remoteBranch), master); assertEquals("Merge branch 'test' of http://egit.eclipse.org/jgit.git", message); @@ -162,16 +162,16 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { @Test public void testIntoOtherThanMaster() throws IOException { - Ref a = db.getRef("refs/heads/a"); - Ref b = db.getRef("refs/heads/b"); + Ref a = db.exactRef("refs/heads/a"); + Ref b = db.exactRef("refs/heads/b"); String message = formatter.format(Arrays.asList(a), b); assertEquals("Merge branch 'a' into b", message); } @Test public void testIntoHeadOtherThanMaster() throws IOException { - Ref a = db.getRef("refs/heads/a"); - Ref b = db.getRef("refs/heads/b"); + Ref a = db.exactRef("refs/heads/a"); + Ref b = db.exactRef("refs/heads/b"); SymbolicRef head = new SymbolicRef("HEAD", b); String message = formatter.format(Arrays.asList(a), head); assertEquals("Merge branch 'a' into b", message); @@ -179,8 +179,8 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase { @Test public void testIntoSymbolicRefHeadPointingToMaster() throws IOException { - Ref a = db.getRef("refs/heads/a"); - Ref master = db.getRef("refs/heads/master"); + Ref a = db.exactRef("refs/heads/a"); + Ref master = db.exactRef("refs/heads/master"); SymbolicRef head = new SymbolicRef("HEAD", master); String message = formatter.format(Arrays.asList(a), head); assertEquals("Merge branch 'a'", message); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java index cd6a4bea2e..674619f0de 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java @@ -630,7 +630,7 @@ public class ResolveMergerTest extends RepositoryTestCase { // ResolveMerge try { MergeResult mergeResult = git.merge().setStrategy(strategy) - .include(git.getRepository().getRef("refs/heads/side")) + .include(git.getRepository().exactRef("refs/heads/side")) .call(); assertEquals(MergeStrategy.RECURSIVE, strategy); assertEquals(MergeResult.MergeStatus.MERGED, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java index b7b2291429..cddbbd528b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java @@ -76,7 +76,7 @@ public class SquashMessageFormatterTest extends SampleDataRepositoryTestCase { Git git = new Git(db); revCommit = git.commit().setMessage("squash_me").call(); - Ref master = db.getRef("refs/heads/master"); + Ref master = db.exactRef("refs/heads/master"); String message = msgFormatter.format(Arrays.asList(revCommit), master); assertEquals( "Squashed commit of the following:\n\ncommit " diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java index 7f865263d6..31b64187c8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java @@ -125,7 +125,7 @@ public class TestProtocolTest { .setRefSpecs(HEADS) .call(); assertEquals(master, - local.getRepository().getRef("master").getObjectId()); + local.getRepository().exactRef("refs/heads/master").getObjectId()); } } @@ -142,7 +142,7 @@ public class TestProtocolTest { .setRefSpecs(HEADS) .call(); assertEquals(master, - remote.getRepository().getRef("master").getObjectId()); + remote.getRepository().exactRef("refs/heads/master").getObjectId()); } } @@ -177,7 +177,7 @@ public class TestProtocolTest { // Expected. } assertEquals(1, rejected.get()); - assertNull(local.getRepository().getRef("master")); + assertNull(local.getRepository().exactRef("refs/heads/master")); git.fetch() .setRemote(user2Uri.toString()) @@ -185,7 +185,7 @@ public class TestProtocolTest { .call(); assertEquals(1, rejected.get()); assertEquals(master, - local.getRepository().getRef("master").getObjectId()); + local.getRepository().exactRef("refs/heads/master").getObjectId()); } } @@ -222,7 +222,7 @@ public class TestProtocolTest { JGitText.get().pushNotPermitted)); } assertEquals(1, rejected.get()); - assertNull(remote.getRepository().getRef("master")); + assertNull(remote.getRepository().exactRef("refs/heads/master")); git.push() .setRemote(user2Uri.toString()) @@ -230,7 +230,7 @@ public class TestProtocolTest { .call(); assertEquals(1, rejected.get()); assertEquals(master, - remote.getRepository().getRef("master").getObjectId()); + remote.getRepository().exactRef("refs/heads/master").getObjectId()); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index c91f2dab72..49a970d03a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -964,9 +964,44 @@ public abstract class Repository implements AutoCloseable { * "refs/heads/master" if "refs/heads/master" already exists. * @return the Ref with the given name, or {@code null} if it does not exist * @throws IOException + * @deprecated Use {@link #exactRef(String)} or {@link #findRef(String)} + * instead. */ + @Deprecated @Nullable public Ref getRef(final String name) throws IOException { + return findRef(name); + } + + /** + * Get a ref by name. + * + * @param name + * the name of the ref to lookup. Must not be a short-hand + * form; e.g., "master" is not automatically expanded to + * "refs/heads/master". + * @return the Ref with the given name, or {@code null} if it does not exist + * @throws IOException + * @since 4.2 + */ + @Nullable + public Ref exactRef(String name) throws IOException { + return getRefDatabase().exactRef(name); + } + + /** + * Search for a ref by (possibly abbreviated) name. + * + * @param name + * the name of the ref to lookup. May be a short-hand form, e.g. + * "master" which is is automatically expanded to + * "refs/heads/master" if "refs/heads/master" already exists. + * @return the Ref with the given name, or {@code null} if it does not exist + * @throws IOException + * @since 4.2 + */ + @Nullable + public Ref findRef(String name) throws IOException { return getRefDatabase().getRef(name); } |