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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations