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:
Squashed commit on branch test-1
containing original commit in the commit message:
Imported MR on GitLab:
- 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 |
---|---|
How to set up and validate locally
- Start a bitbucket server docker instance locally:
- 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
- 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
- Go to the project imports page and select Bitbucket Server and follow the steps to configure
- Create a project + repo on bitbucket. Create/Enable a merge strategy for "Squash" in Settings > Merge Strategies
- 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.
- Checkout master:
git checkout master
- Import the project into gitlab and note that the MR doesn't have any commits or diffs.
- Checkout this branch:
git checkout 356240-find-commits-on-target-branch
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #356240 (closed)