Skip to content

Commit

Permalink
Merge pull request #390 from dahlbyk/chocolatey-profile
Browse files Browse the repository at this point in the history
Handle Chocolatey Host $PROFILE
  • Loading branch information
dahlbyk authored Feb 1, 2017
2 parents 10f136f + 9a178d1 commit 33ed602
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ function Add-PoshGitToProfile([switch]$AllHosts, [switch]$Force, [switch]$WhatIf
}
}

if (!$profilePath) { $profilePath = $PROFILE }

if (!$Force) {
# Search the user's profiles to see if any are using posh-git already, there is an extra search
# ($profilePath) taking place to accomodate the Pester tests.
$importedInProfile = Test-PoshGitImportedInScript $profilePath
if (!$importedInProfile -and !$underTest) {
$importedInProfile = Test-PoshGitImportedInScript $PROFILE
}
if (!$importedInProfile -and !$underTest) {
$importedInProfile = Test-PoshGitImportedInScript $PROFILE.CurrentUserCurrentHost
}
Expand All @@ -118,6 +123,17 @@ function Add-PoshGitToProfile([switch]$AllHosts, [switch]$Force, [switch]$WhatIf
}
}

if (!$profilePath) {
Write-Warning "Skipping add of posh-git import; no profile found."
Write-Verbose "`$profilePath = '$profilePath'"
Write-Verbose "`$PROFILE = '$PROFILE'"
Write-Verbose "CurrentUserCurrentHost = '$($PROFILE.CurrentUserCurrentHost)'"
Write-Verbose "CurrentUserAllHosts = '$($PROFILE.CurrentUserAllHosts)'"
Write-Verbose "AllUsersCurrentHost = '$($PROFILE.AllUsersCurrentHost)'"
Write-Verbose "AllUsersAllHosts = '$($PROFILE.AllUsersAllHosts)'"
return
}

# Check if the location of this module file is in the PSModulePath
if (Test-InPSModulePath $ModuleBasePath) {
$profileContent = "`nImport-Module posh-git"
Expand Down Expand Up @@ -215,7 +231,9 @@ function Test-PoshGitImportedInScript {
return $false
}

(@(Get-Content $Path -ErrorAction SilentlyContinue) -match 'posh-git').Count -gt 0
$match = (@(Get-Content $Path -ErrorAction SilentlyContinue) -match 'posh-git').Count -gt 0
if ($match) { Write-Verbose "posh-git found in '$Path'" }
$match
}

function dbg($Message, [Diagnostics.Stopwatch]$Stopwatch) {
Expand Down

0 comments on commit 33ed602

Please sign in to comment.