summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/gitblit/GitBlit.java102
-rw-r--r--src/com/gitblit/GitBlitException.java10
-rw-r--r--src/com/gitblit/utils/JGitUtils.java9
-rw-r--r--src/com/gitblit/wicket/BasePage.html6
-rw-r--r--src/com/gitblit/wicket/pages/EditRepositoryPage.java8
-rw-r--r--src/com/gitblit/wicket/pages/RepositoriesPage.java2
-rw-r--r--src/com/gitblit/wicket/resources/bullet_error.pngbin0 -> 368 bytes
-rw-r--r--src/com/gitblit/wicket/resources/gitblit.css19
8 files changed, 99 insertions, 57 deletions
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
index a626be84..e557c934 100644
--- a/src/com/gitblit/GitBlit.java
+++ b/src/com/gitblit/GitBlit.java
@@ -2,6 +2,7 @@ package com.gitblit;
import java.io.File;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -30,7 +31,7 @@ public class GitBlit implements ServletContextListener {
private FileResolver<Void> repositoryResolver;
- private File repositories;
+ private File repositoriesFolder;
private boolean exportAll;
@@ -93,52 +94,9 @@ public class GitBlit implements ServletContextListener {
userCookie.setPath("/");
response.addCookie(userCookie);
}
-
- public void editRepositoryModel(RepositoryModel repository, boolean isCreate) {
- Repository r = null;
- if (isCreate) {
- // create repository
- logger.info("create repository " + repository.name);
- r = JGitUtils.createRepository(repositories, repository.name, true);
- } else {
- // load repository
- logger.info("edit repository " + repository.name);
- try {
- r = repositoryResolver.open(null, repository.name);
- } catch (RepositoryNotFoundException e) {
- logger.error("Repository not found", e);
- } catch (ServiceNotEnabledException e) {
- logger.error("Service not enabled", e);
- }
- }
-
- // update settings
- StoredConfig config = JGitUtils.readConfig(r);
- config.setString("gitblit", null, "description", repository.description);
- config.setString("gitblit", null, "owner", repository.owner);
- config.setBoolean("gitblit", null, "useTickets", repository.useTickets);
- config.setBoolean("gitblit", null, "useDocs", repository.useDocs);
- config.setBoolean("gitblit", null, "restrictedAccess", repository.useRestrictedAccess);
- try {
- config.save();
- } catch (IOException e) {
- logger.error("Failed to save repository config!", e);
- }
- r.close();
- }
-
+
public List<String> getRepositoryList() {
- return JGitUtils.getRepositoryList(repositories, exportAll, storedSettings.getBoolean(Keys.git.nestedRepositories, true));
- }
-
- public List<RepositoryModel> getRepositories() {
- List<String> list = getRepositoryList();
- List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();
- for (String repo : list) {
- RepositoryModel model = getRepositoryModel(repo);
- repositories.add(model);
- }
- return repositories;
+ return JGitUtils.getRepositoryList(repositoriesFolder, exportAll, storedSettings.getBoolean(Keys.git.nestedRepositories, true));
}
public Repository getRepository(String repositoryName) {
@@ -155,7 +113,17 @@ public class GitBlit implements ServletContextListener {
}
return r;
}
-
+
+ public List<RepositoryModel> getRepositoryModels() {
+ List<String> list = getRepositoryList();
+ List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();
+ for (String repo : list) {
+ RepositoryModel model = getRepositoryModel(repo);
+ repositories.add(model);
+ }
+ return repositories;
+ }
+
public RepositoryModel getRepositoryModel(String repositoryName) {
Repository r = getRepository(repositoryName);
RepositoryModel model = new RepositoryModel();
@@ -174,12 +142,48 @@ public class GitBlit implements ServletContextListener {
return model;
}
+ public void editRepositoryModel(RepositoryModel repository, boolean isCreate) throws GitBlitException {
+ Repository r = null;
+ if (isCreate) {
+ if (new File(repositoriesFolder, repository.name).exists()) {
+ throw new GitBlitException(MessageFormat.format("Can not create repository {0} because it already exists.", repository.name));
+ }
+ // create repository
+ logger.info("create repository " + repository.name);
+ r = JGitUtils.createRepository(repositoriesFolder, repository.name, true);
+ } else {
+ // load repository
+ logger.info("edit repository " + repository.name);
+ try {
+ r = repositoryResolver.open(null, repository.name);
+ } catch (RepositoryNotFoundException e) {
+ logger.error("Repository not found", e);
+ } catch (ServiceNotEnabledException e) {
+ logger.error("Service not enabled", e);
+ }
+ }
+
+ // update settings
+ StoredConfig config = JGitUtils.readConfig(r);
+ config.setString("gitblit", null, "description", repository.description);
+ config.setString("gitblit", null, "owner", repository.owner);
+ config.setBoolean("gitblit", null, "useTickets", repository.useTickets);
+ config.setBoolean("gitblit", null, "useDocs", repository.useDocs);
+ config.setBoolean("gitblit", null, "restrictedAccess", repository.useRestrictedAccess);
+ try {
+ config.save();
+ } catch (IOException e) {
+ logger.error("Failed to save repository config!", e);
+ }
+ r.close();
+ }
+
public void setupContext(IStoredSettings settings) {
logger.info("Setting up GitBlit context from " + settings.toString());
this.storedSettings = settings;
- repositories = new File(settings.getString(Keys.git.repositoriesFolder, "repos"));
+ repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "repos"));
exportAll = settings.getBoolean(Keys.git.exportAll, true);
- repositoryResolver = new FileResolver(repositories, exportAll);
+ repositoryResolver = new FileResolver<Void>(repositoriesFolder, exportAll);
}
@Override
diff --git a/src/com/gitblit/GitBlitException.java b/src/com/gitblit/GitBlitException.java
new file mode 100644
index 00000000..15e38e16
--- /dev/null
+++ b/src/com/gitblit/GitBlitException.java
@@ -0,0 +1,10 @@
+package com.gitblit;
+
+public class GitBlitException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public GitBlitException(String message) {
+ super(message);
+ }
+}
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index 4cfed0da..70a938ff 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -94,9 +94,10 @@ public class JGitUtils {
File gitFolder = new File(file, Constants.DOT_GIT);
boolean isGitRepository = gitFolder.exists() && gitFolder.isDirectory();
- // then look for folder.git/HEAD
+ // then look for folder.git/HEAD or folder/HEAD and folder/config
if (!isGitRepository) {
- if (file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists()) {
+ if ((file.getName().endsWith(Constants.DOT_GIT_EXT) && new File(file, Constants.HEAD).exists())
+ || (new File(file, "config").exists() && new File(file, Constants.HEAD).exists())) {
gitFolder = file;
isGitRepository = true;
}
@@ -266,13 +267,13 @@ public class JGitUtils {
public static String getRawContentAsString(Repository r, RevBlob blob) {
byte [] content = getRawContent(r, blob);
- return new String(content, Charset.forName("UTF-8"));
+ return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));
}
public static String getRawContentAsString(Repository r, RevCommit commit, String blobPath) {
RevObject obj = getRevObject(r, commit.getTree(), blobPath);
byte [] content = getRawContent(r, (RevBlob) obj);
- return new String(content, Charset.forName("UTF-8"));
+ return new String(content, Charset.forName(Constants.CHARACTER_ENCODING));
}
public static List<PathModel> getFilesInPath(Repository r, String basePath, String objectId) {
diff --git a/src/com/gitblit/wicket/BasePage.html b/src/com/gitblit/wicket/BasePage.html
index b88192b5..69183b68 100644
--- a/src/com/gitblit/wicket/BasePage.html
+++ b/src/com/gitblit/wicket/BasePage.html
@@ -21,8 +21,10 @@
<img src="resources/gitblt_25.png" width="79" height="25" alt="gitblit" class="logo"/>
</wicket:link>
</a>
- <a href="/"><span wicket:id="siteName">[site name]</span></a> / <span wicket:id="repositoryName">[repository name]</span> <span wicket:id="pageName">[page name]</span>
- <div style="float:none;" wicket:id="feedback">[Feedback Panel]</div>
+ <span>
+ <a href="/"><span wicket:id="siteName">[site name]</span></a> / <span wicket:id="repositoryName">[repository name]</span> <span wicket:id="pageName">[page name]</span>
+ </span>
+ <span wicket:id="feedback">[Feedback Panel]</span>
</div>
<!-- page content -->
diff --git a/src/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
index 6201b22b..45fe9e2e 100644
--- a/src/com/gitblit/wicket/pages/EditRepositoryPage.java
+++ b/src/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -9,6 +9,7 @@ import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import com.gitblit.GitBlit;
+import com.gitblit.GitBlitException;
import com.gitblit.wicket.AdminPage;
import com.gitblit.wicket.BasePage;
import com.gitblit.wicket.WicketUtils;
@@ -48,7 +49,12 @@ public class EditRepositoryPage extends BasePage {
@Override
protected void onSubmit() {
- GitBlit.self().editRepositoryModel(repositoryModel, isCreate);
+ try {
+ GitBlit.self().editRepositoryModel(repositoryModel, isCreate);
+ } catch (GitBlitException e) {
+ error(e.getMessage());
+ return;
+ }
setRedirect(true);
setResponsePage(RepositoriesPage.class);
}
diff --git a/src/com/gitblit/wicket/pages/RepositoriesPage.java b/src/com/gitblit/wicket/pages/RepositoriesPage.java
index c834604d..768cea14 100644
--- a/src/com/gitblit/wicket/pages/RepositoriesPage.java
+++ b/src/com/gitblit/wicket/pages/RepositoriesPage.java
@@ -89,7 +89,7 @@ public class RepositoriesPage extends BasePage {
}
add(repositoriesMessage);
- List<RepositoryModel> rows = GitBlit.self().getRepositories();
+ List<RepositoryModel> rows = GitBlit.self().getRepositoryModels();
DataProvider dp = new DataProvider(rows);
DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("repository", dp) {
private static final long serialVersionUID = 1L;
diff --git a/src/com/gitblit/wicket/resources/bullet_error.png b/src/com/gitblit/wicket/resources/bullet_error.png
new file mode 100644
index 00000000..b2e6b752
--- /dev/null
+++ b/src/com/gitblit/wicket/resources/bullet_error.png
Binary files differ
diff --git a/src/com/gitblit/wicket/resources/gitblit.css b/src/com/gitblit/wicket/resources/gitblit.css
index 53845466..8317e363 100644
--- a/src/com/gitblit/wicket/resources/gitblit.css
+++ b/src/com/gitblit/wicket/resources/gitblit.css
@@ -628,4 +628,23 @@ span .tagRef {
span .headRef {
background-color: #ccffcc;
border-color: #ccffcc #00cc33 #00cc33 #ccffcc;
+}
+
+.feedbackPanelERROR {
+ color: red;
+ list-style-image: url(bullet_error.png);
+ font-weight: bold;
+ text-align:left;
+ vertical-align: top;
+ padding:0;
+ margin:0;
+}
+
+.feedbackPanelINFO {
+ color: green;
+ list-style: none;
+ font-weight: bold;
+ text-align:center;
+ padding:0;
+ margin:0;
} \ No newline at end of file