Skip to content

Ignore merge commits when performing diff checks

Joe Woodward requested to merge fix/lfs-locking into master

What does this MR do and why?

  1. Ignores merge commits when performing diff checks
  2. Cleans up the diff check classes

Before this change, attempting to push files locked in LFS or by Path Locks would result in the diff checks failing incorrectly. This happens when 2 users are working on the same branch and

User 1 and 2 are both working on a branch named foo_bar User 1 creates commit 1 with file1.lfs User 1 locks file1.lfs User 1 pushes commit 1 to origin/foo_bar User 2 creates commit 2 with file2.lfs User 2 locks file2.lfs User 2 pulls origin/foo_bar which creates a new merge commit with parents [commit 2, commit 1] User 2 pushes their changes to origin/foo_bar

Previously we would find all changes including ones for merge commits. This meant that the diff check logic believe that changes from commit 1 were now being pushed even though they are coming from history.

Now we filter out all the merge commits so only changes that are not in history will be validated.

Describe in detail what your merge request does and why.

How to set up and validate locally

This is not the easiest thing to test as you need to have 2 users configured locally. You can setup hosts in your ssh config to mock 2 users. I personally created a new project lfs_locks_issue, and then cloned this in 2 directories. In the first directory I set the origin remote to gdk.test:3000 and in the second I used the custom host I setup in ssh hosts. Example of how to configure this can be seen here

Once you have configured multiple users you need to install lfs if you haven't already done so. Configure lfs to track *.lfs files with git lfs track "*.lfs". This will update .gitattributes.

Now LFS is configured we can setup the commits.

As user 1:

git checkout -b lfs-lock-issue
echo 'test' > file1.lfs
git add .
git commit -m 'file 1'
git lfs lock file1.lfs
git push origin/lfs-lock-issue

As user 2:

git checkout -b lfs-lock-issue
echo 'test' > file2.lfs
git add .
git commit -m 'file 2'
git lfs lock file2.lfs
git pull origin lfs-lock-issue
# Save message for merge commit
git push origin lfs-lock-issue

This should work successfully.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports