/** * Strip work dir and return normalized repository path. * * @param workDir * Work dir * @param file * File whose path shall be stripped of its workdir * @return normalized repository relative path or the empty string if the * file is not relative to the work directory. */ @NonNull public static String stripWorkDir(File workDir, File file) { final String filePath = file.getPath(); final String workDirPath = workDir.getPath(); if (filePath.length() <= workDirPath.length() || filePath.charAt(workDirPath.length()) != File.separatorChar || !filePath.startsWith(workDirPath)) { File absWd = workDir.isAbsolute() ? workDir : workDir.getAbsoluteFile(); File absFile = file.isAbsolute() ? file : file.getAbsoluteFile(); if (absWd == workDir && absFile == file) return ""; //$NON-NLS-1$ return stripWorkDir(absWd, absFile); } String relName = filePath.substring(workDirPath.length() + 1); if (File.separatorChar != '/') relName = relName.replace(File.separatorChar, '/'); return relName; }
/** * @return The path to the commit edit message file relative to the * repository's work tree, or null if the repository is bare. */ private String getCommitEditMessageFilePath() { File gitDir = getRepository().getDirectory(); if (gitDir == null) { return null; } return Repository.stripWorkDir(getRepository().getWorkTree(), new File( gitDir, Constants.COMMIT_EDITMSG)); }
private static String calculateModulePath(MavenProject rootProject, MavenProject project) throws MojoExecutionException { // Getting canonical files because on Windows, it's possible one returns "C:\..." and the other "c:\..." which is rather amazing File projectRoot; File moduleRoot; try { projectRoot = rootProject.getBasedir().getCanonicalFile(); moduleRoot = project.getBasedir().getCanonicalFile(); } catch (IOException e) { throw new MojoExecutionException("Could not find directory paths for maven project", e); } String relativePathToModule = Repository.stripWorkDir(projectRoot, moduleRoot); if (relativePathToModule.length() == 0) { relativePathToModule = "."; } return relativePathToModule; }
/** * Strip work dir and return normalized repository path. * * @param workDir Work dir * @param file File whose path shall be stripped of its workdir * @return normalized repository relative path or the empty * string if the file is not relative to the work directory. */ @NonNull public static String stripWorkDir(File workDir, File file) { final String filePath = file.getPath(); final String workDirPath = workDir.getPath(); if (filePath.length() <= workDirPath.length() || filePath.charAt(workDirPath.length()) != File.separatorChar || !filePath.startsWith(workDirPath)) { File absWd = workDir.isAbsolute() ? workDir : workDir.getAbsoluteFile(); File absFile = file.isAbsolute() ? file : file.getAbsoluteFile(); if (absWd == workDir && absFile == file) return ""; //$NON-NLS-1$ return stripWorkDir(absWd, absFile); } String relName = filePath.substring(workDirPath.length() + 1); if (File.separatorChar != '/') relName = relName.replace(File.separatorChar, '/'); return relName; }
private String makeRepoRelative(IResource res) { return stripWorkDir(repository.getWorkTree(), res.getLocation() .toFile()); }
private String makeRepoRelative(Repository repository, IResource res) { return stripWorkDir(repository.getWorkTree(), res.getLocation() .toFile()); }
private String makeRepoRelative(IResource res) { return stripWorkDir(repository.getWorkTree(), res.getLocation() .toFile()); }
/** * Strip work dir and return normalized repository path. * * @param workDir * Work dir * @param file * File whose path shall be stripped of its workdir * @return normalized repository relative path or the empty string if the * file is not relative to the work directory. */ @NonNull public static String stripWorkDir(File workDir, File file) { final String filePath = file.getPath(); final String workDirPath = workDir.getPath(); if (filePath.length() <= workDirPath.length() || filePath.charAt(workDirPath.length()) != File.separatorChar || !filePath.startsWith(workDirPath)) { File absWd = workDir.isAbsolute() ? workDir : workDir.getAbsoluteFile(); File absFile = file.isAbsolute() ? file : file.getAbsoluteFile(); if (absWd == workDir && absFile == file) return ""; //$NON-NLS-1$ return stripWorkDir(absWd, absFile); } String relName = filePath.substring(workDirPath.length() + 1); if (File.separatorChar != '/') relName = relName.replace(File.separatorChar, '/'); return relName; }
/** * Returns specific instance of {@link GitCompareInput} for particular * compare input. * * @param baseData * @param remoteData * @param ancestorData * @return Git specific {@link ICompareInput} */ protected GitCompareInput getCompareInput(ComparisonDataSource baseData, ComparisonDataSource remoteData, ComparisonDataSource ancestorData) { String gitPath = Repository.stripWorkDir(repo.getWorkTree(), path.toFile()); return new GitCompareInput(repo, ancestorData, baseData, remoteData, gitPath); }
@Override protected GitCompareInput getCompareInput(ComparisonDataSource baseData, ComparisonDataSource remoteData, ComparisonDataSource ancestorData) { String gitPath = Repository.stripWorkDir(repo.getWorkTree(), path.toFile()); return new GitCacheCompareInput(repo, (IFile) getResource(), ancestorData, baseData, remoteData, gitPath); }
/** * @return The path to the commit edit message file relative to the * repository's work tree, or null if the repository is bare. */ private String getCommitEditMessageFilePath() { File gitDir = getRepository().getDirectory(); if (gitDir == null) { return null; } return Repository.stripWorkDir(getRepository().getWorkTree(), new File( gitDir, Constants.COMMIT_EDITMSG)); }
/** * @return The path to the commit edit message file relative to the * repository's work tree, or null if the repository is bare. */ private String getCommitEditMessageFilePath() { File gitDir = getRepository().getDirectory(); if (gitDir == null) { return null; } return Repository.stripWorkDir(getRepository().getWorkTree(), new File( gitDir, Constants.COMMIT_EDITMSG)); }
public boolean revertChanges(Log log, List<File> changedFiles) throws MojoExecutionException { if (hasReverted) { return true; } boolean hasErrors = false; File workTree = workingDir(); for (File changedFile : changedFiles) { try { String pathRelativeToWorkingTree = Repository.stripWorkDir(workTree, changedFile); git.checkout().addPath(pathRelativeToWorkingTree).call(); } catch (Exception e) { hasErrors = true; log.error("Unable to revert changes to " + changedFile + " - you may need to manually revert this file. Error was: " + e.getMessage()); } } hasReverted = true; return !hasErrors; }
if (node.getType() == RepositoryTreeNodeType.REPO) { Repository parent = node.getParent().getRepository(); String path = Repository.stripWorkDir(parent.getWorkTree(), node.getRepository().getWorkTree()); List<String> paths = repoPaths.get(parent);
private boolean isTracked(File file, Repository repo) throws IOException { ObjectId objectId = repo.resolve(Constants.HEAD); RevTree tree; if (objectId != null) tree = new RevWalk(repo).parseTree(objectId); else tree = null; TreeWalk treeWalk = new TreeWalk(repo); treeWalk.setRecursive(true); if (tree != null) treeWalk.addTree(tree); else treeWalk.addTree(new EmptyTreeIterator()); treeWalk.addTree(new DirCacheIterator(repo.readDirCache())); treeWalk.setFilter(PathFilterGroup.createFromStrings(Collections.singleton( Repository.stripWorkDir(repo.getWorkTree(), file)))); return treeWalk.next(); }
StyledString string = new StyledString(); Repository repository = (Repository) node.getObject(); String path = Repository.stripWorkDir(node.getParent().getRepository() .getWorkTree(), repository.getWorkTree()); string.append(path);