Pkg.Write: factor common code for fetching, checking out commits.