Class: Dotstrap::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/dotstrap/git.rb

Overview

TODO: split this into Git < Downloader class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, dest_dir = Dotstrap.config_home) ⇒ Git

Returns a new instance of Git.



9
10
11
12
13
14
15
16
# File 'lib/dotstrap/git.rb', line 9

def initialize(repo, dest_dir = Dotstrap.config_home)
  @repo = determine_repo_slug(repo)
  # TODO: allow an option to specify to download with SSH or HTTPs from Git
  @url = determine_url(@repo)
  @repo_owner, @repo_name = split_repo_slug(@repo)
  @repo_path = File.join(dest_dir, "#{@repo_owner}-#{@repo_name}")
  # @repo_path = File.join(dest_dir, @github_user, @repo_name)
end

Instance Attribute Details

#repoObject

Returns the value of attribute repo.



7
8
9
# File 'lib/dotstrap/git.rb', line 7

def repo
  @repo
end

#repo_nameObject

Returns the value of attribute repo_name.



7
8
9
# File 'lib/dotstrap/git.rb', line 7

def repo_name
  @repo_name
end

#repo_ownerObject

Returns the value of attribute repo_owner.



7
8
9
# File 'lib/dotstrap/git.rb', line 7

def repo_owner
  @repo_owner
end

#repo_pathObject

Returns the value of attribute repo_path.



7
8
9
# File 'lib/dotstrap/git.rb', line 7

def repo_path
  @repo_path
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/dotstrap/git.rb', line 7

def url
  @url
end

Instance Method Details

#clone(url = @url, repo_path = @repo_path, repo = @repo) ⇒ Object

FIXME: if user is not logged in to Git the prompt for username/password is mangled because the threads are not synchronized



20
21
22
23
24
25
26
# File 'lib/dotstrap/git.rb', line 20

def clone(url = @url, repo_path = @repo_path, repo = @repo)
  return pull(repo_path) if Dir.exist?(repo_path)
  return false unless system('git', 'clone', *git_verbosity, url, repo_path)
  $LOG.debug { "CLONE #{repo} #{url} #{repo_path}" }
  $LOG.unknown { "#{'=> '.colorize(:blue)}#{repo}\nupdated" }
  repo_path
end

#pull(repo_path = @repo_path, repo = @repo) ⇒ Object



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

def pull(repo_path = @repo_path, repo = @repo)
  Dir.chdir(repo_path)
  return false unless system('git', 'pull', *git_verbosity, repo_path)
  $LOG.debug { "PULL #{repo} #{url} #{repo_path}" }
  $LOG.unknown { "#{'=> '.colorize(:blue)}#{repo}\nupdated" }
  repo_path
end