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

Remove PowerShell v2 support. #427

Merged
merged 7 commits into from
Feb 20, 2017
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
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch Pester Tests",
"script": "${workspaceRoot}/test/testDebugHarness.ps1",
"name": "PowerShell Pester Tests",
"script": "Invoke-Pester",
"args": [],
"cwd": "${file}"
"cwd": "${workspaceRoot}/test"
},
{
"type": "PowerShell",
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# posh-git Release History

## 1.0.0 - TBD
This release introduces breaking changes with 0.x to both drop support for PowerShell 2.0 and support writing prompt strings using ANSI sequences.
The ANSI sequence support will help with cross-platform PowerShell support, which is another goal of this release.

- Drop support for PowerShell 2.0
  ([#163](https://github.com/dahlbyk/posh-git/issues/163))
 ([PR #427](https://github.com/dahlbyk/posh-git/pull/427))
- Remove public `Enable-GitColors`, `Get-AliasPattern` and `Get-GitBranch`; plus `Invoke-NullCoalescing` and its `??` alias
([#93](https://github.com/dahlbyk/posh-git/issues/93))
 ([PR #427](https://github.com/dahlbyk/posh-git/pull/427))

## 0.7.0 - February 14, 2017
This release has focused on improving the "getting started" experience by adding an `Add-PoshGitToProfile` command that
modifies the user's PowerShell profile script to import the posh-git module whenever PowerShell starts.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Rather than turn off file status entirely (`$GitPromptSettings.EnableFileStatus
### Prerequisites
Before installing posh-git make sure the following prerequisites have been met.

1. PowerShell 2.0 or higher. Check your PowerShell version by executing `$PSVersionTable.PSVersion`.
1. PowerShell 3.0 or higher. Check your PowerShell version by executing `$PSVersionTable.PSVersion`.

2. Script execution policy must be set to either `RemoteSigned` or `Unrestricted`.
Check the script execution policy setting by executing `Get-ExecutionPolicy`.
Expand All @@ -45,20 +45,20 @@ You may be asked if you trust packages coming from the PowerShell Gallery. Answe

If you are on PowerShell version 3 or 4, you will need to install the [Package Management Preview for PowerShell 3 & 4](https://www.microsoft.com/en-us/download/details.aspx?id=51451) in order to run the command above.

Note: If you get an error message from Install-Module about NuGet being required to interact with NuGet-based repositories, execute the following commands to bootstrap the NuGet provider:
Note: If you get an error message from `Install-Module` about NuGet being required to interact with NuGet-based repositories, execute the following commands to bootstrap the NuGet provider:
```
Install-PackageProvider NuGet -Force
Import-PackageProvider NuGet -Force
```
Then retry the Install-Module command above.
Then retry the `Install-Module` command above.

After you have successfully installed the posh-git module from the PowerShell Gallery, you will be able to update to a newer version by executing the command:
```
Update-Module posh-git
```

### Installing posh-git via Chocolatey
If you have PowerShell version 2 or are having issues using Install-Module with PowerShell version 3 or 4, you can use [Chocolatey](https://chocolatey.org) to install posh-git.
If you are having issues using `Install-Module` with PowerShell version 3 or 4, you can use [Chocolatey](https://chocolatey.org) to install posh-git.
If you don't have Chocolatey, you can install it from the [Chocolately Install page](https://chocolatey.org/install).
With Chocolatey installed, execute the following command to install posh-git:
```
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ os:

branches:
only:
- develop
- master

init:
Expand Down
2 changes: 1 addition & 1 deletion chocolatey/poshgit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>poshgit</id>
<title>posh-git</title>
<version>0.7.0</version>
<version>1.0.0-pre00</version>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<authors>Keith Dahlby, Mark Embling, Jeremy Skinner, Keith Hill</authors>
<owners>Keith Dahlby</owners>
<description>### posh-git
Expand Down
6 changes: 4 additions & 2 deletions src/CheckVersion.ps1 → src/CheckRequirements.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ if (!(Get-Command git -TotalCount 1 -ErrorAction SilentlyContinue)) {
}

$requiredVersion = [Version]'1.7.2'
if ([String](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)') {
if ([string](git --version 2> $null) -match '(?<ver>\d+(?:\.\d+)+)') {
$version = [Version]$Matches['ver']
}

if ($version -lt $requiredVersion) {
Write-Warning "posh-git requires Git $requiredVersion or better. You have $version."
$false
} else {
}
else {
$true
}
34 changes: 16 additions & 18 deletions src/posh-git.psd1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@{

# Script module or binary module file associated with this manifest.
ModuleToProcess = 'posh-git.psm1'
RootModule = 'posh-git.psm1'

# Version number of this module.
ModuleVersion = '0.7.0'
ModuleVersion = '1.0.0.0'

# ID used to uniquely identify this module
GUID = '74c9fd30-734b-4c89-a8ae-7727ad21d1d5'
Expand All @@ -19,27 +19,23 @@ Copyright = '(c) 2010-2017 Keith Dahlby and contributors'
Description = 'Provides prompt with Git status summary information and tab completion for Git commands, parameters, remotes and branch names.'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '2.0'
PowerShellVersion = '3.0'

# Functions to export from this module
FunctionsToExport = @(
'Invoke-NullCoalescing',
'Add-PoshGitToProfile',
'Get-GitStatus',
'Get-GitDirectory',
'Update-AllBranches',
'Write-GitStatus',
'Write-Prompt',
'Write-VcsStatus',
'Get-GitBranch',
'Get-GitStatus',
'Enable-GitColors',
'Get-GitDirectory',
'TabExpansion',
'Get-AliasPattern',
'Get-SshAgent',
'Start-SshAgent',
'Stop-SshAgent',
'Add-SshKey',
'Get-SshPath',
'Update-AllBranches',
'TabExpansion',
'tgit'
)

Expand All @@ -50,27 +46,29 @@ CmdletsToExport = @()
VariablesToExport = @()

# Aliases to export from this module
AliasesToExport = @('??')
AliasesToExport = @()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove until we stumble on an alias we want to export (unlikely)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty array helps with overall system performance.

If you omit the entry, PowerShell does more expensive work to see if you meant to export any aliases.


# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
# Private data to pass to the module specified in RootModule/ModuleToProcess.
# This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('git', 'prompt', 'tab', 'tab-completion', 'tab-expansion', 'tabexpansion')

# A URL to the license for this module.
LicenseUri = 'https://github.com/dahlbyk/posh-git/blob/v0.7.0/LICENSE.txt'
LicenseUri = 'https://github.com/dahlbyk/posh-git/blob/develop/LICENSE.txt'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/dahlbyk/posh-git'

# ReleaseNotes of this module
ReleaseNotes = 'https://github.com/dahlbyk/posh-git/blob/v0.7.0/CHANGELOG.md'
ReleaseNotes = 'https://github.com/dahlbyk/posh-git/blob/develop/CHANGELOG.md'

} # End of PSData hashtable
# TODO: REMOVE BEFOE RELEASE
PreReleaseVersion = 'pre00'
}

} # End of PrivateData hashtable
}

}
38 changes: 11 additions & 27 deletions src/posh-git.psm1
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
param([switch]$NoVersionWarn,[switch]$ForcePoshGitPrompt)
param([switch]$NoVersionWarn, [switch]$ForcePoshGitPrompt)

if (Get-Module posh-git) { return }

$psv = $PSVersionTable.PSVersion

if ($psv.Major -lt 3 -and !$NoVersionWarn) {
Write-Warning ("posh-git support for PowerShell 2.0 is deprecated; you have version $($psv).`n" +
"To download version 5.0, please visit https://www.microsoft.com/en-us/download/details.aspx?id=50395`n" +
"For more information and to discuss this, please visit https://github.com/dahlbyk/posh-git/issues/163`n" +
"To suppress this warning, change your profile to include 'Import-Module posh-git -Args `$true'.")
}

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

. $PSScriptRoot\Utils.ps1
. $PSScriptRoot\GitUtils.ps1
Expand All @@ -27,11 +16,12 @@ Get-TempEnv 'SSH_AGENT_PID'
Get-TempEnv 'SSH_AUTH_SOCK'

# Get the default prompt definition.
if (($psv.Major -eq 2) -or ![Runspace]::DefaultRunspace.InitialSessionState.Commands) {
$initialSessionState = [Runspace]::DefaultRunspace.InitialSessionState
if (!$initialSessionState.Commands -or !$initialSessionState.Commands['prompt']) {
$defaultPromptDef = "`$(if (test-path variable:/PSDebugContext) { '[DBG]: ' } else { '' }) + 'PS ' + `$(Get-Location) + `$(if (`$nestedpromptlevel -ge 1) { '>>' }) + '> '"
}
else {
$defaultPromptDef = [Runspace]::DefaultRunspace.InitialSessionState.Commands['prompt'].Definition
$defaultPromptDef = $initialSessionState.Commands['prompt'].Definition
}

# If there is no prompt function or the prompt function is the default, replace the current prompt function definition
Expand All @@ -44,8 +34,7 @@ if (!$currentPromptDef) {
}

if ($ForcePoshGitPrompt -or !$currentPromptDef -or ($currentPromptDef -eq $defaultPromptDef)) {
# Have to use [scriptblock]::Create() to get debugger detection to work in PS v2
$poshGitPromptScriptBlock = [scriptblock]::Create(@'
$poshGitPromptScriptBlock = {
if ($GitPromptSettings.DefaultPromptEnableTiming) {
$sw = [System.Diagnostics.Stopwatch]::StartNew()
}
Expand Down Expand Up @@ -107,7 +96,7 @@ if ($ForcePoshGitPrompt -or !$currentPromptDef -or ($currentPromptDef -eq $defau

$global:LASTEXITCODE = $origLastExitCode
$expandedPromptSuffix
'@)
}

# Set the posh-git prompt as the default prompt
Set-Item Function:\prompt -Value $poshGitPromptScriptBlock
Expand All @@ -128,25 +117,20 @@ $ExecutionContext.SessionState.Module.OnRemove = {
}

$exportModuleMemberParams = @{
Alias = @('??') # TODO: Remove in 1.0.0
Function = @(
'Invoke-NullCoalescing',
'Add-PoshGitToProfile',
'Get-GitDirectory',
'Get-GitStatus',
'Update-AllBranches',
'Write-GitStatus',
'Write-Prompt',
'Write-VcsStatus',
'Get-GitBranch',
'Get-GitStatus',
'Enable-GitColors',
'Get-GitDirectory',
'TabExpansion',
'Get-AliasPattern',
'Get-SshAgent',
'Start-SshAgent',
'Stop-SshAgent',
'Add-SshKey',
'Get-SshPath',
'Update-AllBranches',
'TabExpansion',
'tgit'
)
}
Expand Down
24 changes: 13 additions & 11 deletions test/Get-GitBranch.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
. $PSScriptRoot\Shared.ps1

Describe 'Get-GitBranch Tests' {
Context 'Get-GitBranch GIT_DIR Tests' {
It 'Returns GIT_DIR! when in .git dir of the repo' {
$repoRoot = (Resolve-Path $PSScriptRoot\..).Path
Set-Location $repoRoot\.git -ErrorAction Stop
Get-GitBranch | Should BeExactly 'GIT_DIR!'
}
It 'Returns correct path when in a child folder of the .git dir of the repo' {
$repoRoot = (Resolve-Path $PSScriptRoot\..).Path
Set-Location $repoRoot\.git\hooks -ErrorAction Stop
Get-GitBranch | Should BeExactly 'GIT_DIR!'
InModuleScope posh-git {
Describe 'Get-GitBranch Tests' {
Context 'Get-GitBranch GIT_DIR Tests' {
It 'Returns GIT_DIR! when in .git dir of the repo' {
$repoRoot = (Resolve-Path $PSScriptRoot\..).Path
Set-Location $repoRoot\.git -ErrorAction Stop
Get-GitBranch | Should BeExactly 'GIT_DIR!'
}
It 'Returns correct path when in a child folder of the .git dir of the repo' {
$repoRoot = (Resolve-Path $PSScriptRoot\..).Path
Set-Location $repoRoot\.git\hooks -ErrorAction Stop
Get-GitBranch | Should BeExactly 'GIT_DIR!'
}
}
}
}
5 changes: 4 additions & 1 deletion test/Utils.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
Describe 'Utils Function Tests' {
Context 'Add-PoshGitToProfile Tests' {
BeforeAll {
$newLine = [System.Environment]::NewLine
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$newLine = [System.Environment]::NewLine
}
BeforeEach {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$profilePath = [System.IO.Path]::GetTempFileName()
}
AfterEach {
Expand Down Expand Up @@ -84,6 +86,7 @@ New-Alias pscore C:\Users\Keith\GitHub\rkeithhill\PowerShell\src\powershell-win-

Context 'Test-PoshGitImportedInScript Tests' {
BeforeEach {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$profilePath = [System.IO.Path]::GetTempFileName()
}
AfterEach {
Expand Down
2 changes: 0 additions & 2 deletions test/testDebugHarness.ps1

This file was deleted.