Skip to content
Open
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
5 changes: 4 additions & 1 deletion chocolatey/poshgit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ See profile.example.ps1 as to how you can integrate the tab completion and/or gi
Note on performance: displaying file status in the git prompt for a very large repo can be prohibitively slow. Rather than turn off file status entirely, you can disable it on a repo-by-repo basis by adding individual repository paths to `$GitPromptSettings.RepositoriesInWhichToDisableFileStatus`.
</description>
<summary>Provides prompt with Git status summary information and tab completion for Git commands, parameters, remotes and branch names.</summary>
<tags>poshgit posh-git powershell git</tags>
<tags>admin posh-git powershell module git</tags>
<projectUrl>https://github.com/dahlbyk/posh-git</projectUrl>
<licenseUrl>https://github.com/dahlbyk/posh-git/blob/v0/LICENSE.txt</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<packageSourceUrl>https://github.com/dahlbyk/posh-git</packageSourceUrl>
<docsUrl>https://github.com/pauby/posh-git/blob/master/README.md</docsUrl>
<bugTrackerUrl>https://github.com/dahlbyk/posh-git/issues</bugTrackerUrl>
<dependencies>
<dependency id="chocolatey" version="0.9.10" />
<dependency id="git" />
Expand Down
4 changes: 4 additions & 0 deletions chocolatey/tools/chocolateyBeforeModify.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$ErrorActionPreference = 'Stop'

$moduleName = 'posh-git' # this could be different from package name
Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue
76 changes: 31 additions & 45 deletions chocolatey/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,49 +1,35 @@
try {
$poshgitPath = join-path (Get-ToolsLocation) 'poshgit'

try {
if (test-path($poshgitPath)) {
Write-Host "Attempting to remove existing `'$poshgitPath`'."
remove-item $poshgitPath -recurse -force
}
} catch {
Write-Host "Could not remove `'$poshgitPath`'"
}
$ErrorActionPreference = 'Stop'

$version = "v$Env:chocolateyPackageVersion"
if ($version -eq 'v') { $version = 'master' }
$poshGitInstall = if ($env:poshGit ) { $env:poshGit } else { "https://github.com/dahlbyk/posh-git/zipball/$version" }
$zip = Install-ChocolateyZipPackage 'poshgit' $poshGitInstall $poshgitPath
$currentVersionPath = Get-ChildItem "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime | Select-Object -Last 1

if(Test-Path $PROFILE) {
$oldProfile = @(Get-Content $PROFILE)

. $currentVersionPath\src\Utils.ps1
$oldProfileEncoding = Get-FileEncoding $PROFILE

$newProfile = @()
foreach($line in $oldProfile) {
if ($line -like '*PoshGitPrompt*') { continue; }

if($line -like '. *posh-git*profile.example.ps1*') {
$line = ". '$currentVersionPath\profile.example.ps1' choco"
}
if($line -like 'Import-Module *\src\posh-git.psd1*') {
$line = "Import-Module '$currentVersionPath\src\posh-git.psd1'"
}
$newProfile += $line
}
Set-Content -path $profile -value $newProfile -Force -Encoding $oldProfileEncoding
}
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$moduleName = 'posh-git' # this may be different from the package name and different case

# module may already be installed outside of Chocolatey
Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue

$sourcePath = Join-Path -Path $toolsDir -ChildPath "$modulename\*"
$destPath = Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Modules\$moduleName"
Copy link
Copy Markdown
Collaborator

@rkeithhill rkeithhill May 14, 2018

Choose a reason for hiding this comment

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

A big part of the v1 release is to support PowerShell Core. If the user has PS Core installed, we should also install into "PowerShell\Modules\$moduleName" if the $env:ProgramFiles\PowerShell dir exists.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree. I have been wondering what to do about whether you run Chocolatey under Core or not and where you should put the modules. However this is purely for the v0 branch so PS Core wasn't a consideration.


if ($PSVersionTable.PSVersion.Major -ge 5) {
$manifestFile = Join-Path -Path $toolsDir -ChildPath "$moduleName\$moduleName.psd1"
$manifest = Test-ModuleManifest -Path $manifestFile -WarningAction Ignore -ErrorAction Stop
$destPath = Join-Path -Path $destPath -ChildPath $manifest.Version.ToString()
}

Write-Verbose "Creating destination directory '$destPath' for module."
New-Item -Path $destPath -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null

Write-Verbose "Moving '$moduleName' files from '$sourcePath' to '$destPath'."
Move-Item -Path $sourcePath -Destination $destPath -Force

$installer = Join-Path $currentVersionPath 'install.ps1'
& $installer
} catch {
try {
if($oldProfile){ Set-Content -path $PROFILE -value $oldProfile -Force -Encoding $oldProfileEncoding }
}
catch {}
throw
if ($PSVersionTable.PSVersion.Major -lt 4) {
$modulePaths = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') -split ';'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we assume no one will try to use Chocolatey to install this on Linux or macOS? If not, you should use [System.IO.Path]::PathSeparator instead of hard-coding in ;.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

For the time being we can. As per the next comment this is only for v0 so we don't need to worry about PS Core.

if ($modulePaths -notcontains $destPath) {
Write-Verbose "Adding '$destPath' to PSModulePath."
$newModulePath = @($destPath, $modulePaths) -join ';'

[Environment]::SetEnvironmentVariable('PSModulePath', $newModulePath, 'Machine')
$env:PSModulePath = $newModulePath
}
}

Write-Host "To add posh-git to your profile use 'Import-Module posh-git; Add-PoshGitToProfile'."
51 changes: 12 additions & 39 deletions chocolatey/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,44 +1,17 @@
try {
$poshgitPath = join-path (Get-ToolsLocation) 'poshgit'
$ErrorActionPreference = 'Stop'

$currentVersionPath = Get-ChildItem "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime | Select-Object -Last 1
$moduleName = 'posh-git'
$sourcePath = Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Modules\$moduleName"

if(Test-Path $PROFILE) {
$oldProfile = @(Get-Content $PROFILE)
Write-Verbose "Removing all version of '$moduleName' from '$sourcePath'."
Remove-Item -Path $sourcePath -Recurse -Force -ErrorAction SilentlyContinue

. $currentVersionPath\src\Utils.ps1
$oldProfileEncoding = Get-FileEncoding $PROFILE
if ($PSVersionTable.PSVersion.Major -lt 4) {
$modulePaths = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') -split ';'

$newProfile = @()
foreach($line in $oldProfile) {
if ($line -like '*PoshGitPrompt*') { continue; }
if ($line -like '*Load posh-git example profile*') { continue; }
if ($line -like '*Start-SshAgent*') { continue; }

if($line -like '. *posh-git*profile.example.ps1*') {
continue;
}
if($line -like 'Import-Module *\src\posh-git.psd1*') {
continue;
}
$newProfile += $line
}
Set-Content -path $profile -value $newProfile -Force -Encoding $oldProfileEncoding
}

try {
if (test-path($poshgitPath)) {
Write-Host "Attempting to remove existing `'$poshgitPath`'."
remove-item $poshgitPath -recurse -force
}
} catch {
Write-Host "Could not remove `'$poshgitPath`'"
}
} catch {
try {
if($oldProfile){ Set-Content -path $PROFILE -value $oldProfile -Force -Encoding $oldProfileEncoding }
}
catch {}
throw
}
Write-Verbose "Removing '$sourcePath' from PSModulePath."
$newModulePath = $modulePaths | Where-Object { $_ -ne $sourcePath }

[Environment]::SetEnvironmentVariable('PSModulePath', $newModulePath, 'Machine')
$env:PSModulePath = $newModulePath
}