I wanted to have a list of changed files on the branch CI is running compared to master. Turns out that CircleCI uses hard resets when checking out so git diff master... does not work. Parsing the compare url was my next approach but it is empty when needed. I settled on git rev parse origin/master but that seems to cause some troubles. Using the compare url would be better and ideal would be to expose just the commit range.
No idea, sorry. The checkout command has always suited my needs, and Iāve had no call to look into alternatives. Would it be complicated to write an alternative? It seems to me itās just two steps: install the SSH key and do a clone.
Edit: of course, you could use the checkout and then do another Git operation on top. You have the full history there, so such a command should be possible.
The default checkout command does quite a bit so Iād rather not reduce it to two lines. I could just copy it and remove the hard reset but that seems to hacky.
The diff to master isnāt such a good idea in the first place considering our use case. It includes also files that got change on master during the lifetime of the branch. I basically want to run a code formatter on the files changed in the pull request and see if they conform.
It comes down to finding the commit where the branch was created. Not sure if this is possible. Since TravisCI already has a builtin environment variable I guess it is.
I donāt think there is anything to fix (or it is not clear what you want fixing). Most users (and I include myself here) do not understand the black magic of the checkout command - it just works. If you want to do something non-standard, then install an SSH key and use git manually.
If I understand @eps1lon correctly, they want to use the CIRCLE_COMPARE_URL. I also think that @sibelius was referring to this problem and not intended to continue the side discussion around replacing the checkout command.
In my specific use case, it would be interesting to see what directories have changed since the last successful build. However, I am not quite sure whether the CIRCLE_COMPARE_URL is very helpful in this situation, as it only includes all commits for the current build with no information on whether a previous build was successful.
There are two issues here: One is that CIRCLE_COMPARE_URL is empty for some repos on pull requests.
The other problem is that I canāt use merge base to build the compare url on my own because the default checkout command uses reset --hard instead of simply checking out.
Now I could just go ahead and write my own checkout command. I would hope that the default checkout command was written with intent and that the reset --hard serves some purpose. Without knowing that intent it is dangerous to replace it. IMO you should never remove something if you donāt know its purpose.
Thank you for responding. I didnāt look into the orb yet. However, Itās great to know that this issue is recognized and a official recommendation is given for a workaround.
I am facing the same issue: CIRCLE_COMPARE_URL is empty and I need it to be able to list the files modified in my PRās commits.
I tried the orb you mentioned, and I get the following output:
checking if pull/537 is a new branch...
----------------------------------------------------------------------------------------------------
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 37 100 37 0 0 787 0 --:--:-- --:--:-- --:--:-- 787
----------------------------------------------------------------------------------------------------
yes, pull/537 is new and 42e7c2f289acf3a3540f5c64c15a541e9dd929a4 is its only commit
finding most recent ancestor commit from any other branch...
----------------------------------------------------------------------------------------------------
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 37 100 37 0 0 1088 0 --:--:-- --:--:-- --:--:-- 1088
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 37 100 37 0 0 1541 0 --:--:-- --:--:-- --:--:-- 1541
Exited with code 1
I canāt tell why itās failing, could you help me out with that?
Iād love to see the ācompare-urlā orb moved to the official CircleCI organization, so that we donāt need to adjust our Org security settings to āallow uncertified orbsā.
We are holding off doing that for now since we want to fix CIRCLE_COMPARE_URL correctly and moving the workaround Orb to official status may give the indication that we donāt plan to fix it.