Web based conflict resolution for merges breaks git lfs pointer files
Summary
When using GitLab's interface for conflict resolution in merges, git lfs pointer files are saved without a newline at the end of the file. This causes some weird behavior with git lfs when a user pulls the merge. The file is continuously stuck in a modified state (presumably because git lfs views the pointer file as valid and the tracked asset hasn't changed, but git marks the pointer file as modified due to the lack of a newline).
Steps to reproduce
- Create a new branch, branch b, from an existing branch branch a
- In branch b change an asset, which is being tracked by git lfs, and commit the change
- In branch a change the same asset in a different way and commit the change
- In GitLab, create a merge request to merge branch b into branch a
- Use GitLab's web-based conflict resolution to resolve the conflicted file with the contents of either branch a or branch b
- Accept the merge request after resolving the conflict through GitLab
- Pull the merge to branch a from GitLab
- The previously-conflicted file will immediately be marked as modified, and the git lfs pointer file tracked by git will not contain a newline at the end of the file
- git opertaions, like switching branches, will fail due to the modified file. Even a git revert will fail.
Expected behavior
The merge should've succeeded (one of the two valid git lfs pointer files was chosen in the merge) and team members pulling the merge from the GitLab server should be able to immediately begin working with the changes using a regular git workflow.
Actual behavior
The previously-conflicted file will immediately be marked as modified, and the git lfs pointer file tracked by git will not contain a newline at the end of the file. Git operations, like switching branches, will fail due to the modified pointer file. Even a git revert will fail (once again, presumably due to a valid, but incorrectly formatted git lfs pointer file).
Relevant logs and/or screenshots
> git diff
diff --git a/Content/Menus/W_MainMenu.uasset b/Content/Menus/W_MainMenu.uasset
index 0b7432b..0a8df53 100644
--- a/Content/Menus/W_MainMenu.uasset
+++ b/Content/Menus/W_MainMenu.uasset
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:df277aa545f019664948ec4630ec6d33b886ece8baa2b9ad9a0327a4ab7881be
-size 329413
\ No newline at end of file
+size 329413
Results of GitLab application Check
Checking GitLab Shell ...
GitLab Shell version >= 4.1.1 ? ... OK (4.1.1)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
3/1 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Reply by email ...
Reply by email is disabled in config/gitlab.yml
Checking Reply by email ... Finished
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Git configured with autocrlf=input? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory setup correctly? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
projects have namespace: ...
3/1 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.1.0 ? ... yes (2.3.3)
Your git bin path is "/opt/gitlab/embedded/bin/git"
Git version >= 2.7.3 ? ... yes (2.8.4)
Active users: 14
Checking GitLab ... Finished
Results of GitLab environment info
System information
System: Ubuntu 16.04
Current User: git
Using RVM: no
Ruby Version: 2.3.3p222
Gem Version: 2.6.6
Bundler Version:1.13.7
Rake Version: 10.5.0
Sidekiq Version:4.2.7
GitLab information
Version: 8.15.4
Revision: a0b1379
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: https://gitlab.bliptic.net
HTTP Clone URL: https://gitlab.bliptic.net/some-group/some-project.git
SSH Clone URL: git@gitlab.bliptic.net:some-group/some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 4.1.1
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks/
Git: /opt/gitlab/embedded/bin/git
Possible fixes
Make sure git lfs pointer files have a newline at the end of them when performing conflict resolution through GitLab.