GitScmProvider extends ScmProvider { @Override public Path relativePathFromScmRoot(Path path) { RepositoryBuilder builder = getVerifiedRepositoryBuilder(path); return builder.getGitDir().toPath().getParent().relativize(path); } GitScmProvider(JGitBlameCommand jgitBlameCommand, AnalysisWarnings analysisWarnings, GitIgnoreCommand gitIgnoreCommand, System2 system2); @Override GitIgnoreCommand ignoreCommand(); @Override String key(); @Override boolean supports(File baseDir); @Override BlameCommand blameCommand(); @CheckForNull @Override Set<Path> branchChangedFiles(String targetBranchName, Path rootBaseDir); @CheckForNull @Override Map<Path, Set<Integer>> branchChangedLines(String targetBranchName, Path projectBaseDir, Set<Path> changedFiles); @CheckForNull Instant forkDate(String referenceBranchName, Path projectBaseDir); @Override Path relativePathFromScmRoot(Path path); @Override @CheckForNull String revisionId(Path path);  }
@Test public void relativePathFromScmRoot_should_return_dot_project_root() { assertThat(newGitScmProvider().relativePathFromScmRoot(worktree)).isEqualTo(Paths.get("")); }
@Test public void relativePathFromScmRoot_should_return_filename_for_file_in_project_root() throws IOException { Path filename = Paths.get("somefile.xoo"); Path path = worktree.resolve(filename); Files.createFile(path); assertThat(newGitScmProvider().relativePathFromScmRoot(path)).isEqualTo(filename); }
@Test public void relativePathFromScmRoot_should_return_relative_path_for_file_in_project_subdir() throws IOException { Path relpath = Paths.get("sub/dir/to/somefile.xoo"); Path path = worktree.resolve(relpath); Files.createDirectories(path.getParent()); Files.createFile(path); assertThat(newGitScmProvider().relativePathFromScmRoot(path)).isEqualTo(relpath); }