Skip to content

Commit

Permalink
[#184] Ensure default editor is used as fallback for legacy setups
Browse files Browse the repository at this point in the history
* Uses $EDITOR as editor fallback
* Makes default_editor a function instead of module constant

Merges #184 

LGTM given by: @codenamev
  • Loading branch information
timraasveld authored and codenamev committed Jun 7, 2016
1 parent ad7e7a2 commit 6ea9a25
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/git_reflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions lib/git_reflow/commands/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/git_reflow/git_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/git_reflow/git_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit 6ea9a25

Please sign in to comment.