This will make the local reference of master point to the HEAD of branch1 before checking out branch1.
The first command should probably be simply git reset --hard or a git clean -fd (just to ensure that the checkout following it will succeed).
It creates problems when running SonarCloud analysis, as the scanner will be tricked into thinking that there are no changes in the current branch compared to master:
I am experimenting with using a manual near-identical version of the circle-ci “checkout” step, removing the line that results in the master branch being reset --hard onto the $CIRCLE_SHA1
It is, and I’ve pretty much no idea what it is doing! If I had a need to do a custom checkout, then writing my own Git calls - and understanding what they do - would be my approach.
Apologies for this issue lingering for so long. Our team recently got enough bandwidth that I had time to look into our checkout step implementations (there is actually more than one).
Also, as it was developed in the earlier more fast moving days of the company, the test coverage of this part of our build-agent was not as good as it could be. Changing the behaviour of something as mission-critical to the platform as this, with millions of different combinations of Docker image / Git version / etc running through the system is highly challenging and risky.
Anyway, long story short, I spent a few days cranking out many test scenarios to cover the various features the checkout step actually contains, and felt in a good place after this to start trying to fix issues like this. After a staged rollout and a few more regression tests for “unexpected” features. This culminated in a fairly substantial change to the script.
I believe we have covered this scenario now, as well as several others, and I hope this long-standing issue is resolved for you all.
@pete-woods thanks for this fix. One thing I noticed and just reported to support is that on branches where we delete a file, the circleci git checkout implementation seems to magically restore that file (tested via ls after checkout), causing us to test the wrong code.
Not sure if it’s related to this rewrite but thought I’d surface.