Skip to content

Commit

Permalink
Add support for update-git-for-windows command on supported Git versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rkeithhill committed Nov 18, 2018
1 parent ce6381b commit f05b197
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/CheckRequirements.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
$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."
$Global:GitMissing = $true
return
}

$requiredVersion = [Version]'1.7.2'
if ([string](git --version 2> $null) -match '(?<ver>\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 {
Expand Down
4 changes: 4 additions & 0 deletions src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 '|'
Expand Down
2 changes: 1 addition & 1 deletion src/posh-git.psm1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
param([switch]$NoVersionWarn, [switch]$ForcePoshGitPrompt)

& $PSScriptRoot\CheckRequirements.ps1 > $null
. $PSScriptRoot\CheckRequirements.ps1 > $null

. $PSScriptRoot\ConsoleMode.ps1
. $PSScriptRoot\Utils.ps1
Expand Down
2 changes: 1 addition & 1 deletion test/Shared.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f05b197

Please sign in to comment.