From 8786424eb40f9ab976c3d3b9dfeef2adae576439 Mon Sep 17 00:00:00 2001 From: coridrew Date: Wed, 13 Aug 2014 12:59:41 -0500 Subject: [PATCH 01/15] added gitk regex --- GitTabExpansion.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/GitTabExpansion.ps1 b/GitTabExpansion.ps1 index 224c94da8..99bf54467 100644 --- a/GitTabExpansion.ps1 +++ b/GitTabExpansion.ps1 @@ -305,6 +305,7 @@ function TabExpansion($line, $lastWord) { # Execute git tab completion for all git-related commands "^$(Get-AliasPattern git) (.*)" { GitTabExpansion $lastBlock } "^$(Get-AliasPattern tgit) (.*)" { GitTabExpansion $lastBlock } + "^$(Get-AliasPattern gitk) (.*)" { GitTabExpansion $lastBlock } # Fall back on existing tab expansion default { if (Test-Path Function:\TabExpansionBackup) { TabExpansionBackup $line $lastWord } } From 02f1f8188b90ad4b1944c2b9503ec810693ee78f Mon Sep 17 00:00:00 2001 From: coridrew Date: Wed, 13 Aug 2014 13:36:51 -0500 Subject: [PATCH 02/15] added branch tab completion --- GitTabExpansion.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/GitTabExpansion.ps1 b/GitTabExpansion.ps1 index 99bf54467..38478f9d1 100644 --- a/GitTabExpansion.ps1 +++ b/GitTabExpansion.ps1 @@ -164,6 +164,11 @@ function GitTabExpansion($lastBlock) { # Need return statement to prevent fall-through. return $tortoiseGitCommands | where { $_ -like "$($matches['cmd'])*" } } + + # Handles gitk + if($lastBlock -match "^$(Get-AliasPattern gitk) (?\S*)$"){ + return gitBranches $matches['ref'] $true + } switch -regex ($lastBlock -replace "^$(Get-AliasPattern git) ","") { From 23c63e0ebae36360f520433981d2012a5d9af732 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Wed, 13 Aug 2014 13:46:59 -0500 Subject: [PATCH 03/15] Keith is obsessive about whitespace! --- GitTabExpansion.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/GitTabExpansion.ps1 b/GitTabExpansion.ps1 index 38478f9d1..2b606a51d 100644 --- a/GitTabExpansion.ps1 +++ b/GitTabExpansion.ps1 @@ -164,11 +164,11 @@ function GitTabExpansion($lastBlock) { # Need return statement to prevent fall-through. return $tortoiseGitCommands | where { $_ -like "$($matches['cmd'])*" } } - - # Handles gitk - if($lastBlock -match "^$(Get-AliasPattern gitk) (?\S*)$"){ - return gitBranches $matches['ref'] $true - } + + # Handles gitk + if($lastBlock -match "^$(Get-AliasPattern gitk) (?\S*)$"){ + return gitBranches $matches['ref'] $true + } switch -regex ($lastBlock -replace "^$(Get-AliasPattern git) ","") { @@ -310,7 +310,7 @@ function TabExpansion($line, $lastWord) { # Execute git tab completion for all git-related commands "^$(Get-AliasPattern git) (.*)" { GitTabExpansion $lastBlock } "^$(Get-AliasPattern tgit) (.*)" { GitTabExpansion $lastBlock } - "^$(Get-AliasPattern gitk) (.*)" { GitTabExpansion $lastBlock } + "^$(Get-AliasPattern gitk) (.*)" { GitTabExpansion $lastBlock } # Fall back on existing tab expansion default { if (Test-Path Function:\TabExpansionBackup) { TabExpansionBackup $line $lastWord } } From 48c8afc3e0bc49a26c97763e78b23f68bf3545af Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Wed, 13 Aug 2014 13:59:51 -0500 Subject: [PATCH 04/15] enabled multiple branch tc for gitk --- GitTabExpansion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitTabExpansion.ps1 b/GitTabExpansion.ps1 index 2b606a51d..c77bd5151 100644 --- a/GitTabExpansion.ps1 +++ b/GitTabExpansion.ps1 @@ -166,7 +166,7 @@ function GitTabExpansion($lastBlock) { } # Handles gitk - if($lastBlock -match "^$(Get-AliasPattern gitk) (?\S*)$"){ + if($lastBlock -match "^$(Get-AliasPattern gitk).* (?\S*)$"){ return gitBranches $matches['ref'] $true } From 84754a6452c3fd49bcad864dc47b4942ce89bace Mon Sep 17 00:00:00 2001 From: Dave Wyatt Date: Tue, 16 Dec 2014 16:09:47 -0500 Subject: [PATCH 05/15] Added "Administrator: " prefix to window title Posh-Git was not including this prefix when it set the title, and I keep forgetting which window was launched with "Run As Administrator" and which was not. --- GitPrompt.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/GitPrompt.ps1 b/GitPrompt.ps1 index 5f20fdb17..5b0354389 100644 --- a/GitPrompt.ps1 +++ b/GitPrompt.ps1 @@ -138,13 +138,22 @@ function Write-GitStatus($status) { } $repoName = Split-Path -Leaf (Split-Path $status.GitDir) $prefix = if ($s.EnableWindowTitle -is [string]) { $s.EnableWindowTitle } else { '' } - $Host.UI.RawUI.WindowTitle = "$prefix$repoName [$($status.Branch)]" + $adminHeader = Get-AdminTitleHeader + $Host.UI.RawUI.WindowTitle = "$adminHeader$prefix$repoName [$($status.Branch)]" } } elseif ( $Global:PreviousWindowTitle ) { $Host.UI.RawUI.WindowTitle = $Global:PreviousWindowTitle } } +function Get-AdminTitleHeader +{ + $currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent()) + $isAdminProcess = $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) + + if ($isAdminProcess) { return 'Administrator: ' } +} + if(!(Test-Path Variable:Global:VcsPromptStatuses)) { $Global:VcsPromptStatuses = @() } From 6686a524a5f5adcce077116354eacbcf947e5181 Mon Sep 17 00:00:00 2001 From: Jay Bazuzi Date: Thu, 8 Jan 2015 16:03:15 -0800 Subject: [PATCH 06/15] Update readme.me formatting --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index ec36dbe16..88d4d58ae 100644 --- a/readme.md +++ b/readme.md @@ -30,13 +30,13 @@ Install-Module posh-git Installing (manual) ------------------- -0. Verify you have PowerShell 2.0 or better with $PSVersionTable.PSVersion +0. Verify you have PowerShell 2.0 or better with `$PSVersionTable.PSVersion` 1. Verify execution of scripts is allowed with `Get-ExecutionPolicy` (should be `RemoteSigned` or `Unrestricted`). If scripts are not enabled, run PowerShell as Administrator and call `Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm`. 2. Verify that `git` can be run from PowerShell. If the command is not found, you will need to add a git alias or add `%ProgramFiles(x86)%\Git\cmd` - (or `%ProgramFiles%\Git\cmd` if you're still on 32-bit) to your PATH environment variable. + (or `%ProgramFiles%\Git\cmd` if you're still on 32-bit) to your `PATH` environment variable. 3. Clone the posh-git repository to your local machine. From 9921c2fa85c1bb9c9da57d03dedfeeb4275799f8 Mon Sep 17 00:00:00 2001 From: blue Date: Wed, 28 May 2014 16:30:21 +0100 Subject: [PATCH 07/15] Guess Pageant location if not in path Attempt to guess Pageant's location based on GIT_SSH/plink location if Pageant is not on the path. Towards #114 --- GitUtils.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index c6b90bd6a..1383db177 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -262,6 +262,16 @@ function Get-SshAgent() { return 0 } +# Attempt to guess Pageant's location +function Guess-Pageant() { + Write-Verbose "Pageant not in path. Trying to guess location." + if ($env:GIT_SSH -and (test-path $env:GIT_SSH)) { + $pageant = join-path (split-path $env:GIT_SSH) pageant + } + if (!(get-command $pageant -Erroraction SilentlyContinue)) { return } # Guessing failed. + else { return $pageant } +} + # Loosely based on bash script from http://help.github.com/ssh-key-passphrases/ function Start-SshAgent([switch]$Quiet) { [int]$agentPid = Get-SshAgent @@ -277,6 +287,7 @@ function Start-SshAgent([switch]$Quiet) { if ($env:GIT_SSH -imatch 'plink') { Write-Host "GIT_SSH set to $($env:GIT_SSH), using Pageant as SSH agent." $pageant = Get-Command pageant -TotalCount 1 -Erroraction SilentlyContinue + $pageant = if ($pageant) {$pageant} else {Guess-Pageant} if (!$pageant) { Write-Warning "Could not find Pageant."; return } & $pageant } else { @@ -302,6 +313,7 @@ function Get-SshPath($File = 'id_rsa') function Add-SshKey() { if ($env:GIT_SSH -imatch 'plink') { $pageant = Get-Command pageant -Erroraction SilentlyContinue | Select -First 1 -ExpandProperty Name + $pageant = if ($pageant) {$pageant} else {Guess-Pageant} if (!$pageant) { Write-Warning 'Could not find Pageant'; return } if ($args.Count -eq 0) { From 1d2b114acda6574d305256426ed168c1ea98bf7a Mon Sep 17 00:00:00 2001 From: blue Date: Wed, 28 May 2014 16:38:00 +0100 Subject: [PATCH 08/15] Guess ssh-agent/add location if not in path Attempt to guess ssh-agent and ssh-add's locations based on git.exe location if not on the path. Implements #114 --- GitUtils.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 1383db177..c0ff6a64b 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -272,6 +272,16 @@ function Guess-Pageant() { else { return $pageant } } +# Attempt to guess $program's location. For ssh-agent/ssh-add. +function Guess-Ssh($program = 'ssh-agent') { + Write-Verbose "$program not in path. Trying to guess location." + if (!(get-command git -Erroraction SilentlyContinue)) { Write-Warning 'git not in path'; return } + $sshLocation = join-path (get-item(get-command git).path).directory.parent.fullname bin + $sshLocation = join-path $sshLocation $program + if (!(get-command $sshLocation -Erroraction SilentlyContinue)) { return } # Guessing failed. + else { return $sshLocation } +} + # Loosely based on bash script from http://help.github.com/ssh-key-passphrases/ function Start-SshAgent([switch]$Quiet) { [int]$agentPid = Get-SshAgent @@ -292,6 +302,7 @@ function Start-SshAgent([switch]$Quiet) { & $pageant } else { $sshAgent = Get-Command ssh-agent -TotalCount 1 -ErrorAction SilentlyContinue + $sshAgent = if ($sshAgent) {$sshAgent} else {Guess-Ssh('ssh-agent')} if (!$sshAgent) { Write-Warning 'Could not find ssh-agent'; return } & $sshAgent | foreach { @@ -329,6 +340,7 @@ function Add-SshKey() { } } else { $sshAdd = Get-Command ssh-add -TotalCount 1 -ErrorAction SilentlyContinue + $sshAdd = if ($sshAdd) {$sshAdd} else {Guess-Ssh('ssh-add')} if (!$sshAdd) { Write-Warning 'Could not find ssh-add'; return } if ($args.Count -eq 0) { From 82a062696cb91dd922ba84a7be402b09bfdd7b60 Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 15 Nov 2014 11:21:24 +0000 Subject: [PATCH 09/15] Make less calls to Get-Command git --- GitUtils.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index c0ff6a64b..085f94337 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -275,8 +275,9 @@ function Guess-Pageant() { # Attempt to guess $program's location. For ssh-agent/ssh-add. function Guess-Ssh($program = 'ssh-agent') { Write-Verbose "$program not in path. Trying to guess location." - if (!(get-command git -Erroraction SilentlyContinue)) { Write-Warning 'git not in path'; return } - $sshLocation = join-path (get-item(get-command git).path).directory.parent.fullname bin + $gitItem = Get-Command git -Erroraction SilentlyContinue | Get-Item + if ($gitItem -eq $null) { Write-Warning 'git not in path'; return } + $sshLocation = join-path $gitItem.directory.parent.fullname bin $sshLocation = join-path $sshLocation $program if (!(get-command $sshLocation -Erroraction SilentlyContinue)) { return } # Guessing failed. else { return $sshLocation } From 28f83055219b380a21a0abbe2aa9c0d00b03b03b Mon Sep 17 00:00:00 2001 From: blue Date: Sat, 15 Nov 2014 11:23:05 +0000 Subject: [PATCH 10/15] Make less calls to $env:GIT_SSH --- GitUtils.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index 085f94337..9eb588c60 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -265,8 +265,9 @@ function Get-SshAgent() { # Attempt to guess Pageant's location function Guess-Pageant() { Write-Verbose "Pageant not in path. Trying to guess location." - if ($env:GIT_SSH -and (test-path $env:GIT_SSH)) { - $pageant = join-path (split-path $env:GIT_SSH) pageant + $gitSsh = $env:GIT_SSH + if ($gitSsh -and (test-path $gitSsh)) { + $pageant = join-path (split-path $gitSsh) pageant } if (!(get-command $pageant -Erroraction SilentlyContinue)) { return } # Guessing failed. else { return $pageant } From 2d77cc8355d7b4e9eabfb770097b172da689a752 Mon Sep 17 00:00:00 2001 From: Dave Wyatt Date: Thu, 14 May 2015 07:47:56 -0400 Subject: [PATCH 11/15] Cached result of administrator check --- GitPrompt.ps1 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/GitPrompt.ps1 b/GitPrompt.ps1 index 5b0354389..1c4ca45d3 100644 --- a/GitPrompt.ps1 +++ b/GitPrompt.ps1 @@ -52,6 +52,11 @@ $global:GitPromptSettings = New-Object PSObject -Property @{ Debug = $false } +$currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent()) +$isAdminProcess = $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) + +$adminHeader = if ($isAdminProcess) { 'Administrator: ' } else { '' } + $WindowTitleSupported = $true if (Get-Module NuGet) { $WindowTitleSupported = $false @@ -138,22 +143,13 @@ function Write-GitStatus($status) { } $repoName = Split-Path -Leaf (Split-Path $status.GitDir) $prefix = if ($s.EnableWindowTitle -is [string]) { $s.EnableWindowTitle } else { '' } - $adminHeader = Get-AdminTitleHeader - $Host.UI.RawUI.WindowTitle = "$adminHeader$prefix$repoName [$($status.Branch)]" + $Host.UI.RawUI.WindowTitle = "$script:adminHeader$prefix$repoName [$($status.Branch)]" } } elseif ( $Global:PreviousWindowTitle ) { $Host.UI.RawUI.WindowTitle = $Global:PreviousWindowTitle } } -function Get-AdminTitleHeader -{ - $currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent()) - $isAdminProcess = $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) - - if ($isAdminProcess) { return 'Administrator: ' } -} - if(!(Test-Path Variable:Global:VcsPromptStatuses)) { $Global:VcsPromptStatuses = @() } From d97fc00de2bf6fec9567cb97b8872a71d89d306e Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 14 Apr 2015 19:03:41 +0100 Subject: [PATCH 12/15] Warn if PowerShell < 3 encountered on Import --- posh-git.psm1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/posh-git.psm1 b/posh-git.psm1 index 38e921ce1..2c14f8941 100644 --- a/posh-git.psm1 +++ b/posh-git.psm1 @@ -1,5 +1,11 @@ if (Get-Module posh-git) { return } +if ($PSVersionTable.PSVersion.Major -lt 3) { + Write-Warning ("posh-git support for PowerShell 2.0 is deprecated; you have version $($Host.Version).`n" + + "To download version 3.0, please visit https://www.microsoft.com/en-us/download/details.aspx?id=34595`n" + + "For more information and to discuss this, please visit https://github.com/dahlbyk/posh-git/issues/163`n") +} + Push-Location $psScriptRoot .\CheckVersion.ps1 > $null @@ -23,8 +29,8 @@ Export-ModuleMember ` 'Invoke-NullCoalescing', 'Write-GitStatus', 'Write-Prompt', - 'Get-GitStatus', - 'Enable-GitColors', + 'Get-GitStatus', + 'Enable-GitColors', 'Get-GitDirectory', 'TabExpansion', 'Get-AliasPattern', From 67e11eb1ba7c6b35d65e9ec346f85312264f4596 Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 14 Apr 2015 20:00:24 +0100 Subject: [PATCH 13/15] Add a flag to suppress deprecation warning Allow Powershell 2 support deprecation warning to be suppressed by importing the module with a true value as an argument. The ability to pass arguments through Import-Module is pretty limited, accepting only positional arguments, but it still seems a preferable option to environment variables or asking users to modify posh-git directly. Closes #163 --- posh-git.psm1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/posh-git.psm1 b/posh-git.psm1 index 2c14f8941..c8677d0d1 100644 --- a/posh-git.psm1 +++ b/posh-git.psm1 @@ -1,9 +1,12 @@ +param([switch]$NoVersionWarn = $false) + if (Get-Module posh-git) { return } -if ($PSVersionTable.PSVersion.Major -lt 3) { +if ($PSVersionTable.PSVersion.Major -lt 3 -and !$NoVersionWarn) { Write-Warning ("posh-git support for PowerShell 2.0 is deprecated; you have version $($Host.Version).`n" + "To download version 3.0, please visit https://www.microsoft.com/en-us/download/details.aspx?id=34595`n" + - "For more information and to discuss this, please visit https://github.com/dahlbyk/posh-git/issues/163`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'.") } Push-Location $psScriptRoot From 144025220363495a7b8112cb47ddb113c92d2467 Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 14 Apr 2015 20:04:17 +0100 Subject: [PATCH 14/15] Update readme.md to reflect PS 2.0 deprecation --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 88d4d58ae..3cbc7e30c 100644 --- a/readme.md +++ b/readme.md @@ -5,11 +5,11 @@ A set of PowerShell scripts which provide Git/PowerShell integration ### Prompt for Git repositories The prompt within Git repositories can show the current branch and the state of files (additions, modifications, deletions) within. - + ### Tab completion - Provides tab completion for common commands when using git. + Provides tab completion for common commands when using git. E.g. `git ch` --> `git checkout` - + Usage ----- @@ -30,7 +30,7 @@ Install-Module posh-git Installing (manual) ------------------- -0. Verify you have PowerShell 2.0 or better with `$PSVersionTable.PSVersion` +0. Verify you have PowerShell 2.0 or better with `$PSVersionTable.PSVersion`. PowerShell 3.0 is preferred as 2.0 support is deprecated. 1. Verify execution of scripts is allowed with `Get-ExecutionPolicy` (should be `RemoteSigned` or `Unrestricted`). If scripts are not enabled, run PowerShell as Administrator and call `Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm`. From c71a174a7fd8ac58b18dc3ecb417233c358b87e4 Mon Sep 17 00:00:00 2001 From: blue Date: Thu, 14 May 2015 16:39:35 +0100 Subject: [PATCH 15/15] Correct PS version comparison --- posh-git.psm1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/posh-git.psm1 b/posh-git.psm1 index c8677d0d1..0c8508a23 100644 --- a/posh-git.psm1 +++ b/posh-git.psm1 @@ -2,8 +2,10 @@ param([switch]$NoVersionWarn = $false) if (Get-Module posh-git) { return } -if ($PSVersionTable.PSVersion.Major -lt 3 -and !$NoVersionWarn) { - Write-Warning ("posh-git support for PowerShell 2.0 is deprecated; you have version $($Host.Version).`n" + +$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 3.0, please visit https://www.microsoft.com/en-us/download/details.aspx?id=34595`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'.")