*/
@Override
public void updateRepositoryModel(String repositoryName, RepositoryModel repository,
boolean isCreate) throws GitBlitException {
if (isCollectingGarbage(repositoryName)) {
throw new GitBlitException(MessageFormat.format("sorry, Gitblit is busy collecting garbage in {0}",
repositoryName));
}
Repository r = null;
String projectPath = StringUtils.getFirstPathElement(repository.name);
if (!StringUtils.isEmpty(projectPath)) {
if (projectPath.equalsIgnoreCase(settings.getString(Keys.web.repositoryRootGroupName, "main"))) {
// strip leading group name
repository.name = repository.name.substring(projectPath.length() + 1);
}
}
if (isCreate) {
// ensure created repository name ends with .git
if (!repository.name.toLowerCase().endsWith(org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) {
repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;
}
if (hasRepository(repository.name)) {
throw new GitBlitException(MessageFormat.format(
"Can not create repository ''{0}'' because it already exists.",
repository.name));
}
// create repository
logger.info("create repository " + repository.name);
String shared = settings.getString(Keys.git.createRepositoriesShared, "FALSE");
r = JGitUtils.createRepository(repositoriesFolder, repository.name, shared);
} else {
// rename repository
if (!repositoryName.equalsIgnoreCase(repository.name)) {
if (!repository.name.toLowerCase().endsWith(
org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) {
repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;
}
if (new File(repositoriesFolder, repository.name).exists()) {
throw new GitBlitException(MessageFormat.format(
"Failed to rename ''{0}'' because ''{1}'' already exists.",
repositoryName, repository.name));
}
close(repositoryName);
File folder = new File(repositoriesFolder, repositoryName);
File destFolder = new File(repositoriesFolder, repository.name);
if (destFolder.exists()) {
throw new GitBlitException(
MessageFormat
.format("Can not rename repository ''{0}'' to ''{1}'' because ''{1}'' already exists.",
repositoryName, repository.name));
}
File parentFile = destFolder.getParentFile();
if (!parentFile.exists() && !parentFile.mkdirs()) {
throw new GitBlitException(MessageFormat.format(
"Failed to create folder ''{0}''", parentFile.getAbsolutePath()));
}
if (!folder.renameTo(destFolder)) {
throw new GitBlitException(MessageFormat.format(
"Failed to rename repository ''{0}'' to ''{1}''.", repositoryName,
repository.name));
}
// rename the roles
if (!userManager.renameRepositoryRole(repositoryName, repository.name)) {
throw new GitBlitException(MessageFormat.format(
"Failed to rename repository permissions ''{0}'' to ''{1}''.",
repositoryName, repository.name));
}
// rename fork origins in their configs