Class: GitOp

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

Overview

This class is used by lib/backend.rb git operation for gitarro

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git_dir, pr, options) ⇒ GitOp

Returns a new instance of GitOp.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gitarro/git_op.rb', line 44

def initialize(git_dir, pr, options)
  @git_dir = git_dir
  # prefix for the test pr that gitarro tests.
  @pr_fix = 'PR-'
  # pr object for extract all relev. data.
  @pr = pr
  # All gitarro options
  @options = options
  # object to handle external repos
  @repo_external = ExternalRepoGit.new(pr, options)
  gh = 'https://github.com/'
  gg = '[email protected]:'
  @repo_protocol = @options[:https] ? gh : gg
end

Instance Attribute Details

#git_dirObject (readonly)

Returns the value of attribute git_dir.



43
44
45
# File 'lib/gitarro/git_op.rb', line 43

def git_dir
  @git_dir
end

#prObject (readonly)

Returns the value of attribute pr.



43
44
45
# File 'lib/gitarro/git_op.rb', line 43

def pr
  @pr
end

#pr_fixObject (readonly)

Returns the value of attribute pr_fix.



43
44
45
# File 'lib/gitarro/git_op.rb', line 43

def pr_fix
  @pr_fix
end

#repo_externalObject (readonly)

Returns the value of attribute repo_external.



43
44
45
# File 'lib/gitarro/git_op.rb', line 43

def repo_external
  @repo_external
end

#repo_protocolObject (readonly)

Returns the value of attribute repo_protocol.



43
44
45
# File 'lib/gitarro/git_op.rb', line 43

def repo_protocol
  @repo_protocol
end

Instance Method Details

#del_pr_branch(upstream, pr) ⇒ Object

cleanup the pr_branch(delete it)



76
77
78
79
# File 'lib/gitarro/git_op.rb', line 76

def del_pr_branch(upstream, pr)
  `git checkout #{upstream}`
  `git branch -D  #{pr_fix}#{pr}`
end

#merge_pr_totarget(upstream, pr_branch) ⇒ Object

merge pr_branch into upstream targeted branch



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gitarro/git_op.rb', line 60

def merge_pr_totarget(upstream, pr_branch)
  goto_prj_dir
  check_git_dir
  `git checkout #{upstream}`
  check_duplicata_pr_branch("#{pr_fix}#{pr_branch}")
  `git remote update`
  `git fetch`
  `git pull origin #{upstream}`
  `git checkout -b #{pr_fix}#{pr_branch} origin/#{pr_branch}`
  return if $CHILD_STATUS.exitstatus.zero?

  # if it fails the PR contain a forked external repo
  repo_external.checkout_into
end