@CheckForNull
  public Set<ChangedFile> branchChangedFilesWithFileMovementDetection(String targetBranchName, Path rootBaseDir) {
    try (Repository repo = buildRepo(rootBaseDir)) {
      Ref targetRef = resolveTargetRef(targetBranchName, repo);
      if (targetRef == null) {
        addWarningTargetNotFound(targetBranchName);
        return null;
      }

      if (isDiffAlgoInvalid(repo.getConfig())) {
        LOG.warn("The diff algorithm configured in git is not supported. "
          + "No information regarding changes in the branch will be collected, which can lead to unexpected results.");
        return null;
      }

      Optional<RevCommit> mergeBaseCommit = findMergeBase(repo, targetRef);
      if (mergeBaseCommit.isEmpty()) {
        LOG.warn(composeNoMergeBaseFoundWarning(targetRef.getName()));
        return null;
      }
      AbstractTreeIterator mergeBaseTree = prepareTreeParser(repo, mergeBaseCommit.get());

      // we compare a commit with HEAD, so no point ignoring line endings (it will be whatever is committed)
      try (Git git = newGit(repo)) {
        List<DiffEntry> diffEntries = git.diff()
          .setShowNameAndStatusOnly(true)
          .setOldTree(mergeBaseTree)
          .setNewTree(prepareNewTree(repo))
          .call();

        return computeChangedFiles(repo, diffEntries);
      }
    } catch (IOException | GitAPIException e) {
      LOG.warn(e.getMessage(), e);
    }
    return null;
  }
@Test
  public void branchChangedFilesWithFileMovementDetection_correctly_detects_several_file_moves_in_pull_request_base_branch() throws IOException, GitAPIException {
    String fileM1 = "file-m1.xoo";
    String newFileM1 = "new-file-m1.xoo";
    String fileM2 = "file-m2.xoo";
    String newFileM2 = "new-file-m2.xoo";

    Path newFileM1AbsolutPath = worktree.resolve(newFileM1);
    Path newFileM2AbsolutPath = worktree.resolve(newFileM2);

    createAndCommitFile(fileM1);
    createAndCommitFile(fileM2);

    createBranch();

    editLineOfFile(fileM1, 1);
    commit(fileM1);

    moveAndCommitFile(fileM1, newFileM1);
    moveAndCommitFile(fileM2, newFileM2);

    assertThat(newScmProvider().branchChangedFilesWithFileMovementDetection("master", worktree))
      .extracting(ChangedFile::getAbsolutFilePath, ChangedFile::getOldRelativeFilePathReference)
      .containsExactlyInAnyOrder(
        tuple(newFileM1AbsolutPath, fileM1),
        tuple(newFileM2AbsolutPath, fileM2)
      );
  }