提交 87050ce9 编写于 作者: M Mislav Marohnić

Evaluate embedded environment variables in git core.editor

Fixes #430
上级 b068db42
......@@ -437,6 +437,7 @@ module Hub
def git_editor
# possible: ~/bin/vi, $SOME_ENVIRONMENT_VARIABLE, "C:\Program Files\Vim\gvim.exe" --nofork
editor = git_command 'var GIT_EDITOR'
editor.gsub!(/\$(\w+|\{\w+\})/) { ENV[$1.tr('{}', '')] }
editor = ENV[$1] if editor =~ /^\$(\w+)$/
editor = File.expand_path editor if (editor =~ /^[~.]/ or editor.index('/')) and editor !~ /["']/
# avoid shellsplitting "C:\Program Files"
......
......@@ -50,6 +50,20 @@ class ContextTest < Test::Unit::TestCase
end
end
def test_editor_with_embedded_env_variable
stub_command_output 'var GIT_EDITOR', '$EDITOR -w'
with_env('EDITOR', 'subl') do
assert_equal %w'subl -w', context.git_editor
end
end
def test_editor_with_curly_brackets_embedded_env_variable
stub_command_output 'var GIT_EDITOR', 'my${EDITOR}2 -w'
with_env('EDITOR', 'subl') do
assert_equal %w'mysubl2 -w', context.git_editor
end
end
private
def stub_command_output(cmd, value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册