Class: Gitit::GitBranches

Inherits:
Object
  • Object
show all
Includes:
GitExecutor
Defined in:
lib/gitit/git_branches.rb

Overview



Instance Attribute Summary

Attributes included from GitExecutor

#repo

Instance Method Summary collapse

Methods included from GitExecutor

#execute_command, repo

Constructor Details

#initialize(repo) ⇒ GitBranches





12
13
14
# File 'lib/gitit/git_branches.rb', line 12

def initialize(repo)
  @repo = repo
end

Instance Method Details

#create_local_branch(name) ⇒ Object





40
41
42
43
# File 'lib/gitit/git_branches.rb', line 40

def create_local_branch(name)
  execute_command("branch --quiet #{name}")
  $?.exitstatus == 0
end

#exists_locally?(name) ⇒ Boolean



Returns:

  • (Boolean)


26
27
28
29
# File 'lib/gitit/git_branches.rb', line 26

def exists_locally?(name)
  branches = execute_command('branch --no-color').gsub(/^[* ] /, '').lines.map(&:chomp).to_a
  branches.include? name
end

#exists_remotely?(name, remote) ⇒ Boolean



Returns:

  • (Boolean)


33
34
35
36
# File 'lib/gitit/git_branches.rb', line 33

def exists_remotely?(name, remote)
  branches = execute_command('branch -r --no-color').gsub(/^[* ] /, '').lines.map(&:chomp).to_a
  branches.include? "#{remote}/#{name}"
end

#get_current_branchObject





18
19
20
21
22
# File 'lib/gitit/git_branches.rb', line 18

def get_current_branch
  branches = execute_command('branch --no-color')
  branch_match = branches.each_line.select { |b| b.start_with? '* ' }
  branch_match[0].strip.gsub(/\* /, '')
end

#push_local_branch_to_remote(name, remote, force) ⇒ Object





47
48
49
50
51
# File 'lib/gitit/git_branches.rb', line 47

def push_local_branch_to_remote(name, remote, force)
  execute_command("push --quiet -f #{remote} #{name}") if force
  execute_command("push --quiet #{remote} #{name}") unless force
  $?.exitstatus == 0
end