| | |
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.models.RepositoryModel;
|
| | | import com.gitblit.wicket.models.UserModel;
|
| | |
|
| | | public class GitBlit implements ServletContextListener {
|
| | |
|
| | |
| | |
|
| | | public List<String> getOtherCloneUrls(String repositoryName) {
|
| | | List<String> cloneUrls = new ArrayList<String>();
|
| | | for (String url : storedSettings.getStrings(Keys.git.otherUrls)) {
|
| | | for (String url : storedSettings.getStrings(Keys.web.otherUrls)) {
|
| | | cloneUrls.add(MessageFormat.format(url, repositoryName));
|
| | | }
|
| | | return cloneUrls;
|
| | |
| | |
|
| | | public List<String> getRepositoryList() {
|
| | | return JGitUtils.getRepositoryList(repositoriesFolder, exportAll,
|
| | | storedSettings.getBoolean(Keys.git.nestedRepositories, true));
|
| | | storedSettings.getBoolean(Keys.git.searchRepositoriesSubfolders, true));
|
| | | }
|
| | |
|
| | | public Repository getRepository(String repositoryName) {
|
| | |
| | | r = repositoryResolver.open(null, repositoryName);
|
| | | } catch (RepositoryNotFoundException e) {
|
| | | r = null;
|
| | | logger.error("GitBlit.getRepository(String) failed to find repository "
|
| | | + repositoryName);
|
| | | logger.error("GitBlit.getRepository(String) failed to find "
|
| | | + new File(repositoriesFolder, repositoryName).getAbsolutePath());
|
| | | } catch (ServiceNotEnabledException e) {
|
| | | r = null;
|
| | | e.printStackTrace();
|
| | |
| | |
|
| | | public RepositoryModel getRepositoryModel(String repositoryName) {
|
| | | Repository r = getRepository(repositoryName);
|
| | | if (r == null) {
|
| | | return null;
|
| | | }
|
| | | RepositoryModel model = new RepositoryModel();
|
| | | model.name = repositoryName;
|
| | | model.hasCommits = JGitUtils.hasCommits(r);
|
| | |
| | | "accessRestriction", null));
|
| | | model.showRemoteBranches = getConfig(config, "showRemoteBranches", false);
|
| | | model.isFrozen = getConfig(config, "isFrozen", false);
|
| | | model.showReadme = getConfig(config, "showReadme", false);
|
| | | }
|
| | | r.close();
|
| | | return model;
|
| | |
| | | boolean isCreate) throws GitBlitException {
|
| | | Repository r = null;
|
| | | 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 (new File(repositoriesFolder, repository.name).exists()) {
|
| | | throw new GitBlitException(MessageFormat.format(
|
| | | "Can not create repository ''{0}'' because it already exists.",
|
| | |
| | | }
|
| | | // create repository
|
| | | logger.info("create repository " + repository.name);
|
| | | r = JGitUtils.createRepository(repositoriesFolder, repository.name, true);
|
| | | r = JGitUtils.createRepository(repositoriesFolder, repository.name);
|
| | | } else {
|
| | | // rename repository
|
| | | if (!repositoryName.equalsIgnoreCase(repository.name)) {
|
| | |
| | | repository.accessRestriction.name());
|
| | | config.setBoolean("gitblit", null, "showRemoteBranches", repository.showRemoteBranches);
|
| | | config.setBoolean("gitblit", null, "isFrozen", repository.isFrozen);
|
| | | config.setBoolean("gitblit", null, "showReadme", repository.showReadme);
|
| | | try {
|
| | | config.save();
|
| | | } catch (IOException e) {
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | public boolean renameRepository(RepositoryModel model, String newName) {
|
| | | File folder = new File(repositoriesFolder, model.name);
|
| | | if (folder.exists() && folder.isDirectory()) {
|
| | | File newFolder = new File(repositoriesFolder, newName);
|
| | | if (folder.renameTo(newFolder)) {
|
| | | return loginService.renameRole(model.name, newName);
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public void configureContext(IStoredSettings settings) {
|
| | | logger.info("Using configuration from " + settings.toString());
|
| | | logger.info("Reading configuration from " + settings.toString());
|
| | | this.storedSettings = settings;
|
| | | repositoriesFolder = new File(settings.getString(Keys.git.repositoriesFolder, "repos"));
|
| | | exportAll = settings.getBoolean(Keys.git.exportAll, true);
|
| | |
| | | @Override
|
| | | public void contextInitialized(ServletContextEvent contextEvent) {
|
| | | if (storedSettings == null) {
|
| | | // for running gitblit as a traditional webapp in a servlet container
|
| | | WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());
|
| | | configureContext(webxmlSettings);
|
| | | }
|
| | |
| | |
|
| | | @Override
|
| | | public void contextDestroyed(ServletContextEvent contextEvent) {
|
| | | logger.info("GitBlit context destroyed by servlet container.");
|
| | | logger.info("Gitblit context destroyed by servlet container.");
|
| | | }
|
| | | }
|