Class: Hippo::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/hippo/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Repository

Returns a new instance of Repository.



9
10
11
# File 'lib/hippo/repository.rb', line 9

def initialize(options)
  @options = options
end

Instance Method Details

#checkout(ref) ⇒ Boolean

Checkout the version of the application for the given commit or branch name in the local copy.

Parameters:

  • ref (String)

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
# File 'lib/hippo/repository.rb', line 67

def checkout(ref)
  git.checkout("origin/#{ref}")
  true
rescue Git::GitExecuteError => e
  if e.message =~ /did not match any file\(s\) known to git/
    raise RepositoryCheckoutError, "No branch named '#{ref}' found in repository"
  else
    raise RepositoryCheckoutError, e.message
  end
end

#cloneBoolean

Clone this repository into the working directory for this application.

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
# File 'lib/hippo/repository.rb', line 34

def clone
  if File.directory?(path)
    raise RepositoryAlreadyClonedError, "Repository has already been cloned to #{path}. Maybe you just want to pull?"
  end

  @git = Git.clone(url, path)
  true
rescue Git::GitExecuteError => e
  raise RepositoryCloneError, e.message
end

#cloned?Boolean

Has this been cloned?

Returns:

  • (Boolean)


48
49
50
# File 'lib/hippo/repository.rb', line 48

def cloned?
  File.directory?(path)
end

#commitString

Return the commit reference for the currently checked out branch

Returns:

  • (String)


81
82
83
# File 'lib/hippo/repository.rb', line 81

def commit
  git.log(1).first
end

#commit_for_branch(branch) ⇒ Git::Commit

Get the commit reference for the given branch on the remote repository by asking it directly.

Parameters:

  • name (String)

Returns:

  • (Git::Commit)


90
91
92
93
94
95
96
97
98
# File 'lib/hippo/repository.rb', line 90

def commit_for_branch(branch)
  git.object("origin/#{branch}").log(1).first
rescue Git::GitExecuteError => e
  if e.message =~ /Not a valid object name/
    raise Error, "'#{branch}' is not a valid branch name in repository"
  else
    raise
  end
end

#fetchBoolean

Fetch the latest copy of this repository

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/hippo/repository.rb', line 55

def fetch
  git.fetch
  true
rescue Git::GitExecuteError => e
  raise RepositoryFetchError, e.message
end

#pathString

Return the path where this repository is stored on the local computer.

Returns:

  • (String)


21
22
23
24
25
26
27
28
# File 'lib/hippo/repository.rb', line 21

def path
  return @options['path'] if @options['path']

  @path ||= begin
    digest = Digest::SHA256.hexdigest(url)
    File.join('', 'tmp', 'hippo-repos', digest)
  end
end

#template_varsHash

Return the template variables for a repository

Returns:

  • (Hash)


103
104
105
106
107
108
# File 'lib/hippo/repository.rb', line 103

def template_vars
  {
    'url' => url,
    'path' => path
  }
end

#urlObject



13
14
15
# File 'lib/hippo/repository.rb', line 13

def url
  @options['url']
end