Class: Gitit::Branches

Inherits:
Object
  • Object
show all
Includes:
CommandExecutor
Defined in:
lib/gitit/command_branches.rb

Overview



Instance Attribute Summary

Attributes included from CommandExecutor

#repo

Instance Method Summary collapse

Methods included from CommandExecutor

#execute_command

Constructor Details

#initialize(repo) ⇒ Branches





12
13
14
# File 'lib/gitit/command_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/command_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/command_branches.rb', line 26

def exists_locally?(name)
  execute_command("branch --no-color | sed 's/^[* ] //' | grep #{name}")
  $?.exitstatus == 0
end

#exists_remotely?(name, remote) ⇒ Boolean



Returns:

  • (Boolean)


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

def exists_remotely?(name, remote)
  execute_command("branch -r --no-color | sed 's/^[* ] //' | grep #{remote}/#{name}")
  $?.exitstatus == 0
end

#get_current_branchObject





18
19
20
21
22
# File 'lib/gitit/command_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/command_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