3

I am working with gitlab. I have a yml file which runs the git command diff. This command shows the difference between the two branches. here is the yml file

image: bitnami/git:latest stages: - Test Test_stage: tags: - docker stage: Test script: - echo "test stage started" - git diff --color=always origin/main..pipeline_creation README.md | perl -wlne 'print $1 if /^\e\[32m\+\e\[m\e\[32m(.*)\e\[m$/' 

when i run this in the pipeline i am getting this error:

Created fresh repository. Checking out e33fa512 as pipeline_creation... Skipping Git submodules setup Executing "step_script" stage of the job script 00:00 $ echo "test stage started" test stage started $ git branch -a * (HEAD detached at e33fa51) remotes/origin/pipeline_creation $ git diff main..pipeline_creation README.md fatal: ambiguous argument 'main..pipeline_creation': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' 

Locally the command is working fine but when I run it in pipeline its not showing the expected result. Does someone know what am i doing wrong here?

3
  • Since pipeline_creation seems to be the branch that is checked out, are you sure your repo for the job contains a origin/main? What is the output if you use the syntax without the "..", like git diff --color=always origin/main pipeline_creation README.md? Commented Nov 30, 2022 at 12:12
  • still getting the same error. Used git diff main..pipeline_creation README.md Commented Nov 30, 2022 at 12:15
  • 1
    i have updated the output with git branch -a Commented Nov 30, 2022 at 12:17

1 Answer 1

6

The output of git branch -a shows the cause of the problem: The repo does not have any local branches and it only has one remote branch remotes/origin/pipeline_creation. You need to fetch the main branch first before you can use it in the git diff command:

git fetch --depth=1 origin main 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.