Class: Hippo::Repository
- Inherits:
-
Object
- Object
- Hippo::Repository
- Defined in:
- lib/hippo/repository.rb
Instance Method Summary collapse
-
#checkout(ref) ⇒ Boolean
Checkout the version of the application for the given commit or branch name in the local copy.
-
#clone ⇒ Boolean
Clone this repository into the working directory for this application.
-
#cloned? ⇒ Boolean
Has this been cloned?.
-
#commit ⇒ String
Return the commit reference for the currently checked out branch.
-
#commit_for_branch(branch) ⇒ Git::Commit
Get the commit reference for the given branch on the remote repository by asking it directly.
-
#fetch ⇒ Boolean
Fetch the latest copy of this repository.
-
#initialize(options) ⇒ Repository
constructor
A new instance of Repository.
-
#path ⇒ String
Return the path where this repository is stored on the local computer.
-
#template_vars ⇒ Hash
Return the template variables for a repository.
- #url ⇒ Object
Constructor Details
#initialize(options) ⇒ Repository
Returns a new instance of Repository.
9 10 11 |
# File 'lib/hippo/repository.rb', line 9 def initialize() @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.
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. =~ /did not match any file\(s\) known to git/ raise RepositoryCheckoutError, "No branch named '#{ref}' found in repository" else raise RepositoryCheckoutError, e. end end |
#clone ⇒ Boolean
Clone this repository into the working directory for this application.
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. end |
#cloned? ⇒ Boolean
Has this been cloned?
48 49 50 |
# File 'lib/hippo/repository.rb', line 48 def cloned? File.directory?(path) end |
#commit ⇒ String
Return the commit reference for the currently checked out branch
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.
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. =~ /Not a valid object name/ raise Error, "'#{branch}' is not a valid branch name in repository" else raise end end |
#fetch ⇒ Boolean
Fetch the latest copy of this repository
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. end |
#path ⇒ String
Return the path where this repository is stored on the local computer.
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_vars ⇒ Hash
Return the template variables for a repository
103 104 105 106 107 108 |
# File 'lib/hippo/repository.rb', line 103 def template_vars { 'url' => url, 'path' => path } end |
#url ⇒ Object
13 14 15 |
# File 'lib/hippo/repository.rb', line 13 def url @options['url'] end |