diff --git a/chocolatey/poshgit.nuspec b/chocolatey/poshgit.nuspec
index 151f698af..66cc082a6 100644
--- a/chocolatey/poshgit.nuspec
+++ b/chocolatey/poshgit.nuspec
@@ -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`.
Provides prompt with Git status summary information and tab completion for Git commands, parameters, remotes and branch names.
- poshgit posh-git powershell git
+ admin posh-git powershell module git
https://github.com/dahlbyk/posh-git
https://github.com/dahlbyk/posh-git/blob/v0/LICENSE.txt
false
+ https://github.com/dahlbyk/posh-git
+ https://github.com/pauby/posh-git/blob/master/README.md
+ https://github.com/dahlbyk/posh-git/issues
diff --git a/chocolatey/tools/chocolateyBeforeModify.ps1 b/chocolatey/tools/chocolateyBeforeModify.ps1
new file mode 100644
index 000000000..3edaf1fd0
--- /dev/null
+++ b/chocolatey/tools/chocolateyBeforeModify.ps1
@@ -0,0 +1,4 @@
+$ErrorActionPreference = 'Stop'
+
+$moduleName = 'posh-git' # this could be different from package name
+Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue
\ No newline at end of file
diff --git a/chocolatey/tools/chocolateyInstall.ps1 b/chocolatey/tools/chocolateyInstall.ps1
index 0f01a6c3f..5df22aace 100644
--- a/chocolatey/tools/chocolateyInstall.ps1
+++ b/chocolatey/tools/chocolateyInstall.ps1
@@ -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"
+
+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 ';'
+ 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'."
\ No newline at end of file
diff --git a/chocolatey/tools/chocolateyUninstall.ps1 b/chocolatey/tools/chocolateyUninstall.ps1
index 2e3285b31..556d8f152 100644
--- a/chocolatey/tools/chocolateyUninstall.ps1
+++ b/chocolatey/tools/chocolateyUninstall.ps1
@@ -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
+}
\ No newline at end of file