Class: EY::Repo
- Inherits:
-
Object
show all
- Defined in:
- lib/engineyard/repo.rb
Defined Under Namespace
Classes: NoRemotesError, NotAGitRepository
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Repo
$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.
33
34
|
# File 'lib/engineyard/repo.rb', line 33
def initialize
end
|
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
25
26
27
|
# File 'lib/engineyard/repo.rb', line 25
def root
@root
end
|
Class Method Details
.exist? ⇒ Boolean
20
21
22
23
|
# File 'lib/engineyard/repo.rb', line 20
def self.exist?
`git rev-parse --git-dir 2>&1`
$?.success?
end
|
Instance Method Details
#current_branch ⇒ Object
87
88
89
90
91
|
# 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! ⇒ Object
48
49
50
|
# File 'lib/engineyard/repo.rb', line 48
def ensure_repository!
root
end
|
#fail_on_no_remotes! ⇒ Object
98
99
100
101
102
|
# 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) ⇒ Boolean
52
53
54
55
|
# 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) ⇒ Boolean
57
58
59
60
|
# 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') ⇒ Object
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')
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/engineyard/repo.rb', line 71
def read_file(file, ref = 'HEAD')
ensure_repository!
if has_committed_file?(file)
`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 ⇒ Object
93
94
95
96
|
# 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
|