* if the repository can't be created
* @return the newly created {@code Git} object with associated repository
*/
public Git call() throws JGitInternalException {
try {
RepositoryBuilder builder = new RepositoryBuilder();
if (bare)
builder.setBare();
builder.readEnvironment();
if (directory != null) {
File d = directory;
if (!bare)
d = new File(d, Constants.DOT_GIT);
builder.setGitDir(d);
} else if (builder.getGitDir() == null) {
File d = new File(".");
if (d.getParentFile() != null)
d = d.getParentFile();
if (!bare)
d = new File(d, Constants.DOT_GIT);
builder.setGitDir(d);
}
Repository repository = builder.build();
if (!repository.getObjectDatabase().exists())
repository.create(bare);
return new Git(repository);
} catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e);