\r
import java.io.File;\r
import java.io.IOException;\r
+import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
\r
private FileResolver<Void> repositoryResolver;\r
\r
- private File repositories;\r
+ private File repositoriesFolder;\r
\r
private boolean exportAll;\r
\r
userCookie.setPath("/");\r
response.addCookie(userCookie);\r
}\r
-\r
- public void editRepositoryModel(RepositoryModel repository, boolean isCreate) {\r
- Repository r = null;\r
- if (isCreate) {\r
- // create repository\r
- logger.info("create repository " + repository.name);\r
- r = JGitUtils.createRepository(repositories, repository.name, true);\r
- } else {\r
- // load repository\r
- logger.info("edit repository " + repository.name);\r
- try {\r
- r = repositoryResolver.open(null, repository.name);\r
- } catch (RepositoryNotFoundException e) {\r
- logger.error("Repository not found", e);\r
- } catch (ServiceNotEnabledException e) {\r
- logger.error("Service not enabled", e);\r
- }\r
- }\r
-\r
- // update settings\r
- StoredConfig config = JGitUtils.readConfig(r);\r
- config.setString("gitblit", null, "description", repository.description);\r
- config.setString("gitblit", null, "owner", repository.owner);\r
- config.setBoolean("gitblit", null, "useTickets", repository.useTickets);\r
- config.setBoolean("gitblit", null, "useDocs", repository.useDocs);\r
- config.setBoolean("gitblit", null, "restrictedAccess", repository.useRestrictedAccess);\r
- try {\r
- config.save();\r
- } catch (IOException e) {\r
- logger.error("Failed to save repository config!", e);\r
- }\r
- r.close();\r
- }\r
-\r
+ \r
public List<String> getRepositoryList() {\r
- return JGitUtils.getRepositoryList(repositories, exportAll, storedSettings.getBoolean(Keys.git.nestedRepositories, true));\r
- }\r
-\r
- public List<RepositoryModel> getRepositories() {\r
- List<String> list = getRepositoryList();\r
- List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();\r
- for (String repo : list) {\r
- RepositoryModel model = getRepositoryModel(repo);\r
- repositories.add(model);\r
- }\r
- return repositories;\r
+ return JGitUtils.getRepositoryList(repositoriesFolder, exportAll, storedSettings.getBoolean(Keys.git.nestedRepositories, true));\r
}\r
\r
public Repository getRepository(String repositoryName) {\r
}\r
return r;\r
}\r
-\r
+ \r
+ public List<RepositoryModel> getRepositoryModels() {\r
+ List<String> list = getRepositoryList();\r
+ List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();\r
+ for (String repo : list) {\r
+ RepositoryModel model = getRepositoryModel(repo);\r
+ repositories.add(model);\r
+ }\r
+ return repositories;\r
+ }\r
+ \r
public RepositoryModel getRepositoryModel(String repositoryName) {\r
Repository r = getRepository(repositoryName);\r
RepositoryModel model = new RepositoryModel();\r
return model;\r
}\r
\r
+ public void editRepositoryModel(RepositoryModel repository, boolean isCreate) throws GitBlitException {\r
+ Repository r = null;\r
+ if (isCreate) {\r
+ if (new File(repositoriesFolder, repository.name).exists()) {\r
+ throw new GitBlitException(MessageFormat.format("Can not create repository {0} because it already exists.", repository.name));\r
+ }\r
+ // create repository \r
+ logger.info("create repository " + repository.name);\r
+ r = JGitUtils.createRepository(repositoriesFolder, repository.name, true);\r
+ } else {\r
+ // load repository\r
+ logger.info("edit repository " + repository.name);\r
+ try {\r
+ r = repositoryResolver.open(null, repository.name);\r
+ } catch (RepositoryNotFoundException e) {\r
+ logger.error("Repository not found", e);\r
+ } catch (ServiceNotEnabledException e) {\r
+ logger.error("Service not enabled", e);\r
+ }\r
+ }\r
+\r
+ // update settings\r
+ StoredConfig config = JGitUtils.readConfig(r);\r
+ config.setString("gitblit", null, "description", repository.description);\r
+ config.setString("gitblit", null, "owner", repository.owner);\r
+ config.setBoolean("gitblit", null, "useTickets", repository.useTickets);\r
+ config.setBoolean("gitblit", null, "useDocs", repository.useDocs);\r
+ config.setBoolean("gitblit", null, "restrictedAccess", repository.useRestrictedAccess);\r
+ try {\r
+ config.save();\r
+ } catch (IOException e) {\r
+ logger.error("Failed to save repository config!", e);\r
+ }\r
+ r.close();\r
+ }\r
+\r
public void setupContext(IStoredSettings settings) {\r
logger.info("Setting up GitBlit context from " + settings.toString());\r
this.storedSettings = settings;\r
- repositories = new File(settings.getString(Keys.git.repositoriesFolder, "repos"));\r
+ repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "repos"));\r
exportAll = settings.getBoolean(Keys.git.exportAll, true);\r
- repositoryResolver = new FileResolver(repositories, exportAll);\r
+ repositoryResolver = new FileResolver<Void>(repositoriesFolder, exportAll);\r
}\r
\r
@Override\r
File gitFolder = new File(file, Constants.DOT_GIT);\r
boolean isGitRepository = gitFolder.exists() && gitFolder.isDirectory();\r
\r
- // then look for folder.git/HEAD\r
+ // then look for folder.git/HEAD or folder/HEAD and folder/config\r
if (!isGitRepository) {\r
- if (file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists()) {\r
+ if ((file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists())\r
+ || (new File(file, "config").exists() && new File(file, Constants.HEAD).exists())) {\r
gitFolder = file;\r
isGitRepository = true;\r
}\r
\r
public static String getRawContentAsString(Repository r, RevBlob blob) {\r
byte [] content = getRawContent(r, blob);\r
- return new String(content, Charset.forName("UTF-8"));\r
+ return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));\r
}\r
\r
public static String getRawContentAsString(Repository r, RevCommit commit, String blobPath) {\r
RevObject obj = getRevObject(r, commit.getTree(), blobPath);\r
byte [] content = getRawContent(r, (RevBlob) obj);\r
- return new String(content, Charset.forName("UTF-8"));\r
+ return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));\r
}\r
\r
public static List<PathModel> getFilesInPath(Repository r, String basePath, String objectId) {\r