use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class CompareUtils method getIndexTypedElement.
/**
* Get a typed element for the file in the index.
*
* @param baseFile
* @return typed element
* @throws IOException
*/
public static ITypedElement getIndexTypedElement(@NonNull final IFile baseFile) throws IOException {
final RepositoryMapping mapping = RepositoryMapping.getMapping(baseFile);
if (mapping == null) {
Activator.error(NLS.bind(UIText.GitHistoryPage_errorLookingUpPath, baseFile.getLocation(), null), null);
return null;
}
final Repository repository = mapping.getRepository();
final String gitPath = mapping.getRepoRelativePath(baseFile);
final String encoding = CompareCoreUtils.getResourceEncoding(baseFile);
return getIndexTypedElement(repository, gitPath, encoding);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class GitRepositoriesViewTest method assertProjectIsShared.
private void assertProjectIsShared(String projectName, boolean shouldBeShared) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
RepositoryMapping mapping = RepositoryMapping.getMapping(project);
if (shouldBeShared) {
assertNotNull(mapping);
assertNotNull(mapping.getRepository());
} else
assertNull(mapping);
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class SharingWizardTest method erase.
private void erase(String projectName, Set<File> dirs) throws CoreException, IOException {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if (project.exists()) {
RepositoryMapping repo = RepositoryMapping.getMapping(project);
if (repo != null) {
IPath gitDirAbsolutePath = repo.getGitDirAbsolutePath();
File canonicalFile = gitDirAbsolutePath.toFile().getCanonicalFile();
dirs.add(canonicalFile);
File workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalFile();
File gitDirParent = canonicalFile.getParentFile();
if (!(gitDirParent.toString() + File.separator).startsWith(workspacePath.toString() + File.separator))
if (!(gitDirParent.toString() + File.separator).startsWith(getTestDirectory().getAbsolutePath().toString() + File.separator))
fail("Attempting cleanup of directory neither in workspace nor test directory" + canonicalFile);
new DisconnectProviderOperation(Collections.singleton(project)).execute(null);
}
project.close(null);
project.delete(true, true, null);
}
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class DynamicVariablesTest method setUp.
@Before
public void setUp() throws Exception {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
FileUtils.mkdir(new File(root.getLocation().toFile(), "Sub"), true);
gitDir = new File(new File(root.getLocation().toFile(), "Sub"), Constants.DOT_GIT);
repository = FileRepositoryBuilder.create(gitDir);
repository.create();
project = root.getProject(TEST_PROJECT);
project.create(null);
project.open(null);
IProjectDescription description = project.getDescription();
description.setLocation(root.getLocation().append(TEST_PROJECT_LOC));
project.move(description, IResource.FORCE, null);
project2 = root.getProject(TEST_PROJECT2);
project2.create(null);
project2.open(null);
gitDir2 = new File(project2.getLocation().toFile().getAbsoluteFile(), Constants.DOT_GIT);
repository2 = FileRepositoryBuilder.create(gitDir2);
repository2.create();
RepositoryMapping mapping = RepositoryMapping.create(project, gitDir);
RepositoryMapping mapping2 = RepositoryMapping.create(project2, gitDir2);
GitProjectData projectData = new GitProjectData(project);
GitProjectData projectData2 = new GitProjectData(project2);
projectData.setRepositoryMappings(Collections.singletonList(mapping));
projectData.store();
projectData2.setRepositoryMappings(Collections.singletonList(mapping2));
projectData2.store();
GitProjectData.add(project, projectData);
GitProjectData.add(project2, projectData2);
RepositoryProvider.map(project, GitProvider.class.getName());
RepositoryProvider.map(project2, GitProvider.class.getName());
JGitTestUtil.write(new File(repository.getWorkTree(), TEST_PROJECT + "/" + TEST_FILE), "Some data");
JGitTestUtil.write(new File(repository2.getWorkTree(), TEST_FILE2), "Some other data");
project.refreshLocal(IResource.DEPTH_INFINITE, null);
project2.refreshLocal(IResource.DEPTH_INFINITE, null);
git = new Git(repository);
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
git = new Git(repository2);
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
git.branchRename().setNewName("main").call();
}
use of org.eclipse.egit.core.project.RepositoryMapping in project egit by eclipse.
the class RepositoryUtil method isIgnored.
/**
* Checks if existing resource with given path is to be ignored.
* <p>
* <b>Note:</b>The check makes sense only for files which exists in the
* working directory. This method returns false for paths to not existing
* files or directories.
*
* @param path
* Path to be checked, file or directory must exist on the disk
* @return true if the path is either not inside git repository or exists
* and matches an ignore rule
* @throws IOException
* @since 2.3
*/
public static boolean isIgnored(IPath path) throws IOException {
RepositoryMapping mapping = RepositoryMapping.getMapping(path);
if (mapping == null) {
// Linked resources may not be mapped
return true;
}
Repository repository = mapping.getRepository();
WorkingTreeIterator treeIterator = IteratorService.createInitialIterator(repository);
if (treeIterator == null) {
return true;
}
String repoRelativePath = mapping.getRepoRelativePath(path);
if (repoRelativePath == null || repoRelativePath.isEmpty()) {
return true;
}
try (TreeWalk walk = new TreeWalk(repository)) {
walk.addTree(treeIterator);
walk.setFilter(PathFilterGroup.createFromStrings(repoRelativePath));
while (walk.next()) {
WorkingTreeIterator workingTreeIterator = walk.getTree(0, WorkingTreeIterator.class);
if (walk.getPathString().equals(repoRelativePath)) {
return workingTreeIterator.isEntryIgnored();
}
if (workingTreeIterator.getEntryFileMode().equals(FileMode.TREE)) {
walk.enterSubtree();
}
}
}
return false;
}
Aggregations