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 /org.eclipse.jgit.pgm.test/tst | |
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>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst')
3 files changed, 9 insertions, 7 deletions
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(); } |