*
* @throws IOException
* in case of IO problem
*/
public void create(boolean bare) throws IOException {
final FileBasedConfig cfg = getConfig();
if (cfg.getFile().exists()) {
throw new IllegalStateException(MessageFormat.format(
JGitText.get().repositoryAlreadyExists, getDirectory()));
}
FileUtils.mkdirs(getDirectory(), true);
HideDotFiles hideDotFiles = getConfig().getEnum(
ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_HIDEDOTFILES,
HideDotFiles.DOTGITONLY);
if (hideDotFiles != HideDotFiles.FALSE && !isBare())
getFS().setHidden(getDirectory(), true);
refs.create();
objectDatabase.create();
FileUtils.mkdir(new File(getDirectory(), "branches")); //$NON-NLS-1$
FileUtils.mkdir(new File(getDirectory(), "hooks")); //$NON-NLS-1$
RefUpdate head = updateRef(Constants.HEAD);
head.disableRefLog();
head.link(Constants.R_HEADS + Constants.MASTER);
final boolean fileMode;
if (getFS().supportsExecute()) {
File tmp = File.createTempFile("try", "execute", getDirectory()); //$NON-NLS-1$ //$NON-NLS-2$
getFS().setExecute(tmp, true);
final boolean on = getFS().canExecute(tmp);
getFS().setExecute(tmp, false);
final boolean off = getFS().canExecute(tmp);
FileUtils.delete(tmp);
fileMode = on && !off;
} else {
fileMode = false;
}
SymLinks symLinks = SymLinks.FALSE;
if (getFS().supportsSymlinks()) {
File tmp = new File(getDirectory(), "tmplink"); //$NON-NLS-1$
try {
getFS().createSymLink(tmp, "target"); //$NON-NLS-1$
symLinks = null;
FileUtils.delete(tmp);
} catch (IOException e) {
// Normally a java.nio.file.FileSystemException
}
}
if (symLinks != null)
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_SYMLINKS, symLinks.name()
.toLowerCase());
cfg.setInt(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_FILEMODE, fileMode);
if (bare)
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_BARE, true);
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, !bare);
if (SystemReader.getInstance().isMacOS())
// Java has no other way
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_PRECOMPOSEUNICODE, true);
cfg.save();
}