RevertCommandTest: Open Git in try-with-resource
Change-Id: I659adbb0a6f741c4c6f615c8a24b4603c3f6681e Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
d882bf8c4d
commit
895510fc48
|
@ -74,8 +74,7 @@ public class RevertCommandTest extends RepositoryTestCase {
|
|||
@Test
|
||||
public void testRevert() 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();
|
||||
git.commit().setMessage("create a").call();
|
||||
|
@ -122,14 +121,14 @@ public void testRevert() throws IOException, JGitInternalException,
|
|||
reader = db.getReflogReader(db.getBranch());
|
||||
assertTrue(reader.getLastEntry().getComment()
|
||||
.startsWith("revert: Revert \""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertMultiple() throws IOException, JGitInternalException,
|
||||
GitAPIException {
|
||||
Git git = new Git(db);
|
||||
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("a", "first\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
git.commit().setMessage("add first").call();
|
||||
|
@ -169,14 +168,14 @@ public void testRevertMultiple() throws IOException, JGitInternalException,
|
|||
reader = db.getReflogReader(db.getBranch());
|
||||
assertTrue(reader.getLastEntry().getComment()
|
||||
.startsWith("revert: Revert \""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertMultipleWithFail() throws IOException,
|
||||
JGitInternalException, GitAPIException {
|
||||
Git git = new Git(db);
|
||||
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("a", "first\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
git.commit().setMessage("add first").call();
|
||||
|
@ -220,12 +219,13 @@ public void testRevertMultipleWithFail() throws IOException,
|
|||
reader = db.getReflogReader(db.getBranch());
|
||||
assertTrue(reader.getLastEntry().getComment()
|
||||
.startsWith("revert: Revert \""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertDirtyIndex() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
RevCommit sideCommit = prepareRevert(git);
|
||||
|
||||
// modify and add file a
|
||||
|
@ -236,10 +236,11 @@ public void testRevertDirtyIndex() throws Exception {
|
|||
doRevertAndCheckResult(git, sideCommit,
|
||||
MergeFailureReason.DIRTY_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertDirtyWorktree() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
RevCommit sideCommit = prepareRevert(git);
|
||||
|
||||
// modify file a
|
||||
|
@ -249,10 +250,11 @@ public void testRevertDirtyWorktree() throws Exception {
|
|||
doRevertAndCheckResult(git, sideCommit,
|
||||
MergeFailureReason.DIRTY_WORKTREE);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertConflictResolution() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
RevCommit sideCommit = prepareRevert(git);
|
||||
|
||||
RevertCommand revert = git.revert();
|
||||
|
@ -281,11 +283,11 @@ public void testRevertConflictResolution() throws Exception {
|
|||
|
||||
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertkConflictReset() throws Exception {
|
||||
Git git = new Git(db);
|
||||
|
||||
try (Git git = new Git(db)) {
|
||||
RevCommit sideCommit = prepareRevert(git);
|
||||
|
||||
RevertCommand revert = git.revert();
|
||||
|
@ -304,11 +306,12 @@ public void testRevertkConflictReset() throws Exception {
|
|||
assertFalse(new File(db.getDirectory(), Constants.REVERT_HEAD)
|
||||
.exists());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertOverExecutableChangeOnNonExectuableFileSystem()
|
||||
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());
|
||||
|
@ -340,10 +343,11 @@ public void testRevertOverExecutableChangeOnNonExectuableFileSystem()
|
|||
RevCommit newHead = revert.include(commit2).call();
|
||||
assertNotNull(newHead);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertConflictMarkers() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
RevCommit sideCommit = prepareRevert(git);
|
||||
|
||||
RevertCommand revert = git.revert();
|
||||
|
@ -356,10 +360,11 @@ public void testRevertConflictMarkers() throws Exception {
|
|||
String expected = "<<<<<<< master\na(latest)\n=======\na\n>>>>>>> ca96c31 second master\n";
|
||||
checkFile(new File(db.getWorkTree(), "a"), expected);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevertOurCommitName() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
RevCommit sideCommit = prepareRevert(git);
|
||||
|
||||
RevertCommand revert = git.revert();
|
||||
|
@ -372,6 +377,7 @@ public void testRevertOurCommitName() throws Exception {
|
|||
String expected = "<<<<<<< custom name\na(latest)\n=======\na\n>>>>>>> ca96c31 second master\n";
|
||||
checkFile(new File(db.getWorkTree(), "a"), expected);
|
||||
}
|
||||
}
|
||||
|
||||
private RevCommit prepareRevert(final Git git) throws Exception {
|
||||
// create, add and commit file a
|
||||
|
|
Loading…
Reference in New Issue