0

I'm trying to get a list of the files that are different between the branch in execution of the Gitlab CI pipeline, and the ones on remote origin (called main).

I understand that when the gitlab CI pipeline runs, it does a clone of the specific branch, and it looks like it strips away all of the remote origins and branches?

So I do a git fetch to retrieve the remote branches, which nets me main (origin/main)

But from there I've tried every combination of git diff, git diff-tree, git diff merge-base, and I'm just getting nowhere, and fried.

Anyone got any tips?

DavisTasar
  • 245
  • 1
  • 4
  • 14
  • Can you explain more precisely what you mean by "a list of the files that are different between the branch in execution of the Gitlab CI pipeline, and the ones on remote origin (called main)" ? – LeGEC Apr 09 '21 at 22:43
  • Your CI system is probably set up to make a single-branch, shallow clone. This means you simply don't have the other commits. Using `git fetch` you can paper over the problem but you should also consider changing your CI system to use a full clone. There are tradeoffs however you do this. – torek Apr 10 '21 at 00:57
  • @torek, that's actually what I did, git fetch to resolve the shallow clone. Gitlab CI apparently when it creates the pipeline doesn't do a full clone that I've found. So, I added git fetch at the top of my pipeline statements. – DavisTasar Apr 10 '21 at 15:23
  • @LeGEC, Basically my end goal is to get a list of files that have been changed in this branch, as compared to the main branch that's in production. – DavisTasar Apr 10 '21 at 15:23
  • 1
    You can undo a shallow-and-single-branch clone but it takes more than just one `git fetch`: see [How do I “undo” a --single-branch clone?](https://stackoverflow.com/q/17714159/1256452). That's why I suggest finding a way to make the CI system do a full clone in the first place: that might be simpler. – torek Apr 10 '21 at 15:26
  • Good to know. According to the docs: > To disable shallow clone and make GitLab CI/CD fetch all branches and tags each time, keep the value empty or set to 0. – DavisTasar Apr 10 '21 at 20:36

1 Answers1

1

I don't understand the precise meaning of your definition, but I think you are looking either for :

git diff --name-only origin/main HEAD

or for :

git diff --name-only origin/main...HEAD # 3 dots

and perhaps for --name-status instead of --name-only

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Generally speaking, "difference between" is definitely your first option. The second one is something else, something like "the difference between HEAD and the revision from which it was branched off of in the "origin/head" branch. Maybe in this case they produce the same results, but using the first one is semantically more correct even so. – CryptoFool Apr 09 '21 at 22:56
  • I'll give this one a shot, it's hard to remember the specifics of what I've tried. Because I might be able to do a git fetch to resolve the shallow clone, and do the git diff that way, since the local branch thinks it's the head? – DavisTasar Apr 10 '21 at 15:24
  • Okay, so follow-up on this for anyone searching. @LeGEC is correct. The piece that was missing was the comment about removing the shallow clones. Once I did that, and used the second line, I got _exactly_ what I needed. Thank you! – DavisTasar Apr 12 '21 at 13:47