Class: Rgit::Rgit

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Rgit

Returns a new instance of Rgit.



10
11
12
# File 'lib/rgit/rgit.rb', line 10

def initialize(config)
  @config = config
end

Instance Method Details

#add_root(path) ⇒ Object



14
15
16
17
18
19
# File 'lib/rgit/rgit.rb', line 14

def add_root(path)
  raise "Not a directory: #{path}" unless File.directory?(path)
  puts "Adding root: #{path}"
  @config.add_root path
  @config.save
end

#checkout(branch, path = Dir.pwd) ⇒ Object



48
49
50
51
52
53
# File 'lib/rgit/rgit.rb', line 48

def checkout(branch, path = Dir.pwd)
  recursive_cmd(path) do |git|
    puts " Checkout branch: #{branch}".colorize(:light_cyan)
    git.checkout branch
  end
end

#fetch(path = Dir.pwd) ⇒ Object



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

def fetch(path = Dir.pwd)
  recursive_cmd(path) do |git|
    git.remotes.each do | remote|
      puts " Fetching remote: #{remote.name}".colorize(:light_cyan)
      results = git.fetch(remote.name, all: true)
      puts results.split("\n").map {|l| "   #{l}"}.join("\n")
    end
  end
end


71
72
73
74
75
76
77
78
79
80
# File 'lib/rgit/rgit.rb', line 71

def print_roots
  if @config.roots.empty?
    puts "No roots have been configured. Run 'rgit --add-root' to add the current directory as a root"
  else
    puts 'Roots:'
    @config.roots.each do |root|
      puts "  - #{root}"
    end
  end
end

#pull(path = Dir.pwd) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/rgit/rgit.rb', line 28

def pull(path = Dir.pwd)
  recursive_cmd(path) do |git|
    git.remotes.each do | remote|
      puts " Pulling remote: #{remote.name}".colorize(:light_cyan)
      results = git.pull(remote.name, git.current_branch)
      puts results.split("\n").map {|l| "   #{l}"}.join("\n")
    end
  end
end

#remove_root(path) ⇒ Object



21
22
23
24
25
26
# File 'lib/rgit/rgit.rb', line 21

def remove_root(path)
  raise "Not a directory: #{path}" unless File.directory?(path)
  puts "Removing root: #{path}"
  @config.remove_root path
  @config.save
end

#status(path = Dir.pwd) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rgit/rgit.rb', line 55

def status(path = Dir.pwd)
  recursive_cmd(path) do |git|
    unless git.status.untracked.empty?
      puts " Untracked changes (#{git.current_branch}):".colorize(:light_red)
      git.status.untracked.keys.each {|filename| puts "   - #{filename}" }
    end
    unless git.status.changed.empty?
      puts " Uncommitted changes (#{git.current_branch}):".colorize(:light_magenta)
      git.status.changed.keys.each {|filename| puts "   - #{filename}" }
    end
    if git.status.untracked.empty? && git.status.changed.empty?
      puts " On branch: #{git.current_branch}".colorize(:green)
    end
  end
end