Git Clone Repository step results in problematic local branch states

The problem:
There is an option to define if the Git Clone Repository step should merge the PR’s source and destination to validate the code state as it will be after the PR merge.
We prefer to have that option set to “yes” as we find this verification very useful.
Currently, the Git Clone Repository step merges the source branch into the destination branch. However, it is also possible to do the opposite - merge the destination into the source branch. Are there any benefits to the first approach?
Although the resulting code should be the same, the problem is the machine’s local destination branch - after the merge, it has the same code as the source branch. When using code analysis tools that analyze differences between source and destination branch in a PR, to that tool, the source and the destination will look the same.
In our case, we have an integration with Sonarqube in PR checks. Sonarqube analyses destination and source branches and compares the differences. Because of Git Clone Repository step behavior (merging source into destination), the destination branch has the same code as the source branch, so there is always no difference. As a result, Sonar always reports success in the PR decoration, as it thinks there were no changes in the PR.

What is the benefit of merging the source branch into the destination, as opposed to merging the destination branch into the source?

Proposal:
Could you introduce an option to merge branches the other way around?
Merging the destination branch into the source branch would produce the same code while keeping the destination branch unaffected. Because of that, tools would be able to compare the branches and detect the changes in the PR.

2 Likes

We implemented our own git clone step as a workaround and this works fine. However, I think it makes sense for this to be fixed in the actual Git Clone Repository step too, so I’d like some feedback from your end.

I have the same problem! I implemented a custom clone script step, but it would be great if this could be an option in Git Clone Repository step so we don’t have to maintain our step just because of that.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

You can disable the merge to destination branch in the Git Clone step

Hi @damien.murphy ,
Thanks for the suggestion. However, as I mentioned in the original post, we do prefer to have this option selected as it is useful to verify the merged code rather than just the branch.

I see thanks for the clarification.

You could achieve this by disabling the auto merge on the Git Clone step and running the git merge in a script step after the checkout to meet your needs as a workaround.

Thanks, that is indeed the workaround we’re currently using. That being said, I don’t see a reason why the merge would have to happen in the current direction, so I think it’s a valid feature request to have it as an option. We can keep using our custom script, but of course, it is always nicer to use an official step that is actively maintained.