From ab7c0eddf9439a1f9bf6f5423125e9c935e8865f Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Mon, 30 Jan 2017 17:01:20 -0600 Subject: [PATCH 1/3] Warn/quit if $profilePath is missing --- src/Utils.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 2e0167571..ea723eb07 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -118,6 +118,11 @@ function Add-PoshGitToProfile([switch]$AllHosts, [switch]$Force, [switch]$WhatIf } } + if (!$profilePath) { + Write-Warning "Skipping add of posh-git import; no profile found." + return + } + # Check if the location of this module file is in the PSModulePath if (Test-InPSModulePath $ModuleBasePath) { $profileContent = "`nImport-Module posh-git" From 7d0753d79b9abfd8bc9f1273b03ba366ae5db90c Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Mon, 30 Jan 2017 17:02:23 -0600 Subject: [PATCH 2/3] Add verbose logging around Add-PoshGitToProfile --- src/Utils.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index ea723eb07..0e72c64a3 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -120,6 +120,12 @@ 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 } @@ -220,7 +226,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) { From 9a178d11c2a50b8de8139a5f322e92fcbe9c1524 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Mon, 30 Jan 2017 20:34:15 -0600 Subject: [PATCH 3/3] Add handling for non-standard $PROFILE --- src/Utils.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 0e72c64a3..69a778c98 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -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 }