use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitVariableResolver method getGitBranch.
private String getGitBranch(String argument) throws CoreException {
IResource res = getResource(argument);
RepositoryMapping mapping = RepositoryMapping.getMapping(res);
if (mapping != null)
try {
return mapping.getRepository().getBranch();
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), e.getMessage()));
}
else
// $NON-NLS-1$
return "";
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class TrackUntrackOperationTest method assertTrackedState.
@SuppressWarnings("boxing")
private void assertTrackedState(IFile[] fileArr, boolean expectedState) throws IOException {
DirCache cache = repository1.getRepository().readDirCache();
for (IFile file : fileArr) {
RepositoryMapping rm = RepositoryMapping.getMapping(file);
String fileDir = rm.getRepoRelativePath(file);
boolean tracked = cache.findEntry(fileDir) > -1;
assertEquals("Wrong tracking state", expectedState, tracked);
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitResourceDeltaVisitor method visit.
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
final IResource resource = delta.getResource();
if (resource.getType() == IResource.ROOT) {
return true;
}
if (resource.getType() == IResource.PROJECT) {
if (delta.getKind() == IResourceDelta.REMOVED) {
IPath loc = deletedProjects.remove(resource);
if (loc != null) {
projectDeleted |= !loc.toFile().isDirectory();
}
return false;
}
// Git revision control or from a different repository
if (!ResourceUtil.isSharedWithGit(resource)) {
// Ignore the change for project and its children
return false;
}
GitProjectData gitData = GitProjectData.get((IProject) resource);
if (gitData == null) {
return false;
}
RepositoryMapping mapping = gitData.getRepositoryMapping(resource);
if (mapping == null || !gitData.hasInnerRepositories() && mapping.getRepository() != repository) {
return false;
}
// continue with children
return true;
}
Repository repositoryOfResource = null;
if (resource.isLinked()) {
IPath location = resource.getLocation();
if (location == null) {
return false;
}
repositoryOfResource = ResourceUtil.getRepository(location);
// in the same repository
if (repository != repositoryOfResource) {
return false;
}
} else {
repositoryOfResource = ResourceUtil.getRepository(resource);
}
if (resource.getType() == IResource.FOLDER) {
GitProjectData gitData = GitProjectData.get(resource.getProject());
if (gitData == null) {
return false;
}
if (repositoryOfResource == null || !gitData.isProtected(resource) && repositoryOfResource != repository) {
return false;
}
if (delta.getKind() == IResourceDelta.ADDED) {
IPath repoRelativePath = ResourceUtil.getRepositoryRelativePath(resource.getLocation(), repository);
if (repoRelativePath == null) {
return false;
}
if (!repoRelativePath.isEmpty()) {
// $NON-NLS-1$
String path = repoRelativePath.toPortableString() + "/";
if (isIgnoredInOldIndex(path)) {
// keep going to catch .gitignore files.
return true;
}
filesToUpdate.add(path);
resourcesToUpdate.add(resource);
}
}
// continue with children
return true;
}
if (repositoryOfResource != repository) {
return false;
}
if (!isInteresting(delta)) {
return false;
}
if (resource.getName().equals(Constants.DOT_GIT_IGNORE)) {
gitIgnoreChanged = true;
return false;
}
IPath repoRelativePath = ResourceUtil.getRepositoryRelativePath(resource.getLocation(), repository);
if (repoRelativePath == null) {
resourcesToUpdate.add(resource);
return true;
}
String path = repoRelativePath.toPortableString();
if (isIgnoredInOldIndex(path)) {
// change: ignore the delta to avoid unnecessary index updates
return false;
}
filesToUpdate.add(path);
resourcesToUpdate.add(resource);
return true;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitMoveDeleteHook method moveFile.
@Override
public boolean moveFile(final IResourceTree tree, final IFile srcf, final IFile dstf, final int updateFlags, final IProgressMonitor monitor) {
final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
if (!force && !tree.isSynchronized(srcf, IResource.DEPTH_ZERO))
return false;
final RepositoryMapping srcm = RepositoryMapping.getMapping(srcf);
if (srcm == null)
return false;
final RepositoryMapping dstm = RepositoryMapping.getMapping(dstf);
DirCache sCache = null;
try {
sCache = srcm.getRepository().lockDirCache();
final String sPath = srcm.getRepoRelativePath(srcf);
final DirCacheEntry sEnt = sCache.getEntry(sPath);
if (sEnt == null)
return FINISH_FOR_ME;
if (!sEnt.isMerged()) {
tree.failed(new Status(IStatus.WARNING, Activator.getPluginId(), CoreText.MoveDeleteHook_unmergedFileError));
return I_AM_DONE;
}
if (org.eclipse.egit.core.Activator.autoStageMoves()) {
final DirCacheEditor sEdit = sCache.editor();
sEdit.add(new DirCacheEditor.DeletePath(sEnt));
if (dstm != null && dstm.getRepository() == srcm.getRepository()) {
final String dPath = srcm.getRepoRelativePath(dstf);
sEdit.add(new DirCacheEditor.PathEdit(dPath) {
@Override
public void apply(final DirCacheEntry dEnt) {
dEnt.copyMetaData(sEnt);
}
});
}
if (!sEdit.commit()) {
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
}
}
tree.standardMoveFile(srcf, dstf, updateFlags, monitor);
} catch (IOException e) {
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
} finally {
if (sCache != null)
sCache.unlock();
}
return I_AM_DONE;
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitMoveDeleteHook method moveFolder.
@Override
public boolean moveFolder(final IResourceTree tree, final IFolder srcf, final IFolder dstf, final int updateFlags, final IProgressMonitor monitor) {
final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
if (!force && !tree.isSynchronized(srcf, IResource.DEPTH_ZERO))
return false;
final RepositoryMapping srcm = RepositoryMapping.getMapping(srcf);
if (srcm == null)
return false;
final RepositoryMapping dstm = RepositoryMapping.getMapping(dstf);
try {
final String sPath = srcm.getRepoRelativePath(srcf);
if (dstm != null && dstm.getRepository() == srcm.getRepository()) {
MoveResult result = null;
if (org.eclipse.egit.core.Activator.autoStageMoves()) {
// $NON-NLS-1$
final String dPath = srcm.getRepoRelativePath(dstf) + "/";
result = moveIndexContent(dPath, srcm, sPath);
} else {
result = checkUnmergedPaths(srcm, sPath);
}
switch(result) {
case SUCCESS:
break;
case FAILED:
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
return I_AM_DONE;
case UNTRACKED:
// we are not responsible for moving untracked files
return FINISH_FOR_ME;
case UNMERGED:
tree.failed(new Status(IStatus.WARNING, Activator.getPluginId(), CoreText.MoveDeleteHook_unmergedFileInFolderError));
return I_AM_DONE;
}
}
tree.standardMoveFolder(srcf, dstf, updateFlags, monitor);
} catch (IOException e) {
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
}
return true;
}
Aggregations