本文整理了Java中org.eclipse.jgit.lib.Repository.stripWorkDir
方法的一些代码示例,展示了Repository.stripWorkDir
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.stripWorkDir
方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:stripWorkDir
[英]Strip work dir and return normalized repository path.
[中]剥离工作目录并返回规范化的存储库路径。
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* 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;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* @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));
}
代码示例来源:origin: danielflower/multi-module-maven-release-plugin
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;
}
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
/**
* 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;
}
代码示例来源:origin: org.eclipse.egit/ui
private String makeRepoRelative(IResource res) {
return stripWorkDir(repository.getWorkTree(), res.getLocation()
.toFile());
}
代码示例来源:origin: org.eclipse.egit/ui
private String makeRepoRelative(Repository repository, IResource res) {
return stripWorkDir(repository.getWorkTree(), res.getLocation()
.toFile());
}
代码示例来源:origin: org.eclipse.egit/ui
private String makeRepoRelative(IResource res) {
return stripWorkDir(repository.getWorkTree(), res.getLocation()
.toFile());
}
代码示例来源:origin: berlam/github-bucket
/**
* 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;
}
代码示例来源:origin: org.eclipse.egit/ui
/**
* 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);
}
代码示例来源:origin: org.eclipse.egit/ui
@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);
}
代码示例来源:origin: berlam/github-bucket
/**
* @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));
}
代码示例来源:origin: sonia.jgit/org.eclipse.jgit
/**
* @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));
}
代码示例来源:origin: danielflower/multi-module-maven-release-plugin
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;
}
代码示例来源:origin: org.eclipse.egit/ui
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);
代码示例来源:origin: org.eclipse.egit/ui
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();
}
代码示例来源:origin: org.eclipse.egit/ui
StyledString string = new StyledString();
Repository repository = (Repository) node.getObject();
String path = Repository.stripWorkDir(node.getParent().getRepository()
.getWorkTree(), repository.getWorkTree());
string.append(path);
内容来源于网络,如有侵权,请联系作者删除!