Class: MultiRepo::Branch

Inherits:
Ref
  • Object
show all
Defined in:
lib/multirepo/git/branch.rb

Instance Attribute Summary

Attributes inherited from Ref

#name

Instance Method Summary collapse

Methods inherited from Ref

#can_fast_forward_to?, #commit_id, #initialize, #merge_commit?, #short_commit_id

Constructor Details

This class inherits a constructor from MultiRepo::Ref

Instance Method Details

#checkoutObject



27
28
29
30
# File 'lib/multirepo/git/branch.rb', line 27

def checkout
  GitRunner.run(@repo.path, "checkout #{@name}", Verbosity::OUTPUT_ON_ERROR)
  GitRunner.last_command_succeeded
end

#createObject



19
20
21
# File 'lib/multirepo/git/branch.rb', line 19

def create
  GitRunner.run(@repo.path, "branch #{@name}", Verbosity::OUTPUT_ON_ERROR)
end

#exists?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/multirepo/git/branch.rb', line 6

def exists?
  lines = GitRunner.run(@repo.path, "branch", Verbosity::OUTPUT_NEVER).split("\n")
  branch_names = lines.map { |line| line.tr("* ", "") }
  branch_names.include?(@name)
end

#pushObject



23
24
25
# File 'lib/multirepo/git/branch.rb', line 23

def push
  GitRunner.run(@repo.path, "push -u origin #{@name}", Verbosity::OUTPUT_ON_ERROR)
end

#upstream_branchObject



12
13
14
15
16
17
# File 'lib/multirepo/git/branch.rb', line 12

def upstream_branch
  output = GitRunner.run(@repo.path, "config --get branch.#{@name}.merge", Verbosity::OUTPUT_NEVER)
  output.sub!("refs/heads/", "")
  return nil if output == ""
  Branch.new(@repo, "origin/#{output}")
end