Chapter 7 Advanced: Version control
Version control is critically important to writing robust, reproducible code, and is highly recommended regardless of QA requirements. At its most basic, it means keeping track of changes made to code over time. Version control software like Git
take code snapshots and store them either locally or remotely. Purely local version control with Git
offers fewer functionalities but is still extremely useful in reducing the risk of code-breaking changes as analysts can backtrack to previous working versions of their code. Remote version control requires the use of a Git repository hosting service such as Github or Azure DevOps (previously known as VSTS). These are online platforms where git repositories can be saved and synched with their local counterparts. This is a powerful way to write code collaboratively, with QA built-in to the code writing process.
A guide on version control using Git and DevOps for DfE analysts can be found here but watch this space for an updated version in the near future. From a QA point of view, an ideal situation is where the author of the code and their quality assurer collaborate on the same Git
project. Concretely, the analyst creates a pull request to merge their code changes into a clean master version of the code. The approver then evaluates whether the change is appropriate and either approves or asks for edits to be made. This is an ideal scenario and perhaps recommended for business critical work. In most cases, the approver will have first sighting of the code after the project is completed. In that case, version control logs can still be saved to file and shared.
# open a shell from Rstudio Tools
# dropdown menu. Logs can be formatted
# in many different ways. There are
# 2 options below saving logs to
# a text file but many more exist
--pretty=format:'%h was %an, %ar, message: %s' > log.txt
git log --oneline --decorate --graph > log.txt git log