class EY::Repo
Attributes
root[R]
Public Class Methods
exist?()
click to toggle source
# File lib/engineyard/repo.rb, line 20 def self.exist? `git rev-parse --git-dir 2>&1` $?.success? end
new()
click to toggle source
$GIT_DIR is what git uses to override the location of the .git dir. $GIT_WORK_TREE is the working tree for git, which we'll use after $GIT_DIR.
We use this to specify which repo we should look at, since it would also specify where any git commands are directed, thus fooling commands we run anyway.
# File lib/engineyard/repo.rb, line 33 def initialize end
Public Instance Methods
current_branch()
click to toggle source
# File lib/engineyard/repo.rb, line 87 def current_branch ensure_repository! branch = `git symbolic-ref -q HEAD`.chomp.gsub("refs/heads/", "") branch.empty? ? nil : branch end
ensure_repository!()
click to toggle source
# File lib/engineyard/repo.rb, line 48 def ensure_repository! root end
fail_on_no_remotes!()
click to toggle source
# File lib/engineyard/repo.rb, line 98 def fail_on_no_remotes! if remotes.empty? raise EY::Repo::NoRemotesError.new(root) end end
has_committed_file?(file)
click to toggle source
# File lib/engineyard/repo.rb, line 52 def has_committed_file?(file) ensure_repository! `git ls-files --full-name #{file}`.strip == file && $?.success? end
has_file?(file)
click to toggle source
# File lib/engineyard/repo.rb, line 57 def has_file?(file) ensure_repository! has_committed_file?(file) || root.join(file).exist? end
read_file(file, ref = 'HEAD')
click to toggle source
Read the committed version at HEAD (or ref) of a file using the git working tree relative filename. If the file is not committed, but does exist, a warning will be displayed and the file will be read anyway. If the file does not exist, returns nil.
Example:
read_file('config/ey.yml') # will read $GIT_WORK_TREE/config/ey.yml
# File lib/engineyard/repo.rb, line 71 def read_file(file, ref = 'HEAD') ensure_repository! if has_committed_file?(file) # TODO warn if there are unstaged changes. `git show #{ref}:#{file}` else EY.ui.warn <<-WARN Warn: #{file} is not committed to this git repository: \t#{root} This can prevent ey deploy from loading this file for certain server side deploy-time operations. Commit this file to fix this warning. WARN root.join(file).read end end
remotes()
click to toggle source
# File lib/engineyard/repo.rb, line 93 def remotes ensure_repository! @remotes ||= `git remote -v`.scan(/\t[^\s]+\s/).map { |c| c.strip }.uniq end