diff --git a/hgitaly/service/commit.py b/hgitaly/service/commit.py index d2f4bb85e3f9afcdabdee910b292bfafd2bb8fa1_aGdpdGFseS9zZXJ2aWNlL2NvbW1pdC5weQ==..946f4e3e5c5bc8a00e371cda31e375d155c68699_aGdpdGFseS9zZXJ2aWNlL2NvbW1pdC5weQ== 100644 --- a/hgitaly/service/commit.py +++ b/hgitaly/service/commit.py @@ -13,6 +13,7 @@ from mercurial.utils import stringutil as hg_stringutil from google.protobuf.timestamp_pb2 import Timestamp +from hgext3rd.heptapod.branch import get_default_gitlab_branch # TODO move that to heptapod.gitlab from hgext3rd.heptapod.git import parse_gitlab_branch @@ -95,6 +96,8 @@ repo = self.load_repo(request.repository) revision = request.revision logger.debug("FindCommit revision=%r", revision) + if revision == b'HEAD': + revision = get_default_gitlab_branch(revision) try: branchmap_key = gitlab_branch_to_branchmap_branch(revision) if branchmap_key is None: diff --git a/hgitaly/tests/test_commit.py b/hgitaly/tests/test_commit.py index d2f4bb85e3f9afcdabdee910b292bfafd2bb8fa1_aGdpdGFseS90ZXN0cy90ZXN0X2NvbW1pdC5weQ==..946f4e3e5c5bc8a00e371cda31e375d155c68699_aGdpdGFseS90ZXN0cy90ZXN0X2NvbW1pdC5weQ== 100644 --- a/hgitaly/tests/test_commit.py +++ b/hgitaly/tests/test_commit.py @@ -6,6 +6,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import time from heptapod.testhelpers import LocalRepoWrapper +from hgext3rd.heptapod.branch import set_default_gitlab_branch from ..stub.commit_pb2 import FindCommitRequest from ..stub.commit_pb2_grpc import CommitServiceStub @@ -60,6 +61,10 @@ response = grpc_stub.FindCommit(request) assert response.commit == commit2 + # default GitLab branch not being set, it fallbacks on branch/default + request = FindCommitRequest(repository=grpc_repo, revision=b'HEAD') + assert response.commit == commit2 + wrapper.write_commit('animals', message="in topic", topic='antelope', @@ -72,6 +77,11 @@ assert commit_top is not None assert commit_top.subject == b"in topic" + # with explicitely set GitLab branch: + set_default_gitlab_branch(wrapper.repo, b'topic/default/antelope') + request = FindCommitRequest(repository=grpc_repo, revision=b'HEAD') + assert response.commit == commit_top + request = FindCommitRequest(repository=grpc_repo, revision=b'unknown') response = grpc_stub.FindCommit(request) assert not response.HasField('commit')