Chapter: 6 Putting It All Together

6.1 The Workflow

6.1.1 Before we start coding, let’s make sure were up to date.

# Fetch from upstream remote
git fetch upstream

# Checkout your master branch and merge upstream
git checkout master
git merge upstream/master

6.1.2 Create a branch to work on a new feature or bugfix

# Checkout the master branch - you want your new branch to come from master
git checkout master

# Create a new branch named newfeature (give your branch its own simple informative name)
git branch newfeature

# Switch to your new branch
git checkout newfeature

6.1.3 Load the devtools library

# We use devtools a lot, and if we don't wan't to use the long form function call
dev_tools::load_all()
# we can make it available in our console with 
library(devtools)
# so next time we only have to type
load_all()

6.1.4 Abide by the Repeaded Amend strategy

We should make commits often. We should make amends even more often, so if our code ever breaks in horrible ways, we can easily discard our work since the last amend with git reset --hard

First: Make a small change to your code.

Next:

# When you want to test the changes you've made by running code, first execute ...

load_all()

# ... in your console. This function **simulates** that your updated code has been added to your package
# so you can play aroud with it without actually building the changes into all of your package files.
# This means you can load_all (as opposed to build) at any time in development without having to
# rebuild after correcting a mistake

# [VERIFY YOUR UPDATED CODE WORKS (by running code or test cases)]
commit add <files> <you> <just> <updated>

# This next bit goes one of two ways
# 1. If you haven't created a new commit yet...
commit -m "Describe the feature or bugfix"

# 2. If you want to add more changes on top of a commit you've already started...
commit --amend

Finally: Repeat until you’ve correctly implemented a new functionality.

6.1.5 Integrate Changes with the Package

The check() function does three things for us: it updates our roxygen documentation, it runs our testthat test files, and it checks for a bunch of things that make sure we’ve implemented our code well.

  1. Run the devtools::check(cleanup=TRUE) function
  2. Fix the first error or warning
  3. Repeat steps (1) and (2) until all errors and warnings are resolved.
  4. git commit --amend one last time. Make sure to include all those files produced or updated by the check function, even if you didn’t write it yourself.

6.1.6 Incorperate Upstream Changes

Before you create a pull request, you’ll want to make sure you’ve incorperated upstream changes into your feature branch.

# merge upstream changes into master
git fetch upstream
git checkout master
git merge upstream/master
# pull those changes from master into your feature
git checkout newfeature
git pull --rebase origin master

6.1.7 Congratulations!

You have successfully create a feature, and you may submit a pull request :blush:

6.2 Contending with Upstream Changes