Class: Command::Init

Inherits:
Base
  • Object
show all
Defined in:
lib/command/init.rb

Constant Summary collapse

DEFAULT_BRANCH =
"master"

Instance Attribute Summary

Attributes inherited from Base

#status

Instance Method Summary collapse

Methods inherited from Base

#execute, #initialize

Constructor Details

This class inherits a constructor from Command::Base

Instance Method Details

#runObject



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/command/init.rb', line 12

def run
  path = @args.fetch(0, @dir)

  root_path = expanded_pathname(path)
  git_path  = root_path.join(".git")

  ["objects", "refs/heads"].each do |dir|
    begin
      FileUtils.mkdir_p(git_path.join(dir))
    rescue Errno::EACCES => error
      @stderr.puts "fatal: #{ error.message }"
      exit 1
    end
  end

  config = ::Config.new(git_path.join("config"))
  config.open_for_update
  config.set(["core", "bare"], false)
  config.save

  refs = Refs.new(git_path)
  path = File.join("refs", "heads", DEFAULT_BRANCH)
  refs.update_head("ref: #{ path }")

  puts "Initialized empty Jit repository in #{ git_path }"
  exit 0
end