.call();
// Clone it
File directory = createTempDirectory("testBareRepo");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository()
+ .setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The .gitmodules file should exist
- File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
- assertTrue("The .gitmodules file should exist", gitmodules.exists());
- FileBasedConfig c = new FileBasedConfig(gitmodules, FS.DETECTED);
- c.load();
- assertEquals("standard branches work", "master",
- c.getString("submodule", "with-branch", "branch"));
- assertEquals("long branches work", "refs/heads/master",
- c.getString("submodule", "with-long-branch", "branch"));
+ .getRepository();) {
+ // The .gitmodules file should exist
+ File gitmodules = new File(localDb.getWorkTree(),
+ ".gitmodules");
+ assertTrue("The .gitmodules file should exist",
+ gitmodules.exists());
+ FileBasedConfig c = new FileBasedConfig(gitmodules,
+ FS.DETECTED);
+ c.load();
+ assertEquals("standard branches work", "master",
+ c.getString("submodule", "with-branch", "branch"));
+ assertEquals("long branches work", "refs/heads/master",
+ c.getString("submodule", "with-long-branch", "branch"));
+ }
}
}
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.SystemReader;
import org.junit.Test;
/**
@Test
public void testTrailingSpaces() throws IOException {
+ // Windows can't create files with trailing spaces
+ // If this assumption fails the test is halted and ignored.
+ org.junit.Assume.assumeFalse(SystemReader.getInstance().isWindows());
writeTrashFile("a /a", "");
writeTrashFile("a /a ", "");
writeTrashFile("a /a ", "");
fail("expected commit-msg hook to abort commit");
} catch (AbortedByHookException e) {
assertEquals("unexpected error message from commit-msg hook",
- "Rejected by \"commit-msg\" hook.\nstderr\n",
+ "Rejected by \"commit-msg\" hook.\nstderr"
+ + System.lineSeparator(),
e.getMessage());
- assertEquals("unexpected output from commit-msg hook", "test\n",
+ assertEquals("unexpected output from commit-msg hook",
+ "test" + System.lineSeparator(),
out.toString());
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
git.commit().setMessage("commit")
.setHookOutputStream(new PrintStream(out)).call();
- assertEquals(".git/COMMIT_EDITMSG\n", out.toString("UTF-8"));
+ assertEquals(".git/COMMIT_EDITMSG" + System.lineSeparator(),
+ out.toString("UTF-8"));
}
@Test
new String[] {
"arg1", "arg2" },
new PrintStream(out), new PrintStream(err), "stdin");
- assertEquals("unexpected hook output", "test arg1 arg2\nstdin\n",
+ assertEquals("unexpected hook output", "test arg1 arg2"
+ + System.lineSeparator() + "stdin" + System.lineSeparator(),
out.toString("UTF-8"));
- assertEquals("unexpected output on stderr stream", "stderr\n",
+ assertEquals("unexpected output on stderr stream",
+ "stderr" + System.lineSeparator(),
err.toString("UTF-8"));
assertEquals("unexpected exit code", 0, res.getExitCode());
assertEquals("unexpected process status", ProcessResult.Status.OK,
fail("expected pre-commit hook to abort commit");
} catch (AbortedByHookException e) {
assertEquals("unexpected error message from pre-commit hook",
- "Rejected by \"pre-commit\" hook.\nstderr\n",
+ "Rejected by \"pre-commit\" hook.\nstderr"
+ + System.lineSeparator(),
e.getMessage());
- assertEquals("unexpected output from pre-commit hook", "test\n",
+ assertEquals("unexpected output from pre-commit hook",
+ "test" + System.lineSeparator(),
out.toString());
}
}