Java Code Examples for org.eclipse.jgit.lib.Repository#stripWorkDir()

The following examples show how to use org.eclipse.jgit.lib.Repository#stripWorkDir() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Reactor.java    From multi-module-maven-release-plugin with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: LocalGitRepo.java    From multi-module-maven-release-plugin with MIT License 6 votes vote down vote up
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;
}