Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use $EDITOR as text editor fallback #184

Merged
merged 6 commits into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') || ENV['EDITOR']
Copy link
Contributor Author

@timraasveld timraasveld Jun 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the memoize because GitReflow::Config#get already seems to cache the "slow" code, and I got wrongly memoized values in the two it blocks in the spec

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use GitReflow::DEFAULT_EDITOR instead of ENV['EDITOR']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, didn't know that constant existed already :)

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 { allow(ENV).to receive(:[]).with('EDITOR').and_return 'vim' }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather see this set explicitly to avoid issues this may pose with the CI: ENV['EDITOR'] = 'vim'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!


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