Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for update-git-for-windows command on supported Git versions #642

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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