GitLab CI: Checkout only in merge request changed files

Hi!

I have a GitLab Linter CI job. It looks like this.

lint_puppet:
  image: "ruby:latest"
  stage: lint
  script:
    - gem install puppet-lint
    - puppet-lint $CI_PROJECT_DIR

The problem is: I just want to test new code. Is there a way to check out only changed files? I searched for it, but didn’t find anything concrete (probably I’m searching wrong).

Thanks,
Markus

Now I solved it that way:

lint_puppet:
  image: "ruby:latest"
  stage: lint
  script:
    - apt update && apt -y install rsync git
    - gem install puppet-lint
    - git clone -b master --single-branch --depth=1 https://gitlab-ci-token:${CI_JOB_TOKEN}@git.example.com/org/project.git /tmp/targetbranch
    - mkdir -p /tmp/output
    - rsync -rcn --out-format="%n" --exclude=".git" . /tmp/targetbranch | grep \.pp | while read varname; do cp --parents $varname /tmp/output; done || exit 0
    - puppet-lint /tmp/output

Could you do something like this:

rsync -avx $(git diff --name-only master) /tmp/targetbranch

to make it a bit simpler?