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 repository from a given directory

Parameters:

  • base_dir (String)

    the starting directory

  • gem_name (String)

    the name of the gem we are creating



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

def create_git_project(base_dir, gem_name)
  base_dir = expand_path(base_dir)
  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)
  git_add(base_dir, files)
end

.git_add(base_dir, files) ⇒ Object

Add files and perform initial commit to the repository

Parameters:

  • base_dir (String)

    the starting directory

  • files (Array<String>)

    list of files to be used



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

def git_add(base_dir, files)
  base_dir = expand_path(base_dir)
  Dir.chdir(base_dir) do
    git = Grit::Repo.new(File.expand_path('.'))
    files.each do |file|
      git.add(file)
    end
    git.commit_index('Initial commit')
  end
end

.git_init(base_dir) ⇒ Object

Run the ‘git init` on a given directory

Parameters:

  • base_dir (String)

    the starting directory



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

def git_init(base_dir)
  base_dir = expand_path(base_dir)
  # Note: need to be in the right directory for this to work
  Dir.chdir(base_dir)
  MiscUtils.shell(%w(git init) << base_dir)
end