Make MergeBranch RPC idempotent
From gitlab#233090 (comment 392902318), right now if you run MergeBranch twice in a row, it will create two merge commits with the latter being empty. That doesn't happen when you do a git merge <branch> because it detects that a branch has been merged:
$ git merge sh-test-branch1
Updating 270f0a1b00b..083976d8670
Fast-forward
README.md | 1 +
1 file changed, 1 insertion(+)
$ git merge sh-test-branch1
Already up to date.
As you can see in https://gitlab.com/gitlab-org/gitaly/-/blob/300980719a82ec3b40c5d938310cebd6fc3d3c37/ruby/lib/gitlab/git/repository.rb#L300-309, we always create a merge commit no matter what.
Rugged provides a merge_analysis API that might be helpful here: https://www.rubydoc.info/github/libgit2/rugged/Rugged/Repository#merge_analysis-instance_method. If we get up_to_date back before merging, do nothing.
Edited by Stan Hu