From f259da78744b2d9378bb13521d6170dda00de784 Mon Sep 17 00:00:00 2001 From: Bill Hurt Date: Mon, 12 Nov 2018 22:50:02 -0800 Subject: [PATCH] Fix #80 Get-BuildVariable breaks if git is aliased [hub](https://github.com/github/hub) is a tool put out by git that adds commandline tools to help developers work with github from the commandline in a more natural way. It is designed to be used by aliasing git to hub.exe. Hub then handles the additional commands it knows how to implement, and transparently passes through any native git commands to git.exe. The Get-BuildVariable cmdlet does not account for the possibility that git might be aliased, and assumes that the output of Get-Command 'git' can authoritatively be treated as either returning a Path to git or determining that git is not installed on a system. This change switches the method of determining the path to git over to looking at each path in the $env:PATH variable, and returning the path to the first instance of git.exe that it finds. This should be the same method used by Get-Command, and isn't fooled by the presence of aliases. --- BuildHelpers/Public/Get-BuildVariables.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BuildHelpers/Public/Get-BuildVariables.ps1 b/BuildHelpers/Public/Get-BuildVariables.ps1 index 182f27d..fcc7f6e 100644 --- a/BuildHelpers/Public/Get-BuildVariables.ps1 +++ b/BuildHelpers/Public/Get-BuildVariables.ps1 @@ -75,7 +75,7 @@ function Get-BuildVariables { $Path = ( Resolve-Path $Path ).Path $Environment = Get-Item ENV: if(!$PSboundParameters.ContainsKey('GitPath')) { - $GitPath = (Get-Command $GitPath -ErrorAction SilentlyContinue)[0].Path + $GitPath = (Get-ChildItem ($env:PATH -split ';') -filter git.exe -ErrorAction SilentlyContinue | Select-Object -First 1).Fullname } $WeCanGit = ( (Test-Path $( Join-Path $Path .git )) -and (Get-Command $GitPath -ErrorAction SilentlyContinue) )