Fix rules:changes net diff for reverted files in MR pipelines

What does this MR do and why?

Fixes rules:changes firing for files that were changed and then reverted within an MR (when compare_to isn't set).

  • MergeRequest#changed_paths used to union the changes from every commit in the MR, so a file touched in one commit and reverted in another stayed "changed" forever and kept triggering rules:changes
  • Now it computes a single net tree diff between the MR's base and head (FindChangedPaths with a base..head tree pair), so reverted files cancel out. This matches the documented behavior and the existing compare_to path
  • Still uses the same git-diff-tree Gitaly RPC, so it's not subject to diff display limits (keeps the #433257 (closed) fix intact) and doesn't go back to the slow diff_stats path.
  • Behind the mr_changed_paths_net_diff feature flag

References

Relates to #597640

How to set up and validate locally

  1. Turn :mr_changed_paths_net_diff feature on
  2. In a test project, create my_file.txt on master.
  3. Add .gitlab-ci.yml:
rules-changes-test:
  script: echo "foo bar"
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      changes: [my_file.txt]
  1. Branch off, open an MR, then push a commit changing my_file.txt, then a commit reverting it to the original content.
    1. The latest MR pipeline should not contain rules-changes-test.
  2. Turn feature off and retest, the job shows up

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #597640

Edited by Tarun Raja

Merge request reports

Loading