Browse Source

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>
stable-4.3
Jonathan Nieder 10 years ago
parent
commit
5be4814e38
  1. 4
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java
  2. 4
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java
  3. 4
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HookMessageTest.java
  4. 18
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
  5. 3
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java
  6. 8
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java
  7. 5
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java
  8. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
  9. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
  10. 54
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  11. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NameRevCommandTest.java
  12. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
  13. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
  14. 102
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java
  15. 38
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
  16. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
  17. 40
      org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
  18. 24
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
  19. 48
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java
  20. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
  21. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java
  22. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java
  23. 35
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

4
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)); assertTrue(dst.hasObject(A_txt));
assertEquals(B, dst.getRef(master).getObjectId()); assertEquals(B, dst.exactRef(master).getObjectId());
fsck(dst, B); fsck(dst, B);
List<AccessEvent> loose = getRequests(loose(remoteURI, A_txt)); List<AccessEvent> loose = getRequests(loose(remoteURI, A_txt));
@ -234,7 +234,7 @@ public class DumbClientDumbServerTest extends HttpTestCase {
} }
assertTrue(dst.hasObject(A_txt)); assertTrue(dst.hasObject(A_txt));
assertEquals(B, dst.getRef(master).getObjectId()); assertEquals(B, dst.exactRef(master).getObjectId());
fsck(dst, B); fsck(dst, B);
List<AccessEvent> req; List<AccessEvent> req;

4
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)); assertTrue(dst.hasObject(A_txt));
assertEquals(B, dst.getRef(master).getObjectId()); assertEquals(B, dst.exactRef(master).getObjectId());
fsck(dst, B); fsck(dst, B);
List<AccessEvent> loose = getRequests(loose(remoteURI, A_txt)); List<AccessEvent> loose = getRequests(loose(remoteURI, A_txt));
@ -253,7 +253,7 @@ public class DumbClientSmartServerTest extends HttpTestCase {
} }
assertTrue(dst.hasObject(A_txt)); assertTrue(dst.hasObject(A_txt));
assertEquals(B, dst.getRef(master).getObjectId()); assertEquals(B, dst.exactRef(master).getObjectId());
fsck(dst, B); fsck(dst, B);
List<AccessEvent> req; List<AccessEvent> req;

4
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)); assertTrue(remoteRepository.hasObject(Q_txt));
assertNotNull("has " + dstName, remoteRepository.getRef(dstName)); assertNotNull("has " + dstName, remoteRepository.exactRef(dstName));
assertEquals(Q, remoteRepository.getRef(dstName).getObjectId()); assertEquals(Q, remoteRepository.exactRef(dstName).getObjectId());
fsck(remoteRepository, Q); fsck(remoteRepository, Q);
List<AccessEvent> requests = getRequests(); List<AccessEvent> requests = getRequests();

18
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)); assertTrue(dst.hasObject(A_txt));
assertEquals(B, dst.getRef(master).getObjectId()); assertEquals(B, dst.exactRef(master).getObjectId());
fsck(dst, B); fsck(dst, B);
List<AccessEvent> requests = getRequests(); List<AccessEvent> requests = getRequests();
@ -337,7 +337,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
} finally { } finally {
t.close(); t.close();
} }
assertEquals(B, dst.getRepository().getRef(master).getObjectId()); assertEquals(B, dst.getRepository().exactRef(master).getObjectId());
List<AccessEvent> cloneRequests = getRequests(); List<AccessEvent> cloneRequests = getRequests();
// Only create a few new commits. // Only create a few new commits.
@ -358,7 +358,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
} finally { } finally {
t.close(); t.close();
} }
assertEquals(Z, dst.getRepository().getRef(master).getObjectId()); assertEquals(Z, dst.getRepository().exactRef(master).getObjectId());
List<AccessEvent> requests = getRequests(); List<AccessEvent> requests = getRequests();
requests.removeAll(cloneRequests); requests.removeAll(cloneRequests);
@ -400,7 +400,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
} finally { } finally {
t.close(); t.close();
} }
assertEquals(B, dst.getRepository().getRef(master).getObjectId()); assertEquals(B, dst.getRepository().exactRef(master).getObjectId());
List<AccessEvent> cloneRequests = getRequests(); List<AccessEvent> cloneRequests = getRequests();
// Force enough into the local client that enumeration will // Force enough into the local client that enumeration will
@ -424,7 +424,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
} finally { } finally {
t.close(); t.close();
} }
assertEquals(Z, dst.getRepository().getRef(master).getObjectId()); assertEquals(Z, dst.getRepository().exactRef(master).getObjectId());
List<AccessEvent> requests = getRequests(); List<AccessEvent> requests = getRequests();
requests.removeAll(cloneRequests); requests.removeAll(cloneRequests);
@ -579,8 +579,8 @@ public class SmartClientSmartServerTest extends HttpTestCase {
} }
assertTrue(remoteRepository.hasObject(Q_txt)); assertTrue(remoteRepository.hasObject(Q_txt));
assertNotNull("has " + dstName, remoteRepository.getRef(dstName)); assertNotNull("has " + dstName, remoteRepository.exactRef(dstName));
assertEquals(Q, remoteRepository.getRef(dstName).getObjectId()); assertEquals(Q, remoteRepository.exactRef(dstName).getObjectId());
fsck(remoteRepository, Q); fsck(remoteRepository, Q);
final ReflogReader log = remoteRepository.getReflogReader(dstName); final ReflogReader log = remoteRepository.getReflogReader(dstName);
@ -657,8 +657,8 @@ public class SmartClientSmartServerTest extends HttpTestCase {
} }
assertTrue(remoteRepository.hasObject(Q_bin)); assertTrue(remoteRepository.hasObject(Q_bin));
assertNotNull("has " + dstName, remoteRepository.getRef(dstName)); assertNotNull("has " + dstName, remoteRepository.exactRef(dstName));
assertEquals(Q, remoteRepository.getRef(dstName).getObjectId()); assertEquals(Q, remoteRepository.exactRef(dstName).getObjectId());
fsck(remoteRepository, Q); fsck(remoteRepository, Q);
List<AccessEvent> requests = getRequests(); List<AccessEvent> requests = getRequests();

3
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'", assertStringArrayEquals("Switched to a new branch 'new_branch'",
execute("git checkout --orphan 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(); RevCommit commit = git.commit().setMessage("orphan commit").call();
assertEquals(0, commit.getParentCount()); assertEquals(0, commit.getParentCount());
} }

8
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ResetTest.java

@ -67,7 +67,7 @@ public class ResetTest extends CLIRepositoryTestCase {
assertStringArrayEquals("", assertStringArrayEquals("",
execute("git reset --hard " + commit.getId().name())); execute("git reset --hard " + commit.getId().name()));
assertEquals(commit.getId(), assertEquals(commit.getId(),
git.getRepository().getRef("HEAD").getObjectId()); git.getRepository().exactRef("HEAD").getObjectId());
} }
@Test @Test
@ -77,7 +77,7 @@ public class ResetTest extends CLIRepositoryTestCase {
assertStringArrayEquals("", assertStringArrayEquals("",
execute("git reset --hard " + commit.getId().name())); execute("git reset --hard " + commit.getId().name()));
assertEquals(commit.getId(), assertEquals(commit.getId(),
git.getRepository().getRef("HEAD").getObjectId()); git.getRepository().exactRef("HEAD").getObjectId());
} }
@Test @Test
@ -86,7 +86,7 @@ public class ResetTest extends CLIRepositoryTestCase {
assertStringArrayEquals("", assertStringArrayEquals("",
execute("git reset --hard " + commit.getId().name() + " --")); execute("git reset --hard " + commit.getId().name() + " --"));
assertEquals(commit.getId(), assertEquals(commit.getId(),
git.getRepository().getRef("HEAD").getObjectId()); git.getRepository().exactRef("HEAD").getObjectId());
} }
@Test @Test
@ -119,7 +119,7 @@ public class ResetTest extends CLIRepositoryTestCase {
(useDoubleDash) ? " --" : ""); (useDoubleDash) ? " --" : "");
assertStringArrayEquals("", execute(cmd)); assertStringArrayEquals("", execute(cmd));
assertEquals(commit.getId(), assertEquals(commit.getId(),
git.getRepository().getRef("HEAD").getObjectId()); git.getRepository().exactRef("HEAD").getObjectId());
org.eclipse.jgit.api.Status status = git.status().call(); org.eclipse.jgit.api.Status status = git.status().call();
// assert that file a is unstaged // assert that file a is unstaged

5
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/StatusTest.java

@ -42,13 +42,14 @@
*/ */
package org.eclipse.jgit.pgm; 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 java.io.IOException;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.CLIRepositoryTestCase; import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test; import org.junit.Test;
@ -254,7 +255,7 @@ public class StatusTest extends CLIRepositoryTestCase {
} }
private void detachHead(Git git) throws IOException, GitAPIException { 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(); git.checkout().setName(commitId).call();
} }

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

@ -43,6 +43,8 @@
*/ */
package org.eclipse.jgit.api; 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.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -134,7 +136,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
@Test @Test
public void testCreateBranchOnCheckout() throws Exception { public void testCreateBranchOnCheckout() throws Exception {
git.checkout().setCreateBranch(true).setName("test2").call(); git.checkout().setCreateBranch(true).setName("test2").call();
assertNotNull(db.getRef("test2")); assertNotNull(db.exactRef("refs/heads/test2"));
} }
@Test @Test
@ -237,8 +239,8 @@ public class CheckoutCommandTest extends RepositoryTestCase {
.setStartPoint("origin/test") .setStartPoint("origin/test")
.setUpstreamMode(SetupUpstreamMode.TRACK).call(); .setUpstreamMode(SetupUpstreamMode.TRACK).call();
assertEquals("refs/heads/test", db2.getRef(Constants.HEAD).getTarget() assertEquals("refs/heads/test",
.getName()); db2.exactRef(Constants.HEAD).getTarget().getName());
StoredConfig config = db2.getConfig(); StoredConfig config = db2.getConfig();
assertEquals("origin", config.getString( assertEquals("origin", config.getString(
ConfigConstants.CONFIG_BRANCH_SECTION, "test", ConfigConstants.CONFIG_BRANCH_SECTION, "test",
@ -345,7 +347,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
CheckoutCommand co = git.checkout(); CheckoutCommand co = git.checkout();
co.setName("master").call(); 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 = git.checkout();
co.setName(commitId).call(); co.setName(commitId).call();
@ -443,7 +445,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
} }
private void assertHeadDetached() throws IOException { private void assertHeadDetached() throws IOException {
Ref head = db.getRef(Constants.HEAD); Ref head = db.exactRef(Constants.HEAD);
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
assertSame(head, head.getTarget()); assertSame(head, head.getTarget());
} }

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java

@ -408,8 +408,10 @@ public class CommitCommandTest extends RepositoryTestCase {
checkoutBranch("refs/heads/master"); checkoutBranch("refs/heads/master");
MergeResult result = git.merge().include(db.getRef("branch1")) MergeResult result = git.merge()
.setSquash(true).call(); .include(db.exactRef("refs/heads/branch1"))
.setSquash(true)
.call();
assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());

54
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -43,6 +43,8 @@
*/ */
package org.eclipse.jgit.api; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@ -97,7 +99,7 @@ public class MergeCommandTest extends RepositoryTestCase {
Git git = new Git(db); Git git = new Git(db);
git.commit().setMessage("initial commit").call(); 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()); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
// no reflog entry written by merge // no reflog entry written by merge
assertEquals("commit (initial): initial commit", assertEquals("commit (initial): initial commit",
@ -115,7 +117,7 @@ public class MergeCommandTest extends RepositoryTestCase {
createBranch(first, "refs/heads/branch1"); createBranch(first, "refs/heads/branch1");
RevCommit second = git.commit().setMessage("second commit").call(); 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(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
// no reflog entry written by merge // no reflog entry written by merge
@ -135,7 +137,7 @@ public class MergeCommandTest extends RepositoryTestCase {
checkoutBranch("refs/heads/branch1"); 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(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
@ -155,7 +157,7 @@ public class MergeCommandTest extends RepositoryTestCase {
checkoutBranch("refs/heads/branch1"); 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(); .setCommit(false).call();
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, assertEquals(MergeResult.MergeStatus.FAST_FORWARD,
@ -186,7 +188,7 @@ public class MergeCommandTest extends RepositoryTestCase {
checkoutBranch("refs/heads/branch1"); checkoutBranch("refs/heads/branch1");
assertFalse(new File(db.getWorkTree(), "file2").exists()); 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(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
@ -221,7 +223,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeCommand merge = git.merge(); MergeCommand merge = git.merge();
merge.include(second.getId()); merge.include(second.getId());
merge.include(db.getRef(Constants.MASTER)); merge.include(db.exactRef(R_HEADS + MASTER));
try { try {
merge.call(); merge.call();
fail("Expected exception not thrown when merging multiple heads"); fail("Expected exception not thrown when merging multiple heads");
@ -248,7 +250,7 @@ public class MergeCommandTest extends RepositoryTestCase {
git.commit().setMessage("third").call(); git.commit().setMessage("third").call();
MergeResult result = git.merge().setStrategy(mergeStrategy) 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(MergeStatus.MERGED, result.getMergeStatus());
assertEquals( assertEquals(
"merge refs/heads/master: Merge made by " "merge refs/heads/master: Merge made by "
@ -279,9 +281,9 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().setStrategy(mergeStrategy) MergeResult result = git.merge().setStrategy(mergeStrategy)
.setCommit(false) .setCommit(false)
.include(db.getRef(Constants.MASTER)).call(); .include(db.exactRef(R_HEADS + MASTER)).call();
assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus());
assertEquals(db.getRef(Constants.HEAD).getTarget().getObjectId(), assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(),
thirdCommit.getId()); thirdCommit.getId());
} }
@ -378,7 +380,7 @@ public class MergeCommandTest extends RepositoryTestCase {
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
git.commit().setMessage("main").call(); git.commit().setMessage("main").call();
Ref sideBranch = db.getRef("side"); Ref sideBranch = db.exactRef("refs/heads/side");
git.merge().include(sideBranch) git.merge().include(sideBranch)
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
@ -590,7 +592,7 @@ public class MergeCommandTest extends RepositoryTestCase {
.setCommit(false) .setCommit(false)
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus());
assertEquals(db.getRef(Constants.HEAD).getTarget().getObjectId(), assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(),
thirdCommit.getId()); thirdCommit.getId());
assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), 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(), "file2").exists());
assertFalse(new File(db.getWorkTree(), "file3").exists()); assertFalse(new File(db.getWorkTree(), "file3").exists());
MergeResult result = git.merge().include(db.getRef("branch1")) MergeResult result = git.merge()
.setSquash(true).call(); .include(db.exactRef("refs/heads/branch1"))
.setSquash(true)
.call();
assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
@ -1375,8 +1379,10 @@ public class MergeCommandTest extends RepositoryTestCase {
assertTrue(new File(db.getWorkTree(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
assertFalse(new File(db.getWorkTree(), "file3").exists()); assertFalse(new File(db.getWorkTree(), "file3").exists());
MergeResult result = git.merge().include(db.getRef("branch1")) MergeResult result = git.merge()
.setSquash(true).call(); .include(db.exactRef("refs/heads/branch1"))
.setSquash(true)
.call();
assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").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(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
MergeResult result = git.merge().include(db.getRef("branch1")) MergeResult result = git.merge()
.setSquash(true).call(); .include(db.exactRef("refs/heads/branch1"))
.setSquash(true)
.call();
assertTrue(new File(db.getWorkTree(), "file1").exists()); assertTrue(new File(db.getWorkTree(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists()); assertTrue(new File(db.getWorkTree(), "file2").exists());
@ -1468,7 +1476,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeCommand merge = git.merge(); MergeCommand merge = git.merge();
merge.setFastForward(FastForwardMode.FF_ONLY); merge.setFastForward(FastForwardMode.FF_ONLY);
merge.include(db.getRef(Constants.MASTER)); merge.include(db.exactRef(R_HEADS + MASTER));
MergeResult result = merge.call(); MergeResult result = merge.call();
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
@ -1485,7 +1493,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeCommand merge = git.merge(); MergeCommand merge = git.merge();
merge.setFastForward(FastForwardMode.NO_FF); merge.setFastForward(FastForwardMode.NO_FF);
merge.include(db.getRef(Constants.MASTER)); merge.include(db.exactRef(R_HEADS + MASTER));
MergeResult result = merge.call(); MergeResult result = merge.call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED, result.getMergeStatus());
@ -1505,7 +1513,7 @@ public class MergeCommandTest extends RepositoryTestCase {
// when // when
MergeCommand merge = git.merge(); MergeCommand merge = git.merge();
merge.setFastForward(FastForwardMode.NO_FF); merge.setFastForward(FastForwardMode.NO_FF);
merge.include(db.getRef(Constants.MASTER)); merge.include(db.exactRef(R_HEADS + MASTER));
merge.setCommit(false); merge.setCommit(false);
MergeResult result = merge.call(); MergeResult result = merge.call();
@ -1531,7 +1539,7 @@ public class MergeCommandTest extends RepositoryTestCase {
git.commit().setMessage("second commit on branch1").call(); git.commit().setMessage("second commit on branch1").call();
MergeCommand merge = git.merge(); MergeCommand merge = git.merge();
merge.setFastForward(FastForwardMode.FF_ONLY); merge.setFastForward(FastForwardMode.FF_ONLY);
merge.include(db.getRef(Constants.MASTER)); merge.include(db.exactRef(R_HEADS + MASTER));
MergeResult result = merge.call(); MergeResult result = merge.call();
assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); assertEquals(MergeStatus.ABORTED, result.getMergeStatus());
@ -1588,7 +1596,7 @@ public class MergeCommandTest extends RepositoryTestCase {
git.add().addFilepattern("c").call(); git.add().addFilepattern("c").call();
git.commit().setMessage("main").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) git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE)
.setMessage("user message").call(); .setMessage("user message").call();
@ -1621,7 +1629,7 @@ public class MergeCommandTest extends RepositoryTestCase {
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
git.commit().setMessage("main").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) git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE)
.setMessage("user message").call(); .setMessage("user message").call();

4
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/heads/master", c);
tr.update("refs/tags/tag", c); tr.update("refs/tags/tag", c);
assertOneResult("master", assertOneResult("master",
git.nameRev().addRef(db.getRef("refs/heads/master")), c); git.nameRev().addRef(db.exactRef("refs/heads/master")), c);
assertOneResult("tag", assertOneResult("tag",
git.nameRev().addRef(db.getRef("refs/tags/tag")), c); git.nameRev().addRef(db.exactRef("refs/tags/tag")), c);
} }
@Test @Test

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java

@ -477,8 +477,10 @@ public class ResetCommandTest extends RepositoryTestCase {
checkoutBranch("refs/heads/master"); checkoutBranch("refs/heads/master");
MergeResult result = g.merge().include(db.getRef("branch1")) MergeResult result = g.merge()
.setSquash(true).call(); .include(db.exactRef("refs/heads/branch1"))
.setSquash(true)
.call();
assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED, assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED,
result.getMergeStatus()); result.getMergeStatus());

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java

@ -110,7 +110,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
int parentCount) int parentCount)
throws IOException { throws IOException {
assertNotNull(commit); assertNotNull(commit);
Ref stashRef = db.getRef(Constants.R_STASH); Ref stashRef = db.exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(commit, stashRef.getObjectId()); assertEquals(commit, stashRef.getObjectId());
assertNotNull(commit.getAuthorIdent()); assertNotNull(commit.getAuthorIdent());

102
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashDropCommandTest.java

@ -96,13 +96,13 @@ public class StashDropCommandTest extends RepositoryTestCase {
@Test @Test
public void dropWithInvalidLogIndex() throws Exception { public void dropWithInvalidLogIndex() throws Exception {
write(committedFile, "content2"); write(committedFile, "content2");
Ref stashRef = git.getRepository().getRef(Constants.R_STASH); Ref stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef); assertNull(stashRef);
RevCommit stashed = git.stashCreate().call(); RevCommit stashed = git.stashCreate().call();
assertNotNull(stashed); assertNotNull(stashed);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertEquals(stashed, git.getRepository().getRef(Constants.R_STASH) assertEquals(stashed,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
try { try {
assertNull(git.stashDrop().setStashRef(100).call()); assertNull(git.stashDrop().setStashRef(100).call());
fail("Exception not thrown"); fail("Exception not thrown");
@ -115,15 +115,15 @@ public class StashDropCommandTest extends RepositoryTestCase {
@Test @Test
public void dropSingleStashedCommit() throws Exception { public void dropSingleStashedCommit() throws Exception {
write(committedFile, "content2"); write(committedFile, "content2");
Ref stashRef = git.getRepository().getRef(Constants.R_STASH); Ref stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef); assertNull(stashRef);
RevCommit stashed = git.stashCreate().call(); RevCommit stashed = git.stashCreate().call();
assertNotNull(stashed); assertNotNull(stashed);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertEquals(stashed, git.getRepository().getRef(Constants.R_STASH) assertEquals(stashed,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
assertNull(git.stashDrop().call()); assertNull(git.stashDrop().call());
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef); assertNull(stashRef);
ReflogReader reader = git.getRepository().getReflogReader( ReflogReader reader = git.getRepository().getReflogReader(
@ -134,25 +134,25 @@ public class StashDropCommandTest extends RepositoryTestCase {
@Test @Test
public void dropAll() throws Exception { public void dropAll() throws Exception {
write(committedFile, "content2"); write(committedFile, "content2");
Ref stashRef = git.getRepository().getRef(Constants.R_STASH); Ref stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef); assertNull(stashRef);
RevCommit firstStash = git.stashCreate().call(); RevCommit firstStash = git.stashCreate().call();
assertNotNull(firstStash); assertNotNull(firstStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(firstStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
write(committedFile, "content3"); write(committedFile, "content3");
RevCommit secondStash = git.stashCreate().call(); RevCommit secondStash = git.stashCreate().call();
assertNotNull(secondStash); assertNotNull(secondStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(secondStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
assertNull(git.stashDrop().setAll(true).call()); 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( ReflogReader reader = git.getRepository().getReflogReader(
Constants.R_STASH); Constants.R_STASH);
@ -162,25 +162,25 @@ public class StashDropCommandTest extends RepositoryTestCase {
@Test @Test
public void dropFirstStashedCommit() throws Exception { public void dropFirstStashedCommit() throws Exception {
write(committedFile, "content2"); write(committedFile, "content2");
Ref stashRef = git.getRepository().getRef(Constants.R_STASH); Ref stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef); assertNull(stashRef);
RevCommit firstStash = git.stashCreate().call(); RevCommit firstStash = git.stashCreate().call();
assertNotNull(firstStash); assertNotNull(firstStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(firstStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
write(committedFile, "content3"); write(committedFile, "content3");
RevCommit secondStash = git.stashCreate().call(); RevCommit secondStash = git.stashCreate().call();
assertNotNull(secondStash); assertNotNull(secondStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(secondStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
assertEquals(firstStash, git.stashDrop().call()); assertEquals(firstStash, git.stashDrop().call());
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(firstStash, stashRef.getObjectId()); assertEquals(firstStash, stashRef.getObjectId());
@ -196,33 +196,33 @@ public class StashDropCommandTest extends RepositoryTestCase {
@Test @Test
public void dropMiddleStashCommit() throws Exception { public void dropMiddleStashCommit() throws Exception {
write(committedFile, "content2"); write(committedFile, "content2");
Ref stashRef = git.getRepository().getRef(Constants.R_STASH); Ref stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef); assertNull(stashRef);
RevCommit firstStash = git.stashCreate().call(); RevCommit firstStash = git.stashCreate().call();
assertNotNull(firstStash); assertNotNull(firstStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(firstStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
write(committedFile, "content3"); write(committedFile, "content3");
RevCommit secondStash = git.stashCreate().call(); RevCommit secondStash = git.stashCreate().call();
assertNotNull(secondStash); assertNotNull(secondStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(secondStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
write(committedFile, "content4"); write(committedFile, "content4");
RevCommit thirdStash = git.stashCreate().call(); RevCommit thirdStash = git.stashCreate().call();
assertNotNull(thirdStash); assertNotNull(thirdStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(thirdStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(thirdStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
assertEquals(thirdStash, git.stashDrop().setStashRef(1).call()); assertEquals(thirdStash, git.stashDrop().setStashRef(1).call());
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(thirdStash, stashRef.getObjectId()); assertEquals(thirdStash, stashRef.getObjectId());
@ -241,46 +241,46 @@ public class StashDropCommandTest extends RepositoryTestCase {
@Test @Test
public void dropBoundaryStashedCommits() throws Exception { public void dropBoundaryStashedCommits() throws Exception {
write(committedFile, "content2"); write(committedFile, "content2");
Ref stashRef = git.getRepository().getRef(Constants.R_STASH); Ref stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNull(stashRef); assertNull(stashRef);
RevCommit firstStash = git.stashCreate().call(); RevCommit firstStash = git.stashCreate().call();
assertNotNull(firstStash); assertNotNull(firstStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(firstStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(firstStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
write(committedFile, "content3"); write(committedFile, "content3");
RevCommit secondStash = git.stashCreate().call(); RevCommit secondStash = git.stashCreate().call();
assertNotNull(secondStash); assertNotNull(secondStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(secondStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(secondStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
write(committedFile, "content4"); write(committedFile, "content4");
RevCommit thirdStash = git.stashCreate().call(); RevCommit thirdStash = git.stashCreate().call();
assertNotNull(thirdStash); assertNotNull(thirdStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(thirdStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(thirdStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
write(committedFile, "content5"); write(committedFile, "content5");
RevCommit fourthStash = git.stashCreate().call(); RevCommit fourthStash = git.stashCreate().call();
assertNotNull(fourthStash); assertNotNull(fourthStash);
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(fourthStash, git.getRepository().getRef(Constants.R_STASH) assertEquals(fourthStash,
.getObjectId()); git.getRepository().exactRef(Constants.R_STASH).getObjectId());
assertEquals(thirdStash, git.stashDrop().call()); assertEquals(thirdStash, git.stashDrop().call());
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(thirdStash, stashRef.getObjectId()); assertEquals(thirdStash, stashRef.getObjectId());
assertEquals(thirdStash, git.stashDrop().setStashRef(2).call()); assertEquals(thirdStash, git.stashDrop().setStashRef(2).call());
stashRef = git.getRepository().getRef(Constants.R_STASH); stashRef = git.getRepository().exactRef(Constants.R_STASH);
assertNotNull(stashRef); assertNotNull(stashRef);
assertEquals(thirdStash, stashRef.getObjectId()); assertEquals(thirdStash, stashRef.getObjectId());

38
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); tr.lightweightTag("t", a);
gc.packRefs(); gc.packRefs();
assertSame(repo.getRef("t").getStorage(), Storage.PACKED); assertSame(repo.exactRef("refs/tags/t").getStorage(), Storage.PACKED);
} }
@Test @Test
@ -126,8 +126,8 @@ public class GcPackRefsTest extends GcTestCase {
refLock.unlock(); refLock.unlock();
} }
assertSame(repo.getRef("refs/tags/t1").getStorage(), Storage.LOOSE); assertSame(repo.exactRef("refs/tags/t1").getStorage(), Storage.LOOSE);
assertSame(repo.getRef("refs/tags/t2").getStorage(), Storage.PACKED); assertSame(repo.exactRef("refs/tags/t2").getStorage(), Storage.PACKED);
} }
@Test @Test
@ -146,7 +146,7 @@ public class GcPackRefsTest extends GcTestCase {
public Result call() throws Exception { public Result call() throws Exception {
RefUpdate update = new RefDirectoryUpdate( RefUpdate update = new RefDirectoryUpdate(
(RefDirectory) repo.getRefDatabase(), (RefDirectory) repo.getRefDatabase(),
repo.getRef("refs/tags/t")) { repo.exactRef("refs/tags/t")) {
@Override @Override
public boolean isForceUpdate() { public boolean isForceUpdate() {
try { try {
@ -182,7 +182,7 @@ public class GcPackRefsTest extends GcTestCase {
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); pool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
} }
assertEquals(repo.getRef("refs/tags/t").getObjectId(), b); assertEquals(repo.exactRef("refs/tags/t").getObjectId(), b);
} }
@Test @Test
@ -194,23 +194,23 @@ public class GcPackRefsTest extends GcTestCase {
// check for the unborn branch master. HEAD should point to master and // check for the unborn branch master. HEAD should point to master and
// master doesn't exist. // master doesn't exist.
assertEquals(repo.getRef("HEAD").getTarget().getName(), assertEquals(repo.exactRef("HEAD").getTarget().getName(),
"refs/heads/master"); "refs/heads/master");
assertNull(repo.getRef("HEAD").getTarget().getObjectId()); assertNull(repo.exactRef("HEAD").getTarget().getObjectId());
gc.packRefs(); gc.packRefs();
assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE);
assertEquals(repo.getRef("HEAD").getTarget().getName(), assertEquals(repo.exactRef("HEAD").getTarget().getName(),
"refs/heads/master"); "refs/heads/master");
assertNull(repo.getRef("HEAD").getTarget().getObjectId()); assertNull(repo.exactRef("HEAD").getTarget().getObjectId());
git.checkout().setName("refs/heads/side").call(); git.checkout().setName("refs/heads/side").call();
gc.packRefs(); gc.packRefs();
assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE);
// check for detached HEAD // check for detached HEAD
git.checkout().setName(first.getName()).call(); git.checkout().setName(first.getName()).call();
gc.packRefs(); gc.packRefs();
assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE);
} }
@Test @Test
@ -229,20 +229,20 @@ public class GcPackRefsTest extends GcTestCase {
// check for the unborn branch master. HEAD should point to master and // check for the unborn branch master. HEAD should point to master and
// master doesn't exist. // master doesn't exist.
assertEquals(repo.getRef("HEAD").getTarget().getName(), assertEquals(repo.exactRef("HEAD").getTarget().getName(),
"refs/heads/master"); "refs/heads/master");
assertNull(repo.getRef("HEAD").getTarget().getObjectId()); assertNull(repo.exactRef("HEAD").getTarget().getObjectId());
gc.packRefs(); gc.packRefs();
assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE);
assertEquals(repo.getRef("HEAD").getTarget().getName(), assertEquals(repo.exactRef("HEAD").getTarget().getName(),
"refs/heads/master"); "refs/heads/master");
assertNull(repo.getRef("HEAD").getTarget().getObjectId()); assertNull(repo.exactRef("HEAD").getTarget().getObjectId());
// check for non-detached HEAD // check for non-detached HEAD
repo.updateRef(Constants.HEAD).link("refs/heads/side"); repo.updateRef(Constants.HEAD).link("refs/heads/side");
gc.packRefs(); gc.packRefs();
assertSame(repo.getRef("HEAD").getStorage(), Storage.LOOSE); assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE);
assertEquals(repo.getRef("HEAD").getTarget().getObjectId(), assertEquals(repo.exactRef("HEAD").getTarget().getObjectId(),
second.getId()); second.getId());
} }
} }

8
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(); Result update = updateRef.update();
assertEquals(Result.FORCED, update); assertEquals(Result.FORCED, update);
assertEquals(ppid, db.resolve("HEAD")); assertEquals(ppid, db.resolve("HEAD"));
Ref ref = db.getRef("HEAD"); Ref ref = db.exactRef("HEAD");
assertEquals("HEAD", ref.getName()); assertEquals("HEAD", ref.getName());
assertTrue("is detached", !ref.isSymbolic()); assertTrue("is detached", !ref.isSymbolic());
@ -377,7 +377,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
Result update = updateRef.update(); Result update = updateRef.update();
assertEquals(Result.NEW, update); assertEquals(Result.NEW, update);
assertEquals(ppid, db.resolve("HEAD")); assertEquals(ppid, db.resolve("HEAD"));
Ref ref = db.getRef("HEAD"); Ref ref = db.exactRef("HEAD");
assertEquals("HEAD", ref.getName()); assertEquals("HEAD", ref.getName());
assertTrue("is detached", !ref.isSymbolic()); assertTrue("is detached", !ref.isSymbolic());
@ -681,13 +681,13 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
public void testRenameBranchAlsoInPack() throws IOException { public void testRenameBranchAlsoInPack() throws IOException {
ObjectId rb = db.resolve("refs/heads/b"); ObjectId rb = db.resolve("refs/heads/b");
ObjectId rb2 = db.resolve("refs/heads/b~1"); 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"); RefUpdate updateRef = db.updateRef("refs/heads/b");
updateRef.setNewObjectId(rb2); updateRef.setNewObjectId(rb2);
updateRef.setForceUpdate(true); updateRef.setForceUpdate(true);
Result update = updateRef.update(); Result update = updateRef.update();
assertEquals("internal check new ref is loose", Result.FORCED, 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"); writeReflog(db, rb, "Just a message", "refs/heads/b");
assertTrue("log on old branch", new File(db.getDirectory(), assertTrue("log on old branch", new File(db.getDirectory(),
"logs/refs/heads/b").exists()); "logs/refs/heads/b").exists());

40
org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java

@ -127,25 +127,25 @@ public class TestRepositoryTest {
@Test @Test
public void resetFromSymref() throws Exception { public void resetFromSymref() throws Exception {
repo.updateRef("HEAD").link("refs/heads/master"); 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 master = tr.branch("master").commit().create();
RevCommit branch = tr.branch("branch").commit().create(); RevCommit branch = tr.branch("branch").commit().create();
RevCommit detached = tr.commit().create(); RevCommit detached = tr.commit().create();
assertTrue(head.isSymbolic()); assertTrue(head.isSymbolic());
assertEquals("refs/heads/master", head.getTarget().getName()); assertEquals("refs/heads/master", head.getTarget().getName());
assertEquals(master, repo.getRef("refs/heads/master").getObjectId()); assertEquals(master, repo.exactRef("refs/heads/master").getObjectId());
assertEquals(branch, repo.getRef("refs/heads/branch").getObjectId()); assertEquals(branch, repo.exactRef("refs/heads/branch").getObjectId());
// Reset to branches preserves symref. // Reset to branches preserves symref.
tr.reset("master"); tr.reset("master");
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(master, head.getObjectId()); assertEquals(master, head.getObjectId());
assertTrue(head.isSymbolic()); assertTrue(head.isSymbolic());
assertEquals("refs/heads/master", head.getTarget().getName()); assertEquals("refs/heads/master", head.getTarget().getName());
tr.reset("branch"); tr.reset("branch");
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(branch, head.getObjectId()); assertEquals(branch, head.getObjectId());
assertTrue(head.isSymbolic()); assertTrue(head.isSymbolic());
assertEquals("refs/heads/master", head.getTarget().getName()); assertEquals("refs/heads/master", head.getTarget().getName());
@ -153,50 +153,50 @@ public class TestRepositoryTest {
// Reset to a SHA-1 detaches. // Reset to a SHA-1 detaches.
tr.reset(detached); tr.reset(detached);
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(detached, head.getObjectId()); assertEquals(detached, head.getObjectId());
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
tr.reset(detached.name()); tr.reset(detached.name());
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(detached, head.getObjectId()); assertEquals(detached, head.getObjectId());
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
// Reset back to a branch remains detached. // Reset back to a branch remains detached.
tr.reset("master"); tr.reset("master");
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(lastHeadBeforeDetach, head.getObjectId()); assertEquals(lastHeadBeforeDetach, head.getObjectId());
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
} }
@Test @Test
public void resetFromDetachedHead() throws Exception { public void resetFromDetachedHead() throws Exception {
Ref head = repo.getRef("HEAD"); Ref head = repo.exactRef("HEAD");
RevCommit master = tr.branch("master").commit().create(); RevCommit master = tr.branch("master").commit().create();
RevCommit branch = tr.branch("branch").commit().create(); RevCommit branch = tr.branch("branch").commit().create();
RevCommit detached = tr.commit().create(); RevCommit detached = tr.commit().create();
assertNull(head); assertNull(head);
assertEquals(master, repo.getRef("refs/heads/master").getObjectId()); assertEquals(master, repo.exactRef("refs/heads/master").getObjectId());
assertEquals(branch, repo.getRef("refs/heads/branch").getObjectId()); assertEquals(branch, repo.exactRef("refs/heads/branch").getObjectId());
tr.reset("master"); tr.reset("master");
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(master, head.getObjectId()); assertEquals(master, head.getObjectId());
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
tr.reset("branch"); tr.reset("branch");
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(branch, head.getObjectId()); assertEquals(branch, head.getObjectId());
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
tr.reset(detached); tr.reset(detached);
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(detached, head.getObjectId()); assertEquals(detached, head.getObjectId());
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
tr.reset(detached.name()); tr.reset(detached.name());
head = repo.getRef("HEAD"); head = repo.exactRef("HEAD");
assertEquals(detached, head.getObjectId()); assertEquals(detached, head.getObjectId());
assertFalse(head.isSymbolic()); assertFalse(head.isSymbolic());
} }
@ -222,7 +222,7 @@ public class TestRepositoryTest {
.tick(3) .tick(3)
.add("bar", "fixed bar contents") .add("bar", "fixed bar contents")
.create(); .create();
assertEquals(amended, repo.getRef("refs/heads/master").getObjectId()); assertEquals(amended, repo.exactRef("refs/heads/master").getObjectId());
rw.parseBody(amended); rw.parseBody(amended);
assertEquals(1, amended.getParentCount()); assertEquals(1, amended.getParentCount());
@ -257,7 +257,7 @@ public class TestRepositoryTest {
.add("foo", "fixed foo contents") .add("foo", "fixed foo contents")
.create(); .create();
Ref head = repo.getRef(Constants.HEAD); Ref head = repo.exactRef(Constants.HEAD);
assertEquals(amended, head.getObjectId()); assertEquals(amended, head.getObjectId());
assertTrue(head.isSymbolic()); assertTrue(head.isSymbolic());
assertEquals("refs/heads/master", head.getTarget().getName()); assertEquals("refs/heads/master", head.getTarget().getName());
@ -291,7 +291,7 @@ public class TestRepositoryTest {
public void commitToUnbornHead() throws Exception { public void commitToUnbornHead() throws Exception {
repo.updateRef("HEAD").link("refs/heads/master"); repo.updateRef("HEAD").link("refs/heads/master");
RevCommit root = tr.branch("HEAD").commit().create(); RevCommit root = tr.branch("HEAD").commit().create();
Ref ref = repo.getRef(Constants.HEAD); Ref ref = repo.exactRef(Constants.HEAD);
assertEquals(root, ref.getObjectId()); assertEquals(root, ref.getObjectId());
assertTrue(ref.isSymbolic()); assertTrue(ref.isSymbolic());
assertEquals("refs/heads/master", ref.getTarget().getName()); assertEquals("refs/heads/master", ref.getTarget().getName());
@ -316,7 +316,7 @@ public class TestRepositoryTest {
RevCommit result = tr.cherryPick(toPick); RevCommit result = tr.cherryPick(toPick);
rw.parseBody(result); rw.parseBody(result);
Ref headRef = tr.getRepository().getRef("HEAD"); Ref headRef = tr.getRepository().exactRef("HEAD");
assertEquals(result, headRef.getObjectId()); assertEquals(result, headRef.getObjectId());
assertTrue(headRef.isSymbolic()); assertTrue(headRef.isSymbolic());
assertEquals("refs/heads/master", headRef.getLeaf().getName()); assertEquals("refs/heads/master", headRef.getLeaf().getName());
@ -371,7 +371,7 @@ public class TestRepositoryTest {
.create(); .create();
assertNotEquals(head, toPick); assertNotEquals(head, toPick);
assertNull(tr.cherryPick(toPick)); assertNull(tr.cherryPick(toPick));
assertEquals(head, repo.getRef("HEAD").getObjectId()); assertEquals(head, repo.exactRef("HEAD").getObjectId());
} }
private String blobAsString(AnyObjectId treeish, String path) private String blobAsString(AnyObjectId treeish, String path)

24
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java

@ -163,7 +163,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
@Test @Test
public void testReadSymRefToPacked() throws IOException { public void testReadSymRefToPacked() throws IOException {
writeSymref("HEAD", "refs/heads/b"); writeSymref("HEAD", "refs/heads/b");
Ref ref = db.getRef("HEAD"); Ref ref = db.exactRef("HEAD");
assertEquals(Ref.Storage.LOOSE, ref.getStorage()); assertEquals(Ref.Storage.LOOSE, ref.getStorage());
assertTrue("is symref", ref.isSymbolic()); assertTrue("is symref", ref.isSymbolic());
ref = ref.getTarget(); ref = ref.getTarget();
@ -181,7 +181,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertEquals(Result.FORCED, update); // internal assertEquals(Result.FORCED, update); // internal
writeSymref("HEAD", "refs/heads/master"); writeSymref("HEAD", "refs/heads/master");
Ref ref = db.getRef("HEAD"); Ref ref = db.exactRef("HEAD");
assertEquals(Ref.Storage.LOOSE, ref.getStorage()); assertEquals(Ref.Storage.LOOSE, ref.getStorage());
ref = ref.getTarget(); ref = ref.getTarget();
assertEquals("refs/heads/master", ref.getName()); assertEquals("refs/heads/master", ref.getName());
@ -194,13 +194,13 @@ public class RefTest extends SampleDataRepositoryTestCase {
updateRef.setNewObjectId(db.resolve("refs/heads/master")); updateRef.setNewObjectId(db.resolve("refs/heads/master"));
Result update = updateRef.update(); Result update = updateRef.update();
assertEquals(Result.NEW, update); assertEquals(Result.NEW, update);
Ref ref = db.getRef("ref/heads/new"); Ref ref = db.exactRef("ref/heads/new");
assertEquals(Storage.LOOSE, ref.getStorage()); assertEquals(Storage.LOOSE, ref.getStorage());
} }
@Test @Test
public void testGetShortRef() throws IOException { public void testGetShortRef() throws IOException {
Ref ref = db.getRef("master"); Ref ref = db.exactRef("refs/heads/master");
assertEquals("refs/heads/master", ref.getName()); assertEquals("refs/heads/master", ref.getName());
assertEquals(db.resolve("refs/heads/master"), ref.getObjectId()); assertEquals(db.resolve("refs/heads/master"), ref.getObjectId());
} }
@ -222,7 +222,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertNull(db.getRefDatabase().exactRef("refs/foo/bar")); 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("refs/heads/refs/foo/bar", ref.getName());
assertEquals(db.resolve("refs/heads/master"), ref.getObjectId()); assertEquals(db.resolve("refs/heads/master"), ref.getObjectId());
} }
@ -237,7 +237,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertEquals("refs/foo/bar", exactRef.getName()); assertEquals("refs/foo/bar", exactRef.getName());
assertEquals(masterId, exactRef.getObjectId()); 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("refs/foo/bar", ref.getName());
assertEquals(masterId, ref.getObjectId()); assertEquals(masterId, ref.getObjectId());
} }
@ -251,7 +251,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
@Test @Test
public void testReadLoosePackedRef() throws IOException, public void testReadLoosePackedRef() throws IOException,
InterruptedException { InterruptedException {
Ref ref = db.getRef("refs/heads/master"); Ref ref = db.exactRef("refs/heads/master");
assertEquals(Storage.PACKED, ref.getStorage()); assertEquals(Storage.PACKED, ref.getStorage());
FileOutputStream os = new FileOutputStream(new File(db.getDirectory(), FileOutputStream os = new FileOutputStream(new File(db.getDirectory(),
"refs/heads/master")); "refs/heads/master"));
@ -259,7 +259,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
os.write('\n'); os.write('\n');
os.close(); os.close();
ref = db.getRef("refs/heads/master"); ref = db.exactRef("refs/heads/master");
assertEquals(Storage.LOOSE, ref.getStorage()); assertEquals(Storage.LOOSE, ref.getStorage());
} }
@ -271,7 +271,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
*/ */
@Test @Test
public void testReadSimplePackedRefSameRepo() throws IOException { 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^"); ObjectId pid = db.resolve("refs/heads/master^");
assertEquals(Storage.PACKED, ref.getStorage()); assertEquals(Storage.PACKED, ref.getStorage());
RefUpdate updateRef = db.updateRef("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master");
@ -280,19 +280,19 @@ public class RefTest extends SampleDataRepositoryTestCase {
Result update = updateRef.update(); Result update = updateRef.update();
assertEquals(Result.FORCED, update); assertEquals(Result.FORCED, update);
ref = db.getRef("refs/heads/master"); ref = db.exactRef("refs/heads/master");
assertEquals(Storage.LOOSE, ref.getStorage()); assertEquals(Storage.LOOSE, ref.getStorage());
} }
@Test @Test
public void testResolvedNamesBranch() throws IOException { public void testResolvedNamesBranch() throws IOException {
Ref ref = db.getRef("a"); Ref ref = db.findRef("a");
assertEquals("refs/heads/a", ref.getName()); assertEquals("refs/heads/a", ref.getName());
} }
@Test @Test
public void testResolvedSymRef() throws IOException { public void testResolvedSymRef() throws IOException {
Ref ref = db.getRef(Constants.HEAD); Ref ref = db.exactRef(Constants.HEAD);
assertEquals(Constants.HEAD, ref.getName()); assertEquals(Constants.HEAD, ref.getName());
assertTrue("is symbolic ref", ref.isSymbolic()); assertTrue("is symbolic ref", ref.isSymbolic());
assertSame(Ref.Storage.LOOSE, ref.getStorage()); assertSame(Ref.Storage.LOOSE, ref.getStorage());

48
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeMessageFormatterTest.java

@ -84,44 +84,44 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
@Test @Test
public void testOneBranch() throws IOException { public void testOneBranch() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.exactRef("refs/heads/a");
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
String message = formatter.format(Arrays.asList(a), master); String message = formatter.format(Arrays.asList(a), master);
assertEquals("Merge branch 'a'", message); assertEquals("Merge branch 'a'", message);
} }
@Test @Test
public void testTwoBranches() throws IOException { public void testTwoBranches() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.exactRef("refs/heads/a");
Ref b = db.getRef("refs/heads/b"); Ref b = db.exactRef("refs/heads/b");
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
String message = formatter.format(Arrays.asList(a, b), master); String message = formatter.format(Arrays.asList(a, b), master);
assertEquals("Merge branches 'a' and 'b'", message); assertEquals("Merge branches 'a' and 'b'", message);
} }
@Test @Test
public void testThreeBranches() throws IOException { public void testThreeBranches() throws IOException {
Ref c = db.getRef("refs/heads/c"); Ref c = db.exactRef("refs/heads/c");
Ref b = db.getRef("refs/heads/b"); Ref b = db.exactRef("refs/heads/b");
Ref a = db.getRef("refs/heads/a"); Ref a = db.exactRef("refs/heads/a");
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
String message = formatter.format(Arrays.asList(c, b, a), master); String message = formatter.format(Arrays.asList(c, b, a), master);
assertEquals("Merge branches 'c', 'b' and 'a'", message); assertEquals("Merge branches 'c', 'b' and 'a'", message);
} }
@Test @Test
public void testRemoteBranch() throws Exception { public void testRemoteBranch() throws Exception {
Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); Ref remoteA = db.exactRef("refs/remotes/origin/remote-a");
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
String message = formatter.format(Arrays.asList(remoteA), master); String message = formatter.format(Arrays.asList(remoteA), master);
assertEquals("Merge remote-tracking branch 'origin/remote-a'", message); assertEquals("Merge remote-tracking branch 'origin/remote-a'", message);
} }
@Test @Test
public void testMixed() throws IOException { public void testMixed() throws IOException {
Ref c = db.getRef("refs/heads/c"); Ref c = db.exactRef("refs/heads/c");
Ref remoteA = db.getRef("refs/remotes/origin/remote-a"); Ref remoteA = db.exactRef("refs/remotes/origin/remote-a");
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
String message = formatter.format(Arrays.asList(c, remoteA), master); String message = formatter.format(Arrays.asList(c, remoteA), master);
assertEquals("Merge branch 'c', remote-tracking branch 'origin/remote-a'", assertEquals("Merge branch 'c', remote-tracking branch 'origin/remote-a'",
message); message);
@ -129,8 +129,8 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
@Test @Test
public void testTag() throws IOException { public void testTag() throws IOException {
Ref tagA = db.getRef("refs/tags/A"); Ref tagA = db.exactRef("refs/tags/A");
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
String message = formatter.format(Arrays.asList(tagA), master); String message = formatter.format(Arrays.asList(tagA), master);
assertEquals("Merge tag 'A'", message); assertEquals("Merge tag 'A'", message);
} }
@ -141,7 +141,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
.fromString("6db9c2ebf75590eef973081736730a9ea169a0c4"); .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4");
Ref commit = new ObjectIdRef.Unpeeled(Storage.LOOSE, Ref commit = new ObjectIdRef.Unpeeled(Storage.LOOSE,
objectId.getName(), objectId); 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); String message = formatter.format(Arrays.asList(commit), master);
assertEquals("Merge commit '6db9c2ebf75590eef973081736730a9ea169a0c4'", assertEquals("Merge commit '6db9c2ebf75590eef973081736730a9ea169a0c4'",
message); message);
@ -154,7 +154,7 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
.fromString("6db9c2ebf75590eef973081736730a9ea169a0c4"); .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4");
Ref remoteBranch = new ObjectIdRef.Unpeeled(Storage.LOOSE, name, Ref remoteBranch = new ObjectIdRef.Unpeeled(Storage.LOOSE, name,
objectId); objectId);
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
String message = formatter.format(Arrays.asList(remoteBranch), master); String message = formatter.format(Arrays.asList(remoteBranch), master);
assertEquals("Merge branch 'test' of http://egit.eclipse.org/jgit.git", assertEquals("Merge branch 'test' of http://egit.eclipse.org/jgit.git",
message); message);
@ -162,16 +162,16 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
@Test @Test
public void testIntoOtherThanMaster() throws IOException { public void testIntoOtherThanMaster() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.exactRef("refs/heads/a");
Ref b = db.getRef("refs/heads/b"); Ref b = db.exactRef("refs/heads/b");
String message = formatter.format(Arrays.asList(a), b); String message = formatter.format(Arrays.asList(a), b);
assertEquals("Merge branch 'a' into b", message); assertEquals("Merge branch 'a' into b", message);
} }
@Test @Test
public void testIntoHeadOtherThanMaster() throws IOException { public void testIntoHeadOtherThanMaster() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.exactRef("refs/heads/a");
Ref b = db.getRef("refs/heads/b"); Ref b = db.exactRef("refs/heads/b");
SymbolicRef head = new SymbolicRef("HEAD", b); SymbolicRef head = new SymbolicRef("HEAD", b);
String message = formatter.format(Arrays.asList(a), head); String message = formatter.format(Arrays.asList(a), head);
assertEquals("Merge branch 'a' into b", message); assertEquals("Merge branch 'a' into b", message);
@ -179,8 +179,8 @@ public class MergeMessageFormatterTest extends SampleDataRepositoryTestCase {
@Test @Test
public void testIntoSymbolicRefHeadPointingToMaster() throws IOException { public void testIntoSymbolicRefHeadPointingToMaster() throws IOException {
Ref a = db.getRef("refs/heads/a"); Ref a = db.exactRef("refs/heads/a");
Ref master = db.getRef("refs/heads/master"); Ref master = db.exactRef("refs/heads/master");
SymbolicRef head = new SymbolicRef("HEAD", master); SymbolicRef head = new SymbolicRef("HEAD", master);
String message = formatter.format(Arrays.asList(a), head); String message = formatter.format(Arrays.asList(a), head);
assertEquals("Merge branch 'a'", message); assertEquals("Merge branch 'a'", message);

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java

@ -630,7 +630,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
// ResolveMerge // ResolveMerge
try { try {
MergeResult mergeResult = git.merge().setStrategy(strategy) MergeResult mergeResult = git.merge().setStrategy(strategy)
.include(git.getRepository().getRef("refs/heads/side")) .include(git.getRepository().exactRef("refs/heads/side"))
.call(); .call();
assertEquals(MergeStrategy.RECURSIVE, strategy); assertEquals(MergeStrategy.RECURSIVE, strategy);
assertEquals(MergeResult.MergeStatus.MERGED, assertEquals(MergeResult.MergeStatus.MERGED,

2
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); Git git = new Git(db);
revCommit = git.commit().setMessage("squash_me").call(); 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); String message = msgFormatter.format(Arrays.asList(revCommit), master);
assertEquals( assertEquals(
"Squashed commit of the following:\n\ncommit " "Squashed commit of the following:\n\ncommit "

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java

@ -125,7 +125,7 @@ public class TestProtocolTest {
.setRefSpecs(HEADS) .setRefSpecs(HEADS)
.call(); .call();
assertEquals(master, assertEquals(master,
local.getRepository().getRef("master").getObjectId()); local.getRepository().exactRef("refs/heads/master").getObjectId());
} }
} }
@ -142,7 +142,7 @@ public class TestProtocolTest {
.setRefSpecs(HEADS) .setRefSpecs(HEADS)
.call(); .call();
assertEquals(master, assertEquals(master,
remote.getRepository().getRef("master").getObjectId()); remote.getRepository().exactRef("refs/heads/master").getObjectId());
} }
} }
@ -177,7 +177,7 @@ public class TestProtocolTest {
// Expected. // Expected.
} }
assertEquals(1, rejected.get()); assertEquals(1, rejected.get());
assertNull(local.getRepository().getRef("master")); assertNull(local.getRepository().exactRef("refs/heads/master"));
git.fetch() git.fetch()
.setRemote(user2Uri.toString()) .setRemote(user2Uri.toString())
@ -185,7 +185,7 @@ public class TestProtocolTest {
.call(); .call();
assertEquals(1, rejected.get()); assertEquals(1, rejected.get());
assertEquals(master, assertEquals(master,
local.getRepository().getRef("master").getObjectId()); local.getRepository().exactRef("refs/heads/master").getObjectId());
} }
} }
@ -222,7 +222,7 @@ public class TestProtocolTest {
JGitText.get().pushNotPermitted)); JGitText.get().pushNotPermitted));
} }
assertEquals(1, rejected.get()); assertEquals(1, rejected.get());
assertNull(remote.getRepository().getRef("master")); assertNull(remote.getRepository().exactRef("refs/heads/master"));
git.push() git.push()
.setRemote(user2Uri.toString()) .setRemote(user2Uri.toString())
@ -230,7 +230,7 @@ public class TestProtocolTest {
.call(); .call();
assertEquals(1, rejected.get()); assertEquals(1, rejected.get());
assertEquals(master, assertEquals(master,
remote.getRepository().getRef("master").getObjectId()); remote.getRepository().exactRef("refs/heads/master").getObjectId());
} }
} }

35
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. * "refs/heads/master" if "refs/heads/master" already exists.
* @return the Ref with the given name, or {@code null} if it does not exist * @return the Ref with the given name, or {@code null} if it does not exist
* @throws IOException * @throws IOException
* @deprecated Use {@link #exactRef(String)} or {@link #findRef(String)}
* instead.
*/ */
@Deprecated
@Nullable @Nullable
public Ref getRef(final String name) throws IOException { 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); return getRefDatabase().getRef(name);
} }

Loading…
Cancel
Save