Class: GitPrettyAccept::MergeCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/git_pretty_accept/merge_command.rb

Constant Summary collapse

MESSAGE_TEMPLATE_FILENAME =
'.git-pretty-accept-template.txt'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branch, let_user_edit_message) ⇒ MergeCommand

Returns a new instance of MergeCommand.



7
8
9
10
# File 'lib/git_pretty_accept/merge_command.rb', line 7

def initialize(branch, let_user_edit_message)
  @branch = branch
  @let_user_edit_message = let_user_edit_message
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



5
6
7
# File 'lib/git_pretty_accept/merge_command.rb', line 5

def branch
  @branch
end

#let_user_edit_messageObject (readonly)

Returns the value of attribute let_user_edit_message.



5
6
7
# File 'lib/git_pretty_accept/merge_command.rb', line 5

def let_user_edit_message
  @let_user_edit_message
end

Instance Method Details

#merge_messageObject



12
13
14
15
16
# File 'lib/git_pretty_accept/merge_command.rb', line 12

def merge_message
  if File.exists?(MESSAGE_TEMPLATE_FILENAME)
    File.read(MESSAGE_TEMPLATE_FILENAME)
  end
end

#merge_message_with_escaped_single_quoteObject



19
20
21
# File 'lib/git_pretty_accept/merge_command.rb', line 19

def merge_message_with_escaped_single_quote
  merge_message.gsub("'") { %q{'\''} }
end

#to_sObject



23
24
25
26
27
28
29
30
31
# File 'lib/git_pretty_accept/merge_command.rb', line 23

def to_s
  [
    "git merge",
    "--no-ff",
    let_user_edit_message ? '--edit' : '--no-edit',
    branch,
    merge_message && "--message '#{merge_message_with_escaped_single_quote}'"
  ].join(' ')
end