Browse Source

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>
stable-4.2
David Pursehouse 9 years ago committed by Matthias Sohn
parent
commit
78b3f174f2
  1. 66
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java

66
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 { private Git setUpRepoWithRemote() throws Exception {
Repository remoteRepository = createWorkRepository(); Repository remoteRepository = createWorkRepository();
Git remoteGit = new Git(remoteRepository); try (Git remoteGit = new Git(remoteRepository)) {
// commit something // commit something
writeTrashFile("Test.txt", "Hello world"); writeTrashFile("Test.txt", "Hello world");
remoteGit.add().addFilepattern("Test.txt").call(); remoteGit.add().addFilepattern("Test.txt").call();
initialCommit = remoteGit.commit().setMessage("Initial commit").call(); initialCommit = remoteGit.commit().setMessage("Initial commit").call();
writeTrashFile("Test.txt", "Some change"); writeTrashFile("Test.txt", "Some change");
remoteGit.add().addFilepattern("Test.txt").call(); remoteGit.add().addFilepattern("Test.txt").call();
secondCommit = remoteGit.commit().setMessage("Second commit").call(); secondCommit = remoteGit.commit().setMessage("Second commit").call();
// create a master branch // create a master branch
RefUpdate rup = remoteRepository.updateRef("refs/heads/master"); RefUpdate rup = remoteRepository.updateRef("refs/heads/master");
rup.setNewObjectId(initialCommit.getId()); rup.setNewObjectId(initialCommit.getId());
rup.forceUpdate(); rup.forceUpdate();
Repository localRepository = createWorkRepository(); Repository localRepository = createWorkRepository();
Git localGit = new Git(localRepository); Git localGit = new Git(localRepository);
StoredConfig config = localRepository.getConfig(); StoredConfig config = localRepository.getConfig();
RemoteConfig rc = new RemoteConfig(config, "origin"); RemoteConfig rc = new RemoteConfig(config, "origin");
rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath())); rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath()));
rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
rc.update(config); rc.update(config);
config.save(); config.save();
FetchResult res = localGit.fetch().setRemote("origin").call(); FetchResult res = localGit.fetch().setRemote("origin").call();
assertFalse(res.getTrackingRefUpdates().isEmpty()); assertFalse(res.getTrackingRefUpdates().isEmpty());
rup = localRepository.updateRef("refs/heads/master"); rup = localRepository.updateRef("refs/heads/master");
rup.setNewObjectId(initialCommit.getId()); rup.setNewObjectId(initialCommit.getId());
rup.forceUpdate(); rup.forceUpdate();
rup = localRepository.updateRef(Constants.HEAD); rup = localRepository.updateRef(Constants.HEAD);
rup.link("refs/heads/master"); rup.link("refs/heads/master");
rup.setNewObjectId(initialCommit.getId()); rup.setNewObjectId(initialCommit.getId());
rup.update(); rup.update();
return localGit; return localGit;
}
} }
@Test @Test
@ -192,8 +193,7 @@ public class BranchCommandTest extends RepositoryTestCase {
@Test @Test
public void testListAllBranchesShouldNotDie() throws Exception { public void testListAllBranchesShouldNotDie() throws Exception {
Git git = setUpRepoWithRemote(); setUpRepoWithRemote().branchList().setListMode(ListMode.ALL).call();
git.branchList().setListMode(ListMode.ALL).call();
} }
@Test @Test

Loading…
Cancel
Save