Search in sources :

Example 31 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class JGitUtils method createRepository.

/**
	 * Creates a bare, shared repository.
	 *
	 * @param repositoriesFolder
	 * @param name
	 * @param shared
	 *          the setting for the --shared option of "git init".
	 * @return Repository
	 */
public static Repository createRepository(File repositoriesFolder, String name, String shared) {
    try {
        Repository repo = null;
        try {
            Git git = Git.init().setDirectory(new File(repositoriesFolder, name)).setBare(true).call();
            repo = git.getRepository();
        } catch (GitAPIException e) {
            throw new RuntimeException(e);
        }
        GitConfigSharedRepository sharedRepository = new GitConfigSharedRepository(shared);
        if (sharedRepository.isShared()) {
            StoredConfig config = repo.getConfig();
            config.setString("core", null, "sharedRepository", sharedRepository.getValue());
            config.setBoolean("receive", null, "denyNonFastforwards", true);
            config.save();
            if (!JnaUtils.isWindows()) {
                Iterator<File> iter = org.apache.commons.io.FileUtils.iterateFilesAndDirs(repo.getDirectory(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
                // Adjust permissions on file/directory
                while (iter.hasNext()) {
                    adjustSharedPerm(iter.next(), sharedRepository);
                }
            }
        }
        return repo;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) IOException(java.io.IOException) File(java.io.File)

Example 32 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class ITicketService method deleteLabel.

/**
	 * Deletes a label.
	 *
	 * @param repository
	 * @param label
	 * @param createdBy
	 * @return true if the delete was successful
	 * @since 1.4.0
	 */
public synchronized boolean deleteLabel(RepositoryModel repository, String label, String createdBy) {
    if (StringUtils.isEmpty(label)) {
        throw new IllegalArgumentException("label can not be empty!");
    }
    Repository db = null;
    try {
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.unsetSection(LABEL, label);
        config.save();
        return true;
    } catch (IOException e) {
        log.error("failed to delete label " + label + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException)

Example 33 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class ITicketService method deleteMilestone.

/**
	 * Deletes a milestone.
	 *
	 * @param repository
	 * @param milestone
	 * @param createdBy
	 * @param notifyOpenTickets
	 * @return true if successful
	 * @since 1.6.0
	 */
public synchronized boolean deleteMilestone(RepositoryModel repository, String milestone, String createdBy, boolean notifyOpenTickets) {
    if (StringUtils.isEmpty(milestone)) {
        throw new IllegalArgumentException("milestone can not be empty!");
    }
    Repository db = null;
    try {
        TicketMilestone tm = getMilestone(repository, milestone);
        if (tm == null) {
            return false;
        }
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.unsetSection(MILESTONE, milestone);
        config.save();
        milestonesCache.remove(repository.name);
        TicketNotifier notifier = createNotifier();
        for (QueryResult qr : tm.tickets) {
            Change change = new Change(createdBy);
            change.setField(Field.milestone, "");
            TicketModel ticket = updateTicket(repository, qr.number, change);
            if (notifyOpenTickets && ticket.isOpen()) {
                notifier.queueMailing(ticket);
            }
        }
        if (notifyOpenTickets) {
            notifier.sendAll();
        }
        return true;
    } catch (IOException e) {
        log.error("failed to delete milestone " + milestone + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) IOException(java.io.IOException)

Example 34 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class ITicketService method updateLabel.

/**
	 * Updates a label.
	 *
	 * @param repository
	 * @param label
	 * @param createdBy
	 * @return true if the update was successful
	 * @since 1.4.0
	 */
public synchronized boolean updateLabel(RepositoryModel repository, TicketLabel label, String createdBy) {
    Repository db = null;
    try {
        db = repositoryManager.getRepository(repository.name);
        StoredConfig config = db.getConfig();
        config.setString(LABEL, label.name, COLOR, label.color);
        config.save();
        return true;
    } catch (IOException e) {
        log.error("failed to update label " + label + " in " + repository, e);
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return false;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException)

Example 35 with StoredConfig

use of org.eclipse.jgit.lib.StoredConfig in project gitblit by gitblit.

the class ITicketService method getLabels.

/**
	 * Returns the list of labels for the repository.
	 *
	 * @param repository
	 * @return the list of labels
	 * @since 1.4.0
	 */
public List<TicketLabel> getLabels(RepositoryModel repository) {
    String key = repository.name;
    if (labelsCache.containsKey(key)) {
        return labelsCache.get(key);
    }
    List<TicketLabel> list = new ArrayList<TicketLabel>();
    Repository db = repositoryManager.getRepository(repository.name);
    try {
        StoredConfig config = db.getConfig();
        Set<String> names = config.getSubsections(LABEL);
        for (String name : names) {
            TicketLabel label = new TicketLabel(name);
            label.color = config.getString(LABEL, name, COLOR);
            list.add(label);
        }
        labelsCache.put(key, Collections.unmodifiableList(list));
    } catch (Exception e) {
        log.error("invalid tickets settings for " + repository, e);
    } finally {
        db.close();
    }
    return list;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) IOException(java.io.IOException)

Aggregations

StoredConfig (org.eclipse.jgit.lib.StoredConfig)40 IOException (java.io.IOException)26 Repository (org.eclipse.jgit.lib.Repository)19 File (java.io.File)9 ArrayList (java.util.ArrayList)8 URISyntaxException (java.net.URISyntaxException)6 GitException (org.eclipse.che.api.git.exception.GitException)6 SimpleDateFormat (java.text.SimpleDateFormat)5 GitBlitException (com.gitblit.GitBlitException)4 RepositoryModel (com.gitblit.models.RepositoryModel)4 Point (java.awt.Point)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)4 TeamModel (com.gitblit.models.TeamModel)3 Change (com.gitblit.models.TicketModel.Change)3 UserModel (com.gitblit.models.UserModel)3 HashSet (java.util.HashSet)3 Git (org.eclipse.jgit.api.Git)3 RefSpec (org.eclipse.jgit.transport.RefSpec)3 AccessPermission (com.gitblit.Constants.AccessPermission)2