Class: GemBootstrap::GitUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_bootstrap/git_utils.rb

Class Method Summary collapse

Class Method Details

.create_git_project(base_dir, gem_name) ⇒ Object

create new git repo from a given directory

Parameters:

  • base_dir (String)

    the starting directory

  • gem_name (String)

    the name of the gem we are creating



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gem_bootstrap/git_utils.rb', line 9

def create_git_project(base_dir, gem_name)
  base_dir = File.expand_path(base_dir) # so that it works with ~/codes/etc
  files = MiscUtils.files base_dir: base_dir,
                          non_exts: %w[Gemfile
                                       Rakefile
                                       Guardfile
                                       LICENSE
                                       .rubocop.yml
                                       .yardopts
                                       .gitignore] << gem_name,
                          exts: %w[md rb gemspec yml],
                          recursive: true
  git_init(base_dir: base_dir)
  git_add(files, base_dir: base_dir, gem_name: gem_name)
end

.git_add(files, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gem_bootstrap/git_utils.rb', line 36

def git_add(files, options = {})
  base_dir = File.expand_path(options[:base_dir])
  Dir.chdir(base_dir) do
    git = Grit::Repo.new(File.expand_path("."))
    files.each do |file|
      # puts "Add '#{file}' to repository"
      git.add(file)
    end
    git.commit_index("Initial commit")
  end
end

.git_init(options = {}) ⇒ Object

Run the git init on a given directory

Parameters:

  • base_dir (String)

    the base directory



28
29
30
31
32
33
34
# File 'lib/gem_bootstrap/git_utils.rb', line 28

def git_init(options = {})
  current_dir = File.expand_path(options[:base_dir])
  base_dir = options[:base_dir] || Dir.pwd
  Dir.chdir(base_dir)
  MiscUtils.shell(%w[git init] << base_dir)
  Dir.chdir(current_dir)
end