Class: Omnibus::GitFetcher

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/omnibus/fetchers/git_fetcher.rb

Constant Summary

Constants included from Util

Util::SHELLOUT_OPTIONS

Instance Attribute Summary

Attributes inherited from Fetcher

#build_dir, #described_version, #name, #project_dir, #resolved_version, #source

Instance Method Summary collapse

Methods inherited from Fetcher

#fetcher, #initialize, #version

Methods included from Util

#compiler_safe_path, #copy_file, #create_directory, #create_file, #create_link, included, #path_key, #remove_directory, #remove_file, #retry_block, #shellout, #shellout!, #windows_safe_path

Methods included from Logging

included

Methods included from Digestable

#digest, #digest_directory, included

Constructor Details

This class inherits a constructor from Omnibus::Fetcher

Instance Method Details

#cleantrue, false

Clean the project directory by resetting the current working tree to the required revision.

Returns:

  • (true, false)

    true if the project directory was cleaned, false otherwise. In our case, we always return true because we always call git checkout/clean.



48
49
50
51
52
53
# File 'lib/omnibus/fetchers/git_fetcher.rb', line 48

def clean
  log.info(log_key) { "Cleaning existing clone" }
  git_checkout
  git("clean -fdx")
  true
end

#fetchvoid

This method returns an undefined value.

Fetch (clone) or update (fetch) the remote git repository.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/omnibus/fetchers/git_fetcher.rb', line 60

def fetch
  log.info(log_key) { "Fetching from `#{source_url}'" }
  create_required_directories

  if cloned?
    git_fetch
  else
    force_recreate_project_dir! unless dir_empty?(project_dir)
    git_clone
  end
end

#fetch_required?true, false

A fetch is required if the git repository is not cloned or if the local revision does not match the desired revision.

Returns:

  • (true, false)


25
26
27
# File 'lib/omnibus/fetchers/git_fetcher.rb', line 25

def fetch_required?
  !(cloned? && contains_revision?(resolved_version))
end

#version_for_cacheString

The version for this item in the cache.

This method is called before clean but after fetch. Do not ever use the contents of the project_dir here.

We aren’t including the source/repo path here as there could be multiple branches/tags that all point to the same commit. We’re assuming that we won’t realistically ever get two git commits that are unique but share sha1s.

TODO: Does this work with submodules?

Returns:

  • (String)


87
88
89
# File 'lib/omnibus/fetchers/git_fetcher.rb', line 87

def version_for_cache
  "revision:#{resolved_version}"
end

#version_guidString

The version identifier for this git location. This is computed using the current revision on disk.

Returns:

  • (String)


35
36
37
# File 'lib/omnibus/fetchers/git_fetcher.rb', line 35

def version_guid
  "git:#{current_revision}"
end