CherryPickCommandTest: Create Git instances in try-with-resource

Change-Id: I9d49258bdf12f3221013c37cfb8a21ea27f28860
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
David Pursehouse 2016-01-21 18:07:54 +09:00
parent 1257cfc262
commit 776030f198
1 changed files with 182 additions and 176 deletions

View File

@ -88,8 +88,7 @@ public void testCherryPickNoCommit() throws IOException,
private void doTestCherryPick(boolean noCommit) throws IOException,
JGitInternalException,
GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "first line\nsec. line\nthird line\n");
git.add().addFilepattern("a").call();
RevCommit firstCommit = git.commit().setMessage("create a").call();
@ -128,12 +127,12 @@ private void doTestCherryPick(boolean noCommit) throws IOException,
assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext());
}
}
@Test
public void testSequentialCherryPick() throws IOException, JGitInternalException,
GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "first line\nsec. line\nthird line\n");
git.add().addFilepattern("a").call();
RevCommit firstCommit = git.commit().setMessage("create a").call();
@ -164,10 +163,11 @@ public void testSequentialCherryPick() throws IOException, JGitInternalException
assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext());
}
}
@Test
public void testCherryPickDirtyIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareCherryPick(git);
// modify and add file a
@ -178,10 +178,11 @@ public void testCherryPickDirtyIndex() throws Exception {
doCherryPickAndCheckResult(git, sideCommit,
MergeFailureReason.DIRTY_INDEX);
}
}
@Test
public void testCherryPickDirtyWorktree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareCherryPick(git);
// modify file a
@ -191,10 +192,11 @@ public void testCherryPickDirtyWorktree() throws Exception {
doCherryPickAndCheckResult(git, sideCommit,
MergeFailureReason.DIRTY_WORKTREE);
}
}
@Test
public void testCherryPickConflictResolution() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareCherryPick(git);
CherryPickResult result = git.cherryPick().include(sideCommit.getId())
@ -219,6 +221,7 @@ public void testCherryPickConflictResolution() throws Exception {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
}
@Test
public void testCherryPickConflictResolutionNoCOmmit() throws Exception {
@ -251,8 +254,7 @@ public void testCherryPickConflictResolutionNoCOmmit() throws Exception {
@Test
public void testCherryPickConflictReset() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareCherryPick(git);
CherryPickResult result = git.cherryPick().include(sideCommit.getId())
@ -269,11 +271,12 @@ public void testCherryPickConflictReset() throws Exception {
assertFalse(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD)
.exists());
}
}
@Test
public void testCherryPickOverExecutableChangeOnNonExectuableFileSystem()
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File file = writeTrashFile("test.txt", "a");
assertNotNull(git.add().addFilepattern("test.txt").call());
assertNotNull(git.commit().setMessage("commit1").call());
@ -305,10 +308,11 @@ public void testCherryPickOverExecutableChangeOnNonExectuableFileSystem()
assertNotNull(result);
assertEquals(CherryPickStatus.OK, result.getStatus());
}
}
@Test
public void testCherryPickConflictMarkers() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareCherryPick(git);
CherryPickResult result = git.cherryPick().include(sideCommit.getId())
@ -318,10 +322,11 @@ public void testCherryPickConflictMarkers() throws Exception {
String expected = "<<<<<<< master\na(master)\n=======\na(side)\n>>>>>>> 527460a side\n";
checkFile(new File(db.getWorkTree(), "a"), expected);
}
}
@Test
public void testCherryPickOurCommitName() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareCherryPick(git);
CherryPickResult result = git.cherryPick().include(sideCommit.getId())
@ -331,6 +336,7 @@ public void testCherryPickOurCommitName() throws Exception {
String expected = "<<<<<<< custom name\na(master)\n=======\na(side)\n>>>>>>> 527460a side\n";
checkFile(new File(db.getWorkTree(), "a"), expected);
}
}
private RevCommit prepareCherryPick(final Git git) throws Exception {
// create, add and commit file a
@ -399,8 +405,7 @@ private void doCherryPickAndCheckResult(final Git git,
*/
@Test
public void testCherryPickMerge() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
commitFile("file", "1\n2\n3\n", "master");
commitFile("file", "1\n2\n3\n", "side");
checkoutBranch("refs/heads/side");
@ -438,4 +443,5 @@ public void testCherryPickMerge() throws Exception {
assertEquals(CherryPickStatus.OK, result2.getStatus());
checkFile(new File(db.getWorkTree(), "file"), "a\n2\n3\n");
}
}
}