Error:
"Pull request cannot be automatically merged."
Further investigation shows:
UserAgent TFS JobAgent(TfsJobAgent.exe, 15.117.26714.0)
ExceptionType LibGit2Sharp.LibGit2SharpException
Message LibGit2Sharp.LibGit2SharpException: TF401022: By policy, the Git object '49c782016d305ee3d24f8a98fd549d815fc1ceb5' is too large to materialize into memory. Its size, 202478760, exceeds the threshold of 104857600 bytes. at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) at LibGit2Sharp.Core.Proxy.git_merge_commits(RepositoryHandle repo, ObjectHandle ourCommit, ObjectHandle theirCommit, GitMergeOpts opts, Boolean& earlyStop) at LibGit2Sharp.ObjectDatabase.MergeCommits(Commit ours, Commit theirs, MergeTreeOptions options) at Microsoft.TeamFoundation.Git.Server.Native.LibGit2NativeLibrary.CreateMergeWithConflictTracking(Sha1Id mergeSourceCommitId, Sha1Id mergeTargetCommitId, CommitDetails commitDetails, Boolean findRenames, Int32 renameThreshold, Int32 targetLimit, IEnumerable`1 parentIdsForMergeCommit, CustomerIntelligenceData ciData)
1) Create side branch from master
2) Rename file with size >100Mb in master
3) Try to merge side to master
This is an issue in _Team Foundation Server_. As such, you need to report this to Microsoft. They support your installation, we do not.
In this _particular_ issue, TFS doesn't support automerging files greater than 100 megabytes. This is by-design, as part of TFS and VSTS. There's simply nothing that we can do about it. You need to merge your pull request manually, which is why it's telling you that it can't be automatically merged.
But even if this _was_ a bug in LibGit2Sharp, or in libgit2 - and it's not - you would _still_ need to report this to Microsoft. Microsoft controls the delivery of their software to you - we do not. (We could have fixed this and they haven't updated their version, and we may need to work with them to investigate the problem.)
So I'm closing this - and if you think this is a problem, or you have _any_ problem using TFS and VSTS, please use Microsoft's support channels.
Thanks!
But this is definetely bug in your library.
I already report about in Microsoft, but without your fix they can't do anything.
If you fix it, I can build .dll and replace it in TFS.
No, it is not a bug in the library. The library absolutely supports merging large files. You can feel free to try it out and see.
This is a limitation in TFS: it is not a bug in TFS, it is _by design_. Trying to merge very large files could exhaust memory and lead to a denial of service attack. It is explicitly disabled. I can assure you that this is true, because _I added this limitation to TFS_.
Ok, but why your library try to allocate in memory files that was modified in another branch before merge?
Not _before_ merge, this is _part_ of the merge. (TFS is actually _doing_ a merge, computing the new tree, in order to know whether your pull request can be merged automatically or not.)
When you do a merge in libgit2 (and LibGit2Sharp), then files need to be read to compute the resultant merge:
If you change some file in both branches, then the library will need to read the file in each branch (and the common ancestor) in order to compute the automerged file.
If you enable rename detection during merge then the library will need to read files that were added or deleted in any branch to determine if they were renames. If you enable rename detection and allow rewrites to count as rename candidates, then any file changed in any branch will need to read to consider renames.
Thank you very much, Edward! Your answer was detailed and precise.
@rerime I now that it's not related to this ticket itself, but how did you managed to read the error of the TfsJobAgent with the exception and the callstack? I have the same error message "Pull request cannot be automatically merged." but didn't succeed to understand what happens...
Most helpful comment
No, it is not a bug in the library. The library absolutely supports merging large files. You can feel free to try it out and see.
This is a limitation in TFS: it is not a bug in TFS, it is _by design_. Trying to merge very large files could exhaust memory and lead to a denial of service attack. It is explicitly disabled. I can assure you that this is true, because _I added this limitation to TFS_.