From d4cd496e33ca657d732cd4c950513346f5d8af85 Mon Sep 17 00:00:00 2001 From: LittleboyHarry Date: Thu, 1 Oct 2020 00:06:40 +0800 Subject: [PATCH 1/4] Fixed non-ascii branch name garbled. --- src/Utils.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 5e138cdbe..bac520482 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -32,16 +32,16 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) { # A native executable that writes to stderr AND has its stderr redirected will generate non-terminating # error records if the user has set $ErrorActionPreference to Stop. Override that value in this scope. $ErrorActionPreference = 'Continue' - if ($currentEncoding.IsSingleByte) { - try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch [System.IO.IOException] {} + if (!$currentEncoding.IsSingleByte) { + [Console]::OutputEncoding = [Text.Encoding]::UTF8 + & $cmd + [Console]::OutputEncoding = $currentEncoding + } + else { + & $cmd } - & $cmd } finally { - if ($currentEncoding.IsSingleByte) { - try { [Console]::OutputEncoding = $currentEncoding } catch [System.IO.IOException] {} - } - # Clear out stderr output that was added to the $Error collection, putting those errors in a module variable if ($global:Error.Count -gt $errorCount) { $numNewErrors = $global:Error.Count - $errorCount From aa58e395276062084a18d4d17d2e81adc8c71962 Mon Sep 17 00:00:00 2001 From: LittleboyHarry Date: Thu, 1 Oct 2020 01:07:42 +0800 Subject: [PATCH 2/4] Fixed single byte Tests in TabExpansion --- src/Utils.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index bac520482..2e97e9d1e 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -32,12 +32,12 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) { # A native executable that writes to stderr AND has its stderr redirected will generate non-terminating # error records if the user has set $ErrorActionPreference to Stop. Override that value in this scope. $ErrorActionPreference = 'Continue' - if (!$currentEncoding.IsSingleByte) { + try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 & $cmd [Console]::OutputEncoding = $currentEncoding } - else { + catch [System.IO.IOException] { & $cmd } } From e439c99d9db1941b0a4194667db9928a1c5dcfba Mon Sep 17 00:00:00 2001 From: LittleboyHarry Date: Thu, 1 Oct 2020 17:11:30 +0800 Subject: [PATCH 3/4] Avoid re-fetch git branch name when IOException --- src/Utils.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 2e97e9d1e..a52f0f9e8 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -35,7 +35,10 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) { try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 & $cmd - [Console]::OutputEncoding = $currentEncoding + try { + [Console]::OutputEncoding = $currentEncoding + } + catch [System.IO.IOException] {} } catch [System.IO.IOException] { & $cmd From 3d212c7b49af3ce083f4628e8248c31298e43ad7 Mon Sep 17 00:00:00 2001 From: LittleboyHarry Date: Fri, 2 Oct 2020 09:53:33 +0800 Subject: [PATCH 4/4] Accept the owner advice in Utils.ps1 --- src/Utils.ps1 | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index a52f0f9e8..193fa938e 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -32,19 +32,13 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) { # A native executable that writes to stderr AND has its stderr redirected will generate non-terminating # error records if the user has set $ErrorActionPreference to Stop. Override that value in this scope. $ErrorActionPreference = 'Continue' - try { - [Console]::OutputEncoding = [Text.Encoding]::UTF8 - & $cmd - try { - [Console]::OutputEncoding = $currentEncoding - } - catch [System.IO.IOException] {} - } - catch [System.IO.IOException] { - & $cmd - } + + try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch [System.IO.IOException] {} + & $cmd } finally { + try { [Console]::OutputEncoding = $currentEncoding } catch [System.IO.IOException] {} + # Clear out stderr output that was added to the $Error collection, putting those errors in a module variable if ($global:Error.Count -gt $errorCount) { $numNewErrors = $global:Error.Count - $errorCount