git_reflow 0.8.9 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/multi-ruby-tests.yml +33 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +2 -0
  5. data/.ruby-version +1 -0
  6. data/Appraisals +1 -6
  7. data/CHANGELOG.md +466 -348
  8. data/Gemfile.lock +99 -72
  9. data/LICENSE +20 -20
  10. data/README.md +481 -0
  11. data/Rakefile +15 -8
  12. data/Workflow +3 -0
  13. data/_config.yml +1 -0
  14. data/bin/console +7 -7
  15. data/bin/setup +6 -6
  16. data/exe/git-reflow +20 -36
  17. data/git_reflow.gemspec +26 -30
  18. data/lib/git_reflow.rb +3 -15
  19. data/lib/git_reflow/config.rb +48 -13
  20. data/lib/git_reflow/git_helpers.rb +69 -22
  21. data/lib/git_reflow/git_server.rb +63 -63
  22. data/lib/git_reflow/git_server/base.rb +68 -68
  23. data/lib/git_reflow/git_server/bit_bucket.rb +101 -101
  24. data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +84 -84
  25. data/lib/git_reflow/git_server/git_hub.rb +53 -41
  26. data/lib/git_reflow/git_server/git_hub/pull_request.rb +16 -14
  27. data/lib/git_reflow/git_server/pull_request.rb +4 -2
  28. data/lib/git_reflow/merge_error.rb +9 -9
  29. data/lib/git_reflow/rspec.rb +3 -2
  30. data/lib/git_reflow/rspec/command_line_helpers.rb +23 -6
  31. data/lib/git_reflow/rspec/stub_helpers.rb +13 -13
  32. data/lib/git_reflow/rspec/workflow_helpers.rb +18 -0
  33. data/lib/git_reflow/sandbox.rb +16 -6
  34. data/lib/git_reflow/version.rb +1 -1
  35. data/lib/git_reflow/workflow.rb +304 -9
  36. data/lib/git_reflow/workflows/FlatMergeWorkflow +38 -0
  37. data/lib/git_reflow/workflows/core.rb +364 -238
  38. data/spec/fixtures/authentication_failure.json +3 -0
  39. data/spec/fixtures/awesome_workflow.rb +3 -7
  40. data/spec/fixtures/git/git_config +7 -7
  41. data/spec/fixtures/issues/comment.json.erb +27 -27
  42. data/spec/fixtures/issues/comments.json +29 -29
  43. data/spec/fixtures/issues/comments.json.erb +15 -15
  44. data/spec/fixtures/pull_requests/comment.json.erb +45 -45
  45. data/spec/fixtures/pull_requests/comments.json +47 -47
  46. data/spec/fixtures/pull_requests/comments.json.erb +15 -15
  47. data/spec/fixtures/pull_requests/commits.json +29 -29
  48. data/spec/fixtures/pull_requests/external_pull_request.json +145 -145
  49. data/spec/fixtures/pull_requests/pull_request.json +142 -142
  50. data/spec/fixtures/pull_requests/pull_request.json.erb +142 -142
  51. data/spec/fixtures/pull_requests/pull_request_branch_nonexistent_error.json +32 -0
  52. data/spec/fixtures/pull_requests/pull_request_exists_error.json +32 -32
  53. data/spec/fixtures/pull_requests/pull_requests.json +136 -136
  54. data/spec/fixtures/repositories/commit.json +53 -53
  55. data/spec/fixtures/repositories/commit.json.erb +53 -53
  56. data/spec/fixtures/repositories/commits.json.erb +13 -13
  57. data/spec/fixtures/repositories/statuses.json +31 -31
  58. data/spec/fixtures/users/user.json +32 -0
  59. data/spec/lib/git_reflow/git_helpers_spec.rb +115 -12
  60. data/spec/lib/git_reflow/git_server/bit_bucket_spec.rb +81 -81
  61. data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +10 -10
  62. data/spec/lib/git_reflow/git_server/git_hub_spec.rb +77 -3
  63. data/spec/lib/git_reflow/git_server/pull_request_spec.rb +9 -3
  64. data/spec/lib/git_reflow/git_server_spec.rb +101 -101
  65. data/spec/lib/git_reflow/sandbox_spec.rb +1 -1
  66. data/spec/lib/git_reflow/workflow_spec.rb +304 -59
  67. data/spec/lib/git_reflow/workflows/core_spec.rb +225 -67
  68. data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +71 -59
  69. data/spec/lib/git_reflow_spec.rb +2 -25
  70. data/spec/spec_helper.rb +3 -0
  71. data/spec/support/fixtures.rb +54 -54
  72. data/spec/support/github_helpers.rb +99 -109
  73. data/spec/support/mock_pull_request.rb +17 -17
  74. data/spec/support/web_mocks.rb +39 -39
  75. metadata +51 -74
  76. data/README.rdoc +0 -461
  77. data/circle.yml +0 -26
  78. data/lib/git_reflow/commands/deliver.rb +0 -10
  79. data/lib/git_reflow/commands/refresh.rb +0 -20
  80. data/lib/git_reflow/commands/review.rb +0 -13
  81. data/lib/git_reflow/commands/setup.rb +0 -11
  82. data/lib/git_reflow/commands/stage.rb +0 -9
  83. data/lib/git_reflow/commands/start.rb +0 -18
  84. data/lib/git_reflow/commands/status.rb +0 -7
  85. data/lib/git_reflow/os_detector.rb +0 -23
  86. data/lib/git_reflow/workflows/flat_merge.rb +0 -10
  87. data/spec/fixtures/workflow_with_super.rb +0 -8
data/Rakefile CHANGED
@@ -1,8 +1,15 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
- require "rspec/core/rake_task"
4
-
5
- RSpec::Core::RakeTask.new(:spec)
6
-
7
- task :default => :spec
8
-
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+ require "github_changelog_generator/task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
9
+ config.user = 'reenhanced'
10
+ config.project = 'gitreflow'
11
+ config.since_tag = 'v0.9.2'
12
+ config.future_release = 'master'
13
+ end
14
+
15
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ # This file is empty on purpose in case there are any custom workflows configured locally.
2
+ # Eventually we will update it to:
3
+ # use "OpenSourceWorkflow"
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-modernist
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "git_reflow"
5
-
6
- require "irb"
7
- IRB.start
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git_reflow"
5
+
6
+ require "irb"
7
+ IRB.start
data/bin/setup CHANGED
@@ -1,6 +1,6 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -1,36 +1,20 @@
1
- #!/usr/bin/env ruby
2
- $: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
3
- require 'rubygems'
4
- require 'gli'
5
- require 'git_reflow'
6
-
7
- include GLI::App
8
-
9
- program_desc 'Git Reflow manages your git workflow.'
10
-
11
- version GitReflow::VERSION
12
-
13
- commands_from 'git_reflow/commands'
14
-
15
- pre do |global,command,options,args|
16
- # Pre logic here
17
- # Return true to proceed; false to abourt and not call the
18
- # chosen command
19
- # Use skips_pre before a command to skip this block
20
- # on that command only
21
- true
22
- end
23
-
24
- post do |global,command,options,args|
25
- # Post logic here
26
- # Use skips_post before a command to skip this
27
- # block on that command only
28
- end
29
-
30
- on_error do |exception|
31
- # Error logic here
32
- # return false to skip default error handling
33
- true
34
- end
35
-
36
- exit run(ARGV)
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
3
+ require 'rubygems'
4
+ require 'git_reflow'
5
+
6
+ reflow_command = ARGV.shift
7
+ if reflow_command.nil? || GitReflow.workflow.commands[reflow_command.to_sym].nil?
8
+ GitReflow.help
9
+ elsif ARGV.include? "--help"
10
+ GitReflow.documentation_for_command(reflow_command)
11
+ else
12
+ trap 'INT' do
13
+ GitReflow.say "Aborted.", :error
14
+ exit
15
+ end
16
+
17
+ command_options = GitReflow.parse_command_options!(reflow_command)
18
+ GitReflow.logger.debug "Running command `#{reflow_command}` with options: #{command_options.inspect}"
19
+ GitReflow.public_send(reflow_command.to_sym, command_options)
20
+ end
@@ -1,44 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Ensure we require the local version and not one we might have installed already
2
- require File.join([File.dirname(__FILE__),'lib','git_reflow/version.rb'])
4
+ require File.join([File.dirname(__FILE__), 'lib', 'git_reflow/version.rb'])
3
5
  Gem::Specification.new do |s|
4
- s.name = 'git_reflow'
5
- s.version = GitReflow::VERSION
6
- s.license = 'MIT'
7
- s.authors = ["Valentino Stoll", "Robert Stern", "Nicholas Hance"]
8
- s.email = ["dev@reenhanced.com"]
9
- s.homepage = "http://github.com/reenhanced/gitreflow"
10
- s.summary = "A better git process"
11
- s.description = "Git Reflow manages your git workflow."
12
- s.platform = Gem::Platform::RUBY
13
- s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
- s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
- s.has_rdoc = true
17
- s.extra_rdoc_files = ['README.rdoc']
18
- s.bindir = "exe"
19
- s.require_paths = ["lib"]
20
- s.rdoc_options << '--title' << 'git_reflow' << '--main' << 'README.rdoc' << '-ri'
6
+ s.name = 'git_reflow'
7
+ s.version = GitReflow::VERSION
8
+ s.license = 'MIT'
9
+ s.authors = ['Valentino Stoll', 'Robert Stern', 'Nicholas Hance']
10
+ s.email = ['dev@reenhanced.com']
11
+ s.homepage = 'http://github.com/reenhanced/gitreflow'
12
+ s.summary = 'A better git process'
13
+ s.description = 'Git Reflow manages your git workflow.'
14
+ s.platform = Gem::Platform::RUBY
15
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ s.bindir = 'exe'
19
+ s.require_paths = ['lib']
20
+ s.rdoc_options << '--title' << 'git_reflow' << '-ri'
21
21
 
22
- s.add_development_dependency('appraisal', '2.1.0')
23
- s.add_development_dependency('bundler', "~> 1.12")
22
+ s.add_development_dependency('appraisal', '2.2.0')
24
23
  s.add_development_dependency('chronic')
24
+ s.add_development_dependency('github_changelog_generator')
25
25
  s.add_development_dependency('pry-byebug')
26
- s.add_development_dependency('rake', "~> 11.0")
26
+ s.add_development_dependency('rake', '~> 13.0.1')
27
27
  s.add_development_dependency('rdoc')
28
- s.add_development_dependency('rspec', "~> 3.4.0")
28
+ s.add_development_dependency('rspec', '~> 3.9')
29
29
  s.add_development_dependency('webmock')
30
- s.add_development_dependency('wwtd', '1.3.0')
30
+ s.add_development_dependency('wwtd', '1.4')
31
31
 
32
+ s.add_dependency('bundler', '>= 1.10.0')
33
+ s.add_dependency('codenamev_bitbucket_api', '0.4.1')
32
34
  s.add_dependency('colorize', '>= 0.7.0')
33
- s.add_dependency('gli', '2.15.0')
35
+ s.add_dependency('github_api', '0.18.2')
34
36
  s.add_dependency('highline')
35
37
  s.add_dependency('httpclient')
36
- s.add_dependency('github_api', '0.15.0')
37
- # rack is a dependency of oauth2, which is a dependency of github_api
38
- # The latest rack only supports ruby > 2.2.2, so we lock this down until
39
- # support for ruby 2.1.x is dropped
40
- s.add_dependency('rack', ['>= 1.2', '< 2'])
41
- s.add_dependency('reenhanced_bitbucket_api', '0.3.2')
42
38
 
43
39
  s.post_install_message = "You need to setup your GitHub OAuth token\nPlease run 'git-reflow setup'"
44
40
  end
@@ -6,13 +6,6 @@ require 'httpclient'
6
6
  require 'json'
7
7
  require 'colorize'
8
8
 
9
- # XXX: work around logger spam from hashie (required by github api)
10
- # https://github.com/intridea/hashie/issues/394
11
- require "hashie"
12
- require "hashie/logger"
13
- Hashie.logger = Logger.new(nil)
14
-
15
-
16
9
  require 'github_api'
17
10
  require 'git_reflow/version.rb' unless defined?(GitReflow::VERSION)
18
11
  require 'git_reflow/config'
@@ -22,7 +15,6 @@ require 'git_reflow/git_server/bit_bucket'
22
15
  require 'git_reflow/git_server/git_hub'
23
16
  require 'git_reflow/logger'
24
17
  require 'git_reflow/merge_error'
25
- require 'git_reflow/os_detector'
26
18
  require 'git_reflow/sandbox'
27
19
  require 'git_reflow/workflow'
28
20
  require 'git_reflow/workflows/core'
@@ -47,20 +39,16 @@ module GitReflow
47
39
  Workflow.current
48
40
  end
49
41
 
50
- def default_editor
51
- "#{ENV['EDITOR'] || 'vi'}".freeze
52
- end
53
-
54
42
  def git_server
55
43
  @git_server ||= GitServer.connect provider: GitReflow::Config.get('reflow.git-server').strip, silent: true
56
44
  end
57
45
 
58
- def respond_to?(method_sym, include_all = false)
59
- (workflow and workflow.respond_to?(method_sym, include_all)) || super(method_sym, include_all)
46
+ def respond_to_missing?(method_sym, include_all = false)
47
+ (workflow && workflow.respond_to?(method_sym, include_all)) || super(method_sym, include_all)
60
48
  end
61
49
 
62
50
  def method_missing(method_sym, *arguments, &block)
63
- if workflow and workflow.respond_to? method_sym
51
+ if workflow && workflow.respond_to?(method_sym, false)
64
52
  workflow.send method_sym, *arguments, &block
65
53
  else
66
54
  super
@@ -1,25 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitReflow
4
+ # This is a utility module for getting and setting git-config variables.
2
5
  module Config
3
- extend self
6
+ CONFIG_FILE_PATH = "#{ENV['HOME']}/.gitconfig.reflow"
4
7
 
5
- CONFIG_FILE_PATH = "#{ENV['HOME']}/.gitconfig.reflow".freeze
8
+ module_function
6
9
 
10
+ # Gets the reqested git configuration variable.
11
+ #
12
+ # @param [String] key The key to get the value(s) for
13
+ # @option options [Boolean] :reload (false) whether to reload the value or use a cached value if available
14
+ # @option options [Boolean] :all (false) whether to return all keys for a multi-valued key
15
+ # @option options [Boolean] :local (false) whether to get the value specific to the current project
16
+ # @return the value of the git configuration
7
17
  def get(key, reload: false, all: false, local: false)
8
- if reload == false and cached_key_value = instance_variable_get(:"@#{key.tr('.-', '_')}")
9
- cached_key_value
18
+ return cached_git_config_value(key) unless reload || cached_git_config_value(key).empty?
19
+
20
+ local = local ? '--local ' : ''
21
+ if all
22
+ new_value = GitReflow::Sandbox.run("git config #{local}--get-all #{key}", loud: false, blocking: false)
10
23
  else
11
- local = local ? '--local ' : ''
12
- if all
13
- new_value = GitReflow::Sandbox.run("git config #{local}--get-all #{key}", loud: false, blocking: false)
14
- else
15
- new_value = GitReflow::Sandbox.run("git config #{local}--get #{key}", loud: false, blocking: false)
16
- end
17
- instance_variable_set(:"@#{key.tr('.-', '_')}", new_value.strip)
24
+ new_value = GitReflow::Sandbox.run("git config #{local}--get #{key}", loud: false, blocking: false)
18
25
  end
26
+ cache_git_config_key(key, new_value)
19
27
  end
20
28
 
29
+ # Sets the reqested git configuration variable.
30
+ #
31
+ # @param [String] key The key to set the value for
32
+ # @param [String] value The value to set it to
33
+ # @option options [Boolean] :local (false) whether to set the value specific to the current project
34
+ # @return the value of the git configuration
21
35
  def set(key, value, local: false)
22
- value = "#{value}".strip
36
+ value = value.to_s.strip
23
37
  if local
24
38
  GitReflow::Sandbox.run "git config --replace-all #{key} \"#{value}\"", loud: false, blocking: false
25
39
  else
@@ -27,8 +41,14 @@ module GitReflow
27
41
  end
28
42
  end
29
43
 
44
+ # Remove values of the reqested git configuration variable.
45
+ #
46
+ # @param [String] key The key to remove
47
+ # @option options [Boolean] :value (nil) The value of the key to remove
48
+ # @option options [Boolean] :local (false) whether to remove the value specific to the current project
49
+ # @return the result of running the git command
30
50
  def unset(key, value: nil, local: false)
31
- value = (value.nil?) ? "" : "\"#{value}\""
51
+ value = value.nil? ? '' : "\"#{value}\""
32
52
  if local
33
53
  GitReflow::Sandbox.run "git config --unset-all #{key} #{value}", loud: false, blocking: false
34
54
  else
@@ -36,6 +56,13 @@ module GitReflow
36
56
  end
37
57
  end
38
58
 
59
+ # Adds a new git configuration variable.
60
+ #
61
+ # @param [String] key The new key to set the value for
62
+ # @param [String] value The value to set it to
63
+ # @option options [Boolean] :local (false) whether to set the value specific to the current project
64
+ # @option options [Boolean] :global (false) whether to set the value globaly. if neither local or global is set gitreflow will default to using a configuration file
65
+ # @return the result of running the git command
39
66
  def add(key, value, local: false, global: false)
40
67
  if global
41
68
  GitReflow::Sandbox.run "git config --global --add #{key} \"#{value}\"", loud: false, blocking: false
@@ -45,5 +72,13 @@ module GitReflow
45
72
  GitReflow::Sandbox.run "git config -f #{CONFIG_FILE_PATH} --add #{key} \"#{value}\"", loud: false, blocking: false
46
73
  end
47
74
  end
75
+
76
+ def cached_git_config_value(key)
77
+ instance_variable_get(:"@#{key.tr('.-', '_')}").to_s
78
+ end
79
+
80
+ def cache_git_config_key(key, value)
81
+ instance_variable_set(:"@#{key.tr('.-', '_')}", value.to_s.strip)
82
+ end
48
83
  end
49
84
  end
@@ -1,51 +1,71 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'git_reflow/config'
2
4
  require 'git_reflow/sandbox'
3
5
 
4
6
  module GitReflow
7
+ # Includes many helper methods for common tasks within a git repository.
5
8
  module GitHelpers
6
9
  include Sandbox
7
10
 
11
+ def default_editor
12
+ ENV['EDITOR'] || 'vi'
13
+ end
14
+
8
15
  def git_root_dir
9
- return @git_root_dir if "#{@git_root_dir}".length > 0
16
+ return @git_root_dir unless @git_root_dir.to_s.empty?
10
17
  @git_root_dir = run('git rev-parse --show-toplevel', loud: false).strip
11
18
  end
12
19
 
13
20
  def git_editor_command
14
- git_editor = "#{GitReflow::Config.get('core.editor')}"
15
- if git_editor.length > 0
21
+ git_editor = GitReflow::Config.get('core.editor')
22
+ if !git_editor.empty?
16
23
  git_editor
17
24
  else
18
- GitReflow.default_editor
25
+ default_editor
19
26
  end
20
27
  end
21
28
 
22
29
  def remote_user
23
- return "" unless "#{GitReflow::Config.get('remote.origin.url')}".length > 0
30
+ return '' if GitReflow::Config.get('remote.origin.url').empty?
24
31
  extract_remote_user_and_repo_from_remote_url(GitReflow::Config.get('remote.origin.url'))[:user]
25
32
  end
26
33
 
27
34
  def remote_repo_name
28
- return "" unless "#{GitReflow::Config.get('remote.origin.url')}".length > 0
35
+ return '' if GitReflow::Config.get('remote.origin.url').empty?
29
36
  extract_remote_user_and_repo_from_remote_url(GitReflow::Config.get('remote.origin.url'))[:repo]
30
37
  end
31
38
 
39
+ def default_base_branch
40
+ base_branch_name = GitReflow::Config.get('reflow.base-branch')
41
+ return 'master' if base_branch_name.empty?
42
+ base_branch_name
43
+ end
44
+
32
45
  def current_branch
33
46
  run("git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g'", loud: false).strip
34
47
  end
35
48
 
36
49
  def pull_request_template
37
- filenames_to_try = %w( .github/PULL_REQUEST_TEMPLATE.md
38
- .github/PULL_REQUEST_TEMPLATE
39
- PULL_REQUEST_TEMPLATE.md
40
- PULL_REQUEST_TEMPLATE ).map do |file|
50
+ filenames_to_try = %w[.github/PULL_REQUEST_TEMPLATE.md
51
+ .github/PULL_REQUEST_TEMPLATE
52
+ PULL_REQUEST_TEMPLATE.md
53
+ PULL_REQUEST_TEMPLATE].map do |file|
41
54
  "#{git_root_dir}/#{file}"
42
55
  end
43
56
 
44
- filename = filenames_to_try.detect do |file|
45
- File.exist? file
57
+ parse_first_matching_template_file(filenames_to_try)
58
+ end
59
+
60
+ def merge_commit_template
61
+ filenames_to_try = %w[.github/MERGE_COMMIT_TEMPLATE.md
62
+ .github/MERGE_COMMIT_TEMPLATE
63
+ MERGE_COMMIT_TEMPLATE.md
64
+ MERGE_COMMIT_TEMPLATE].map do |file|
65
+ "#{git_root_dir}/#{file}"
46
66
  end
47
67
 
48
- File.read filename if filename
68
+ parse_first_matching_template_file(filenames_to_try)
49
69
  end
50
70
 
51
71
  def get_first_commit_message
@@ -53,12 +73,12 @@ module GitReflow
53
73
  end
54
74
 
55
75
  def push_current_branch(options = {})
56
- remote = options[:remote] || "origin"
76
+ remote = options[:remote] || 'origin'
57
77
  run_command_with_label "git push #{remote} #{current_branch}"
58
78
  end
59
79
 
60
80
  def update_current_branch(options = {})
61
- remote = options[:remote] || "origin"
81
+ remote = options[:remote] || 'origin'
62
82
  run_command_with_label "git pull #{remote} #{current_branch}"
63
83
  push_current_branch(options)
64
84
  end
@@ -86,23 +106,50 @@ module GitReflow
86
106
  run_command_with_label "git merge #{base_branch}"
87
107
  end
88
108
 
89
- def append_to_squashed_commit_message(message = '')
90
- tmp_squash_message_path = "#{git_root_dir}/.git/tmp_squash_msg"
91
- squash_message_path = "#{git_root_dir}/.git/SQUASH_MSG"
92
- File.open(tmp_squash_message_path, "w") do |file_content|
109
+ def append_to_merge_commit_message(message = '', merge_method: "squash")
110
+ tmp_merge_message_path = "#{git_root_dir}/.git/tmp_merge_msg"
111
+ dest_merge_message_path = merge_message_path(merge_method: merge_method)
112
+
113
+ run "touch #{tmp_merge_message_path}"
114
+
115
+ File.open(tmp_merge_message_path, "w") do |file_content|
93
116
  file_content.puts message
94
- if File.exists?(squash_message_path)
95
- File.foreach(squash_message_path) do |line|
117
+ if File.exists? dest_merge_message_path
118
+ File.foreach(dest_merge_message_path) do |line|
96
119
  file_content.puts line
97
120
  end
98
121
  end
99
122
  end
100
123
 
101
- run "mv #{tmp_squash_message_path} #{squash_message_path}"
124
+ run "mv #{tmp_merge_message_path} #{dest_merge_message_path}"
125
+ end
126
+
127
+ def merge_message_path(merge_method: nil)
128
+ merge_method = merge_method || GitReflow::Config.get("reflow.merge-method")
129
+ merge_method = "squash" if "#{merge_method}".length < 1
130
+ if merge_method =~ /squash/i
131
+ "#{git_root_dir}/.git/SQUASH_MSG"
132
+ else
133
+ "#{git_root_dir}/.git/MERGE_MSG"
134
+ end
102
135
  end
103
136
 
104
137
  private
105
138
 
139
+ def parse_first_matching_template_file(template_file_names)
140
+ filename = template_file_names.detect do |file|
141
+ File.exist? file
142
+ end
143
+
144
+ # Thanks to @Shalmezad for contribuiting the template `gsub` snippet :-)
145
+ # https://github.com/reenhanced/gitreflow/issues/51#issuecomment-253535093
146
+ if filename
147
+ template_content = File.read filename
148
+ template_content.gsub!(/\{\{([a-zA-Z_]+[a-zA-Z0-9_]*)\}\}/) { GitReflow.public_send($1) }
149
+ template_content
150
+ end
151
+ end
152
+
106
153
  def extract_remote_user_and_repo_from_remote_url(remote_url)
107
154
  result = { user: '', repo: '' }
108
155
  return result unless "#{remote_url}".length > 0