Method: Git::Base.init
- Defined in:
- lib/git/base.rb
.init(directory, options = {}) ⇒ Git::Base
Create an empty Git repository or reinitialize an existing Git repository
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/git/base.rb', line 31 def self.init(directory, = {}) [:working_directory] ||= directory [:repository] ||= File.join([:working_directory], '.git') FileUtils.mkdir_p([:working_directory]) if [:working_directory] && !File.directory?([:working_directory]) = { :bare => [:bare] } .delete(:working_directory) if [:bare] # Submodules have a .git *file* not a .git folder. # This file's contents point to the location of # where the git refs are held (In the parent repo) if [:working_directory] && File.file?(File.join([:working_directory], '.git')) git_file = File.open('.git').read[8..-1].strip [:repository] = git_file [:index] = git_file + '/index' end # TODO: this dance seems awkward: this creates a Git::Lib so we can call # init so we can create a new Git::Base which in turn (ultimately) # creates another/different Git::Lib. # # TODO: maybe refactor so this Git::Bare.init does this: # self.new(opts).init(init_opts) and move all/some of this code into # Git::Bare#init. This way the init method can be called on any # repository you have a Git::Base instance for. This would not # change the existing interface (other than adding to it). # Git::Lib.new().init() self.new() end |