Skip to content

Commit

Permalink
Fix RamblingCookieMonster#80 Get-BuildVariable breaks if git is aliased
Browse files Browse the repository at this point in the history
[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 RamblingCookieMonster#80
  • Loading branch information
RandomNoun7 committed Nov 13, 2018
1 parent a8793c8 commit 4ff88c2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BuildHelpers/Public/Get-BuildVariables.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) )
Expand Down
2 changes: 1 addition & 1 deletion BuildHelpers/Public/Invoke-Git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
# http://stackoverflow.com/questions/8761888/powershell-capturing-standard-out-and-error-with-start-process
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
if(!$PSBoundParameters.ContainsKey('GitPath')) {
$GitPath = (Get-Command $GitPath -ErrorAction Stop)[0].Path
$GitPath = (Get-ChildItem ($env:PATH -split ';') -filter git.exe -ErrorAction SilentlyContinue | Select-Object -First 1).Fullname
}
$pinfo.FileName = $GitPath
$Command = $GitPath
Expand Down

0 comments on commit 4ff88c2

Please sign in to comment.