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

      if (isDiffAlgoInvalid(repo.getConfig())) {
        // we already print a warning when branchChangedFiles is called
        return null;
      }

      // force ignore different line endings when comparing a commit with the workspace
      repo.getConfig().setBoolean("core", null, "autocrlf", true);

      Optional<RevCommit> mergeBaseCommit = findMergeBase(repo, targetRef);

      if (mergeBaseCommit.isEmpty()) {
        LOG.warn(composeNoMergeBaseFoundWarning(targetRef.getName()));
        return null;
      }

      Map<Path, Set<Integer>> changedLines = new HashMap<>();

      for (Map.Entry<Path, ChangedFile> entry : changedFiles.entrySet()) {
        collectChangedLines(repo, mergeBaseCommit.get(), changedLines, entry.getKey(), entry.getValue());
      }

      return changedLines;
    } catch (Exception e) {
      LOG.warn("Failed to get changed lines from git", e);
    }

    return null;
  }
@Test
  public void branchChangedLinesWithFileMovementDetection_detects_modified_lines_on_renamed_pr_files_compared_to_original_files_on_target_branch()
    throws GitAPIException, IOException {
    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, 2);
    commit(fileM1);

    editLineOfFile(fileM2, 1);
    commit(fileM2);

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

    Map<Path, ChangedFile> changedFiles = Map.of(
      newFileM1AbsolutPath, ChangedFile.of(newFileM1AbsolutPath, fileM1),
      newFileM2AbsolutPath, ChangedFile.of(newFileM2AbsolutPath, fileM2)
    );

    Map<Path, Set<Integer>> changedLines = newScmProvider().branchChangedLinesWithFileMovementDetection("master",
      worktree.resolve("project1"), changedFiles);

    assertThat(changedLines)
      .containsOnly(
        entry(newFileM1AbsolutPath, Set.of(2)),
        entry(newFileM2AbsolutPath, Set.of(1))
      );
  }