aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-01-14 17:53:28 +0900
committerMatthias Sohn <matthias.sohn@sap.com>2016-01-19 17:27:46 +0100
commit78b3f174f21102bb8e36d3a2d16a2956a3265045 (patch)
tree81af7268f1ed7c506d95cfe2762754bb2257bcee /org.eclipse.jgit.test
parent7f84e40f31c692df57c75719bb1733dbb8d0eb40 (diff)
downloadjgit-78b3f174f21102bb8e36d3a2d16a2956a3265045.tar.gz
jgit-78b3f174f21102bb8e36d3a2d16a2956a3265045.zip
BranchCommandTest: Create Git instances in try-with-resource
Also remove a local variable in one of the tests that was hiding a member variable with the same name. Change-Id: Ia4d94cdbf2d83d8be2645f0a93d8891d01606c59 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java66
1 files changed, 33 insertions, 33 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
index 910a645e2b..2fe40b99ed 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
@@ -104,37 +104,38 @@ public class BranchCommandTest extends RepositoryTestCase {
private Git setUpRepoWithRemote() throws Exception {
Repository remoteRepository = createWorkRepository();
- Git remoteGit = new Git(remoteRepository);
- // commit something
- writeTrashFile("Test.txt", "Hello world");
- remoteGit.add().addFilepattern("Test.txt").call();
- initialCommit = remoteGit.commit().setMessage("Initial commit").call();
- writeTrashFile("Test.txt", "Some change");
- remoteGit.add().addFilepattern("Test.txt").call();
- secondCommit = remoteGit.commit().setMessage("Second commit").call();
- // create a master branch
- RefUpdate rup = remoteRepository.updateRef("refs/heads/master");
- rup.setNewObjectId(initialCommit.getId());
- rup.forceUpdate();
-
- Repository localRepository = createWorkRepository();
- Git localGit = new Git(localRepository);
- StoredConfig config = localRepository.getConfig();
- RemoteConfig rc = new RemoteConfig(config, "origin");
- rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath()));
- rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
- rc.update(config);
- config.save();
- FetchResult res = localGit.fetch().setRemote("origin").call();
- assertFalse(res.getTrackingRefUpdates().isEmpty());
- rup = localRepository.updateRef("refs/heads/master");
- rup.setNewObjectId(initialCommit.getId());
- rup.forceUpdate();
- rup = localRepository.updateRef(Constants.HEAD);
- rup.link("refs/heads/master");
- rup.setNewObjectId(initialCommit.getId());
- rup.update();
- return localGit;
+ try (Git remoteGit = new Git(remoteRepository)) {
+ // commit something
+ writeTrashFile("Test.txt", "Hello world");
+ remoteGit.add().addFilepattern("Test.txt").call();
+ initialCommit = remoteGit.commit().setMessage("Initial commit").call();
+ writeTrashFile("Test.txt", "Some change");
+ remoteGit.add().addFilepattern("Test.txt").call();
+ secondCommit = remoteGit.commit().setMessage("Second commit").call();
+ // create a master branch
+ RefUpdate rup = remoteRepository.updateRef("refs/heads/master");
+ rup.setNewObjectId(initialCommit.getId());
+ rup.forceUpdate();
+
+ Repository localRepository = createWorkRepository();
+ Git localGit = new Git(localRepository);
+ StoredConfig config = localRepository.getConfig();
+ RemoteConfig rc = new RemoteConfig(config, "origin");
+ rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath()));
+ rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
+ rc.update(config);
+ config.save();
+ FetchResult res = localGit.fetch().setRemote("origin").call();
+ assertFalse(res.getTrackingRefUpdates().isEmpty());
+ rup = localRepository.updateRef("refs/heads/master");
+ rup.setNewObjectId(initialCommit.getId());
+ rup.forceUpdate();
+ rup = localRepository.updateRef(Constants.HEAD);
+ rup.link("refs/heads/master");
+ rup.setNewObjectId(initialCommit.getId());
+ rup.update();
+ return localGit;
+ }
}
@Test
@@ -192,8 +193,7 @@ public class BranchCommandTest extends RepositoryTestCase {
@Test
public void testListAllBranchesShouldNotDie() throws Exception {
- Git git = setUpRepoWithRemote();
- git.branchList().setListMode(ListMode.ALL).call();
+ setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call();
}
@Test