Skip to content

Bitbucket: Find squashed commits by message on target branch

What does this MR do and why?

Adds on Fix BitBucket Server Importer: Changes Missing ... (!131894 - merged) which attempts to find a commit imported from Bitbucket Server in commit messages by passing the target branch as the ref. This is to find commits which have been squashed and merged into a non-default branch. Currently, an MR that targets a non-default branch which is squashed and merged does not show a diff when imported into Gitlab.

MR on Bitbucket:

Screenshot 2023-10-02 at 09.33.14.png

Squashed commit on branch test-1 containing original commit in the commit message:

Screenshot 2023-10-02 at 09.35.17.png

Imported MR on GitLab:

Screenshot_2023-10-02_at_09.30.40

  • Original commit on Bitbucket: 1c1a2f7ea9d48d83822dd5f18d4307b156156841
  • Squashed commit on Bitbucket on branch test-1: 35d1e85f94ea9d7c78576f881b2c75759ba94cc8
  • Finding original commit on gitlab: project.repository.commit("1c1a2f7ea9d48d83822dd5f18d4307b156156841") => nil
  • Finding original commit via message without passing a ref: project.repository.find_commits_by_message("1c1a2f7ea9d48d83822dd5f18d4307b156156841")&.first&.sha => nil
  • Finding original commit via message with passing the target branch as ref: project.repository.find_commits_by_message("1c1a2f7ea9d48d83822dd5f18d4307b156156841", "test-1")&.first&.sha => "35d1e85f94ea9d7c78576f881b2c75759ba94cc8"

Therefore, by passing the target branch to the find_commits_by_message method, we are able to find squashed commits merged to any branch, not just the default branch.

Screenshots or screen recordings

Before After
Screenshot_2023-10-02_at_09.30.40 Screenshot_2023-10-02_at_09.26.25

How to set up and validate locally

  1. Start a bitbucket server docker instance locally:
    1. https://gitlab.com/gitlab-org/manage/import-and-integrate/team/-/blob/main/integrations/bitbucket_server.md#set-up-local-bitbucket-instance-from-the-official-dockerhub-image
    2. Note: I had to bump the amount of memory and CPU to 4 CPUs and 4GB memory otherwise the process exits. You can monitor usage by running docker stats
  2. Go to the project imports page and select Bitbucket Server and follow the steps to configure
  3. Create a project + repo on bitbucket. Create/Enable a merge strategy for "Squash" in Settings > Merge Strategies
  4. Push two branches with changes and create an MR to merge the one branch into the other. Merge the MR with the Squash strategy & Delete the source branch.
  5. Checkout master: git checkout master
  6. Import the project into gitlab and note that the MR doesn't have any commits or diffs.
  7. Checkout this branch: git checkout 356240-find-commits-on-target-branch
  8. Import the project again and note that the MR has the commits and diffs now.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #356240 (closed)

Edited by Madelein van Niekerk

Merge request reports