diff --git a/gitlab/v4/objects/repositories.py b/gitlab/v4/objects/repositories.py index 5a56a2d65..60bcf59bd 100644 --- a/gitlab/v4/objects/repositories.py +++ b/gitlab/v4/objects/repositories.py @@ -135,6 +135,26 @@ def repository_compare(self, from_, to, **kwargs): query_data = {"from": from_, "to": to} return self.manager.gitlab.http_get(path, query_data=query_data, **kwargs) + @cli.register_custom_action("Project", ("from_", "to")) + @exc.on_http_error(exc.GitlabGetError) + def merge_base(self, from_, to, **kwargs): + """Return a diff between two branches/commits. + + Args: + from_(str): Source branch/SHA + to(str): Destination branch/SHA + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabGetError: If the server failed to perform the request + + Returns: + str: The diff + """ + path = f'/projects/{self.get_id()}/repository/merge_base?refs[]={from_}&refs[]={to}' + return self.manager.gitlab.http_get(path, **kwargs) + @cli.register_custom_action("Project") @exc.on_http_error(exc.GitlabGetError) def repository_contributors(self, **kwargs):