use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.
the class ProjectReferenceImporterTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
testRepository = new TestRepository(gitDir);
repository = testRepository.getRepository();
RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
util.addConfiguredRepository(repository.getDirectory());
}
use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.
the class RepositoriesViewContentProvider method getElements.
@Override
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
List<RepositoryTreeNode> nodes = new ArrayList<>();
List<String> directories = new ArrayList<>();
RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
if (inputElement instanceof Collection) {
for (Iterator it = ((Collection) inputElement).iterator(); it.hasNext(); ) {
Object next = it.next();
if (next instanceof RepositoryTreeNode)
nodes.add((RepositoryTreeNode) next);
else if (next instanceof String)
directories.add((String) next);
}
} else if (inputElement instanceof IWorkspaceRoot) {
directories.addAll(repositoryUtil.getConfiguredRepositories());
}
for (String directory : directories) {
try {
File gitDir = new File(directory);
if (gitDir.exists()) {
RepositoryNode rNode = new RepositoryNode(null, repositoryCache.lookupRepository(gitDir));
nodes.add(rNode);
} else
repositoryUtil.removeDir(gitDir);
} catch (IOException e) {
// ignore for now
}
}
Collections.sort(nodes);
return nodes.toArray();
}
use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.
the class ProjectReferenceImporterTest method tearDown.
@Override
@After
public void tearDown() throws Exception {
RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
util.removeDir(repository.getDirectory());
testRepository.dispose();
repository = null;
super.tearDown();
}
use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.
the class GitLabels method getStyledLabel.
/**
* Computes detailed repository label that consists of repository name,
* state, checked-out branch and it's status (returned by
* {@linkplain #formatBranchTrackingStatus(BranchTrackingStatus)})
*
* @param repository
* @return a styled string for the repository
* @throws IOException
*/
@NonNull
public static StyledString getStyledLabel(@NonNull Repository repository) throws IOException {
RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
StyledString string = getChangedPrefix(repository);
string.append(repositoryUtil.getRepositoryName(repository));
String branch = repositoryUtil.getShortBranch(repository);
if (branch != null) {
string.append(' ');
string.append('[', StyledString.DECORATIONS_STYLER);
string.append(branch, StyledString.DECORATIONS_STYLER);
BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
if (trackingStatus != null && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
String formattedTrackingStatus = GitLabels.formatBranchTrackingStatus(trackingStatus);
string.append(' ');
string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
}
RepositoryState repositoryState = repository.getRepositoryState();
if (repositoryState != RepositoryState.SAFE) {
// $NON-NLS-1$
string.append(" - ", StyledString.DECORATIONS_STYLER);
string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
}
string.append(']', StyledString.DECORATIONS_STYLER);
}
return string;
}
use of org.eclipse.egit.core.RepositoryUtil in project egit by eclipse.
the class SubmoduleUpdateOperation method execute.
@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
IWorkspaceRunnable action = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor pm) throws CoreException {
RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
SubMonitor progress = SubMonitor.convert(pm, 4);
progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_updating, util.getRepositoryName(repository)));
Git git = Git.wrap(repository);
Collection<String> updated = null;
try {
SubmoduleInitCommand init = git.submoduleInit();
for (String path : paths) init.addPath(path);
init.call();
progress.worked(1);
SubmoduleUpdateCommand update = git.submoduleUpdate();
for (String path : paths) update.addPath(path);
update.setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(2)));
MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
if (strategy != null) {
update.setStrategy(strategy);
}
update.setCallback(new CloneCommand.Callback() {
@Override
public void initializedSubmodules(Collection<String> submodules) {
// Nothing to do
}
@Override
public void cloningSubmodule(String path) {
progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_cloning, util.getRepositoryName(repository), path));
}
@Override
public void checkingOut(AnyObjectId commit, String path) {
// Nothing to do
}
});
updated = update.call();
SubMonitor refreshMonitor = progress.newChild(1).setWorkRemaining(updated.size());
for (String path : updated) {
Repository subRepo = SubmoduleWalk.getSubmoduleRepository(repository, path);
if (subRepo != null) {
ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(subRepo), refreshMonitor.newChild(1));
} else {
refreshMonitor.worked(1);
}
}
} catch (GitAPIException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
} catch (IOException e) {
throw new TeamException(e.getLocalizedMessage(), e.getCause());
} finally {
if (updated != null && !updated.isEmpty()) {
repository.notifyIndexChanged();
}
}
}
};
ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Aggregations