Method: Chef::Provider::Git#fetch_updates

Defined in:
lib/chef/provider/git.rb

#fetch_updatesObject



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/chef/provider/git.rb', line 226

def fetch_updates
  setup_remote_tracking_branches(new_resource.remote, new_resource.repository)
  converge_by("fetch updates for #{new_resource.remote}") do
    # since we're in a local branch already, just reset to specified revision rather than merge
    logger.trace "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}"
    git("fetch", "--prune", new_resource.remote, cwd: cwd)
    git("fetch", new_resource.remote, "--tags", cwd: cwd)
    if sha_hash?(new_resource.revision) || is_tag? || already_on_target_branch?
      # detached head or if we are already on the proper branch
      git("reset", "--hard", target_revision, cwd: cwd)
    elsif new_resource.checkout_branch
      # check out to a local branch
      git("branch", "-f", new_resource.checkout_branch, target_revision, cwd: cwd)
      git("checkout", new_resource.checkout_branch, cwd: cwd)
    else
      # need a branch with a tracking branch
      git("branch", "-f", new_resource.revision, target_revision, cwd: cwd)
      git("checkout", new_resource.revision, cwd: cwd)
      git("branch", "-u", "#{new_resource.remote}/#{new_resource.revision}", cwd: cwd)
    end
  end
end