From 4b4843b3314dc2d18df03bc419a3a49e39a160ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 3 Dec 2019 04:03:59 +0100 Subject: [PATCH] Improve `color.ui` config support - Query `Config` instead of `GlobalConfig` to respect per-repo and per-invocation configuration too. - Support "never" (synonym for "false") and "always" values. --- commands/issue.go | 6 +++++- features/pr-list.feature | 18 +++++++++++++++++- features/steps.rb | 25 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/commands/issue.go b/commands/issue.go index 32d5d9b92..309ec3a8e 100644 --- a/commands/issue.go +++ b/commands/issue.go @@ -634,8 +634,12 @@ func listLabels(cmd *Command, args *Args) { func colorizeOutput(colorSet bool, when string) bool { if !colorSet || when == "auto" { - if value, _ := git.GlobalConfig("color.ui"); value == "false" { + colorConfig, _ := git.Config("color.ui") + switch colorConfig { + case "false", "never": return false + case "always": + return true } return ui.IsTerminal(os.Stdout) } else if when == "never" { diff --git a/features/pr-list.feature b/features/pr-list.feature index 3e1453e36..3b67d90aa 100644 --- a/features/pr-list.feature +++ b/features/pr-list.feature @@ -155,13 +155,29 @@ Feature: hub pr list } """ When I successfully run `hub pr list --format "%I %pC %pS %Creset%n" --color` - Then the output should contain exactly: + Then its output should contain exactly: """ 999 \e[37m draft \e[m 102 \e[32m open \e[m 42 \e[35m merged \e[m 8 \e[31m closed \e[m\n """ + When I successfully run `hub -c color.ui=always pr list --format "%I %pC %pS %Creset%n"` + Then its output should contain exactly: + """ + 999 \e[37m draft \e[m + 102 \e[32m open \e[m + 42 \e[35m merged \e[m + 8 \e[31m closed \e[m\n + """ + When I successfully run `hub -c color.ui=false pr list --format "%I %pC%pS%Creset%n" --color=auto` + Then its output should contain exactly: + """ + 999 draft + 102 open + 42 merged + 8 closed\n + """ Scenario: Sort by number of comments ascending Given the GitHub API server: diff --git a/features/steps.rb b/features/steps.rb index 6a1c20454..c42b9ca13 100644 --- a/features/steps.rb +++ b/features/steps.rb @@ -290,3 +290,28 @@ contents.gsub!(/[0-9a-f]{7} \(Hub, \d seconds? ago\)/, "SHA1SHA (Hub, 0 seconds ago)") File.open(file, "w") { |f| f.write(contents) } end + +Then(/^its (output|stderr|stdout) should( not)? contain( exactly)?:$/) do |channel, negated, exactly, expected| + matcher = case channel.to_sym + when :output + :have_output + when :stderr + :have_output_on_stderr + when :stdout + :have_output_on_stdout + end + + commands = [last_command_started] + + output_string_matcher = if exactly + :an_output_string_being_eq + else + :an_output_string_including + end + + if negated + expect(commands).not_to include_an_object send(matcher, send(output_string_matcher, expected)) + else + expect(commands).to include_an_object send(matcher, send(output_string_matcher, expected)) + end +end