I would like to get a list of changed files given the source and the target branch of a merge request.
This command works perfectly fine when run locally:
git --no-pager diff --name-only feature-branch...dev
It returns exactly what it is shown in the merge request “changes” tab in the UI.
When executing it on the GitLab CI, I get this error instead:
fatal: ambiguous argument 'feature-branch...dev': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
This is the .gitlab-ci.yml file:
my-job:
script:
- git --no-pager diff --name-only "${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}"..."${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
only:
- merge_requests
EDIT:
If I fetch both the remote and the target branch, I get way more changed files that it is shown in the UI:
my-job:
script:
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME:$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- git --no-pager diff --name-only "${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}"..."${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
only:
- merge_requests