Skip to content

Checkout + reset confuses SonarQube #159

@sandro-h

Description

@sandro-h

Current state

The PR plugin checks out a pull request the following way:

  • Checkout (clone) the master (or default) branch
  • git reset --hard it to the pull request revision

This is causing issues with at least one tool that relies on a reasonable git state: SonarQube. It expects a pull request to be checked out in a separate branch (ideally the PR source branch) and the master to be untouched. See this Sonar community thread where the same issue was observed (and fixed) in CircleCI.

Suggested fix

The plugin could create a local branch first, and then reset that to the pull request revision. This way master remains untouched. I realize depending on Provider (github, gitlab, bitbucket), we don't know the real source branch name, but even just a dummy branch name would fix the problem.

I created a proof of concept here: adnovum@84b46fb

Would you be willing to accept such a change in the form of a pull-request? I see the following open points:

  • The git-cmd library doesn't support creating a new branch, so there's a bit too much boilerplate in the change right now.
  • It uses a dummy branch name gocd-pr/<PR_ID>. This is good enough for us, since we use Bitbucket whose provider doesn't know the source branch anyway. But if you insist, I can make further adjustments to use the source branch if available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions