rules: changes is triggering in merge request pipelines when a matching file is changed but then changed back
## Summary
`rules: changes` is triggering in merge request pipelines when a matching file is changed but then changed back.
## Problem
- I make a branch and MR, with a job containing `rules: changes: ["my_file.txt"]`
- I make commits that do not change `my_file.txt`. The job **does not** run (as expected).
- I make a commit changing `my_file.txt`. The job **does** run (as expected).
- I make another commit _undoing_ the change to `my_file.txt`. The job **does** run still (_unexpected!_)
This behavior is unexpected because [the documentation](https://docs.gitlab.com/ci/yaml/#rules) clearly states:
> Merge request pipelines, rules:changes compares the changes with the target MR branch.
### Current workarounds and why they fall short
A solution I've found for this problem is to simply use `compare_to: $CI_MERGE_REQUEST_TARGET_BRANCH`.
However, this fall short because it shouldn't be necessary. [The documentation](https://docs.gitlab.com/ci/yaml/#rules) clearly states:
> Merge request pipelines, rules:changes compares the changes with the target MR branch.
### Example jobs
Here is an example job definition in `.gitlab-ci.yml` that reproduces the issue:
```yaml
rules-changes-test:
script:
- echo "foo bar"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- my_file.txt
```
And here's how the issue can be "fixed":
```yaml
rules-changes-test:
script:
- echo "foo bar"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
paths:
- my_file.txt
compare_to: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
```
## Expected Behavior
I expect that using `compare_to: $CI_MERGE_REQUEST_TARGET_BRANCH` and not using `compare_to` at all should be equivalent.
## Proposed Solutions
- Fix `rules: changes` when not using `compare_to` so that it behaves as expected
- Fix the documentation to state clearly and accurately how the `diff` used by `rules: changes` is computed
- Provide a `$CI_` environment variable that lists the files in the diff (currently a full diff is available through the API, however this is more than desired and inconvenient to get).
## Environment
- GitLab.com (SaaS)
- Affects any project using `rules: changes` without `compare_to` in
## Links
- https://docs.gitlab.com/ci/yaml/#rules
issue