diff --git a/src/CheckRequirements.ps1 b/src/CheckRequirements.ps1 index eb6e3b3f1..2501b3cec 100644 --- a/src/CheckRequirements.ps1 +++ b/src/CheckRequirements.ps1 @@ -1,4 +1,7 @@ -$Global:GitMissing = $false +$global:GitMissing = $false + +$requiredVersion = [Version]'1.7.2' +$script:GitVersion = $requiredVersion if (!(Get-Command git -TotalCount 1 -ErrorAction SilentlyContinue)) { Write-Warning "git command could not be found. Please create an alias or add it to your PATH." @@ -6,13 +9,12 @@ if (!(Get-Command git -TotalCount 1 -ErrorAction SilentlyContinue)) { return } -$requiredVersion = [Version]'1.7.2' if ([string](git --version 2> $null) -match '(?\d+(?:\.\d+)+)') { - $version = [Version]$Matches['ver'] + $script:GitVersion = [System.Version]$Matches['ver'] } -if ($version -lt $requiredVersion) { - Write-Warning "posh-git requires Git $requiredVersion or better. You have $version." +if ($GitVersion -lt $requiredVersion) { + Write-Warning "posh-git requires Git $requiredVersion or better. You have $GitVersion." $false } else { diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index afa2bc028..6823fb610 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -57,6 +57,10 @@ $script:someCommands = @('add','am','annotate','archive','bisect','blame','branc 'notes','prune','pull','push','rebase','reflog','remote','rerere','reset','revert','rm', 'shortlog','show','stash','status','submodule','svn','tag','whatchanged', 'worktree') +if ((($PSVersionTable.PSVersion.Major -eq 5) -or $IsWindows) -and ($script:GitVersion -ge [System.Version]'2.16.2')) { + $script:someCommands += 'update-git-for-windows' +} + $script:gitCommandsWithLongParams = $longGitParams.Keys -join '|' $script:gitCommandsWithShortParams = $shortGitParams.Keys -join '|' $script:gitCommandsWithParamValues = $gitParamValues.Keys -join '|' diff --git a/src/posh-git.psm1 b/src/posh-git.psm1 index 1c360fdb4..f2487714a 100644 --- a/src/posh-git.psm1 +++ b/src/posh-git.psm1 @@ -1,6 +1,6 @@ param([switch]$NoVersionWarn, [switch]$ForcePoshGitPrompt) -& $PSScriptRoot\CheckRequirements.ps1 > $null +. $PSScriptRoot\CheckRequirements.ps1 > $null . $PSScriptRoot\ConsoleMode.ps1 . $PSScriptRoot\Utils.ps1 diff --git a/test/Shared.ps1 b/test/Shared.ps1 index 87a140b84..9b5c025a4 100644 --- a/test/Shared.ps1 +++ b/test/Shared.ps1 @@ -21,7 +21,7 @@ function global:git { $cmdline = "$args" # Write-Warning "in global git func with: $cmdline" switch ($cmdline) { - '--version' { 'git version 2.11.0.windows.1' } + '--version' { 'git version 2.16.2.windows.1' } 'help' { Get-Content $PSScriptRoot\git-help.txt } default { $res = Invoke-Expression "&$gitbin $cmdline" diff --git a/test/TabExpansion.Tests.ps1 b/test/TabExpansion.Tests.ps1 index 99ce4656c..822f45801 100644 --- a/test/TabExpansion.Tests.ps1 +++ b/test/TabExpansion.Tests.ps1 @@ -37,6 +37,17 @@ Describe 'TabExpansion Tests' { $result2 -contains 'set-head' | Should Be $true $result2 -contains 'set-url' | Should Be $true } + It 'Tab completes update-git-for-windows only on Windows' { + $result = & $module GitTabExpansionInternal 'git update-' + + if ((($PSVersionTable.PSVersion.Major -eq 5) -or $IsWindows)) { + $result -contains '' | Should Be $false + $result -contains 'update-git-for-windows' | Should Be $true + } + else { + $result | Should BeNullOrEmpty + } + } } Context 'Fetch/Push/Pull TabExpansion Tests' { BeforeEach {