Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BuildHelpers/Public/Get-BuildVariables.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ function Get-BuildVariables {
}
$true
})]
$GitPath = 'git'
$GitPath

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hard coded git.exe we are searching for makes this default value unnecessary.

)

$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

@RandomNoun7 RandomNoun7 Nov 13, 2018

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to fix the fact that git.exe is hard coded here. I will either need to change the -filter to something like -filter "*$GitPath*" or change the param default to git.exe

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've changed my mind on this. If the user provides a git path they should be providing a full path to the git executable. If they provide anything at all this variable is given directly to the Process Start info Filename Parameter anyway, so if they do something like provide an input that it can't use, it will already fail.

If the user does not provide input to the $GitPath parameter, we already know conclusively that we want to search for git.exe. We aren't searching for git.com or git.bat, or anything like that.

This says to me that it is safe to simply leave the $GitPath parameter optional, and there is no need to provide a default value.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiyo! @gaelcolas has an old PR in one of my repos for a similar thing, looking to resolve just git (this should still pick up git.exe, but buys us compatibility with systems that don't use .exe). Might be worth looking into something like this here? (This is a pre-skimming-your-whole-commit-and-my-old-code comment : P)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about this PR for a while, and suddenly I get a notice that there was a comment. If @gaelcolas wants to link me the PR that would be great. Otherwise I'll go searching around for it on Monday.

}

$WeCanGit = ( (Test-Path $( Join-Path $Path .git )) -and (Get-Command $GitPath -ErrorAction SilentlyContinue) )
Expand Down
4 changes: 2 additions & 2 deletions BuildHelpers/Public/Invoke-Git.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
}
$true
})]
[string]$GitPath = 'git'
[string]$GitPath

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hard coded git.exe we are searching for makes this default value unnecessary.

)

$Path = (Resolve-Path $Path).Path
# 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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

}
$pinfo.FileName = $GitPath
$Command = $GitPath
Expand Down