Class: Mj::Git::RemoteBranch

Inherits:
Object
  • Object
show all
Defined in:
lib/mj/git/remote_branch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, command_executer: CommandExecuter.new) ⇒ RemoteBranch

Returns a new instance of RemoteBranch.



8
9
10
11
# File 'lib/mj/git/remote_branch.rb', line 8

def initialize(name, command_executer: CommandExecuter.new)
  @name = name
  @command_executer = command_executer
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/mj/git/remote_branch.rb', line 6

def name
  @name
end

Instance Method Details

#checkout_commandObject



13
14
15
# File 'lib/mj/git/remote_branch.rb', line 13

def checkout_command
  "git checkout -b #{local_branch_name} #{name}"
end

#deleteObject



42
43
44
# File 'lib/mj/git/remote_branch.rb', line 42

def delete
  @command_executer.execute("git push origin :#{local_branch_name}")
end

#has_pr?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mj/git/remote_branch.rb', line 29

def has_pr?
  !pr.nil?
end

#last_commit_dateObject



17
18
19
# File 'lib/mj/git/remote_branch.rb', line 17

def last_commit_date
  @last_commit_date ||= DateTime.parse(@command_executer.execute("git log -1 --format=%cd #{name}").first)
end

#lengthObject



21
22
23
# File 'lib/mj/git/remote_branch.rb', line 21

def length
  @name.length
end

#prGit::PullRequest

Returns:



34
35
36
37
38
39
40
# File 'lib/mj/git/remote_branch.rb', line 34

def pr
  if defined?(@pr)
    return @pr
  end

  @pr ||= fetch_pr
end

#to_localObject



25
26
27
# File 'lib/mj/git/remote_branch.rb', line 25

def to_local
  LocalBranch.new(local_branch_name)
end