Skip to content

Commit 24d3518

Browse files
committed
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. Unfortunately if git is aliased to hub.exe then the result of Get-Command is not an object of type `System.Management.Automation.ApplicationInfo` that has a `Path` property but an object of type `System.Management.Automation.AliasInfo` which does not contain a path either to git or to the executable it's been aliased to. One possible strategy would be to find that git has been alaised and find the path to executable that it has been aliased to, but this seems less than ideal since the third party binary is not what this module really wants to execute, and this module will only ever need the capabilities of the native git.exe, not the extended capabilities of hub. 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. This change should be a fix for #80
1 parent a8793c8 commit 24d3518

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎BuildHelpers/Public/Get-BuildVariables.ps1‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ function Get-BuildVariables {
6969
}
7070
$true
7171
})]
72-
$GitPath = 'git'
72+
$GitPath
7373
)
7474

7575
$Path = ( Resolve-Path $Path ).Path
7676
$Environment = Get-Item ENV:
7777
if(!$PSboundParameters.ContainsKey('GitPath')) {
78-
$GitPath = (Get-Command $GitPath -ErrorAction SilentlyContinue)[0].Path
78+
$GitPath = (Get-ChildItem ($env:PATH -split ';') -filter git.exe -ErrorAction SilentlyContinue | Select-Object -First 1).Fullname
7979
}
8080

8181
$WeCanGit = ( (Test-Path $( Join-Path $Path .git )) -and (Get-Command $GitPath -ErrorAction SilentlyContinue) )

‎BuildHelpers/Public/Invoke-Git.ps1‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@
7777
}
7878
$true
7979
})]
80-
[string]$GitPath = 'git'
80+
[string]$GitPath
8181
)
8282

8383
$Path = (Resolve-Path $Path).Path
8484
# http://stackoverflow.com/questions/8761888/powershell-capturing-standard-out-and-error-with-start-process
8585
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
8686
if(!$PSBoundParameters.ContainsKey('GitPath')) {
87-
$GitPath = (Get-Command $GitPath -ErrorAction Stop)[0].Path
87+
$GitPath = (Get-ChildItem ($env:PATH -split ';') -filter git.exe -ErrorAction SilentlyContinue | Select-Object -First 1).Fullname
8888
}
8989
$pinfo.FileName = $GitPath
9090
$Command = $GitPath

0 commit comments

Comments
 (0)