// fork from original to a temporary bare repo
File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName);
if (refChecks.exists()) {
FileUtils.delete(refChecks, FileUtils.RECURSIVE);
}
CloneCommand clone = Git.cloneRepository();
clone.setURI(url + "/" + originName);
clone.setDirectory(refChecks);
clone.setBare(true);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(cp);
GitBlitSuite.close(clone.call());
// elevate repository to clone permission
RepositoryModel model = repositories().getRepositoryModel(forkName);
switch (permission) {
case VIEW:
model.accessRestriction = AccessRestrictionType.CLONE;
break;
case CLONE:
model.accessRestriction = AccessRestrictionType.CLONE;
break;
default:
model.accessRestriction = AccessRestrictionType.PUSH;
}
model.authorizationControl = AuthorizationControl.NAMED;
// grant user specified
user.setRepositoryPermission(model.name, permission);
gitblit().addUser(user);
repositories().updateRepositoryModel(model.name, model, false);
// clone temp bare repo to working copy
File local = new File(GitBlitSuite.REPOSITORIES, workingCopy);
if (local.exists()) {
FileUtils.delete(local, FileUtils.RECURSIVE);
}
clone = Git.cloneRepository();
clone.setURI(MessageFormat.format("{0}/{1}", url, model.name));
clone.setDirectory(local);
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setCredentialsProvider(cp);
try {
GitBlitSuite.close(clone.call());
} catch (GitAPIException e) {
if (permission.atLeast(AccessPermission.CLONE)) {
throw e;
} else {
// close serving repository