Class: Coral::Git
- Inherits:
-
Grit::Repo
- Object
- Grit::Repo
- Coral::Git
- Defined in:
- lib/coral_core/util/git.rb
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ Git
constructor
—————————————————————————– Constructor / Destructor.
Constructor Details
#initialize(path, options = {}) ⇒ Git
Constructor / Destructor
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/coral_core/util/git.rb', line 7 def initialize(path, = {}) epath = File.(path) git_dir = File.join(epath, '.git') @bare = ([:is_bare] ? true : false) if File.exist?(git_dir) self.working_dir = epath if File.directory?(git_dir) self.path = git_dir else git_dir = Util::Disk.read(git_dir) unless git_dir.nil? git_dir = git_dir.gsub(/^gitdir\:\s*/, '').strip self.path = git_dir if File.directory?(git_dir) end end elsif File.directory?(epath) && ([:is_bare] || (epath =~ /\.git$/ && File.exist?(File.join(epath, 'HEAD')))) self.path = epath @bare = true end self.git = ::Grit::Git.new(self.path) self.git.work_tree = epath unless File.directory?(epath) && self.git.exist? FileUtils.mkdir_p(epath) unless File.directory?(epath) self.git.init({ :bare => @bare }) end end |