diff --git a/lib/git_reflow.rb b/lib/git_reflow.rb index d661589..258c105 100644 --- a/lib/git_reflow.rb +++ b/lib/git_reflow.rb @@ -21,7 +21,9 @@ module GitReflow include GitHelpers extend self - DEFAULT_EDITOR = "#{ENV['EDITOR']}".freeze || "vi".freeze + def default_editor + "#{ENV['EDITOR']}".freeze || "vi".freeze + end def status(destination_branch) pull_request = git_server.find_open_pull_request( :from => current_branch, :to => destination_branch ) diff --git a/lib/git_reflow/commands/setup.rb b/lib/git_reflow/commands/setup.rb index d31734c..c1b9ff4 100644 --- a/lib/git_reflow/commands/setup.rb +++ b/lib/git_reflow/commands/setup.rb @@ -26,8 +26,8 @@ GitReflow::Config.set "constants.approvalRegex", GitReflow::GitServer::PullRequest::DEFAULT_APPROVAL_REGEX.to_s, local: reflow_options[:project_only] if GitReflow::Config.get('core.editor').length <= 0 - GitReflow::Config.set('core.editor', GitReflow::DEFAULT_EDITOR, local: reflow_options[:project_only]) - GitReflow.say "Updated git's editor (via git config key 'core.editor') to: #{GitReflow::DEFAULT_EDITOR}.", :notice + GitReflow::Config.set('core.editor', GitReflow.default_editor, local: reflow_options[:project_only]) + GitReflow.say "Updated git's editor (via git config key 'core.editor') to: #{GitReflow.default_editor}.", :notice end end end diff --git a/lib/git_reflow/git_helpers.rb b/lib/git_reflow/git_helpers.rb index 9652929..dd90007 100644 --- a/lib/git_reflow/git_helpers.rb +++ b/lib/git_reflow/git_helpers.rb @@ -10,7 +10,7 @@ def git_root_dir end def git_editor_command - @git_editor_command ||= GitReflow::Config.get('core.editor') + GitReflow::Config.get('core.editor') || GitReflow.default_editor end def remote_user diff --git a/spec/lib/git_reflow/git_helpers_spec.rb b/spec/lib/git_reflow/git_helpers_spec.rb index f3f0c52..fdf9a76 100644 --- a/spec/lib/git_reflow/git_helpers_spec.rb +++ b/spec/lib/git_reflow/git_helpers_spec.rb @@ -19,6 +19,23 @@ module Gitacular it { expect{ subject }.to have_run_command_silently "git rev-parse --show-toplevel" } end + describe '.git_editor_command' do + subject { Gitacular.git_editor_command } + before { ENV['EDITOR'] = 'vim' } + + it 'defaults to GitReflow config' do + allow(GitReflow::Config).to receive(:get).with('core.editor').and_return 'nano' + + expect(subject).to eq 'nano' + end + + it 'falls back to the environment variable $EDITOR' do + allow(GitReflow::Config).to receive(:get).with('core.editor').and_return nil + + expect(subject).to eq 'vim' + end + end + describe ".remote_user" do subject { Gitacular.remote_user }