I am currently trying to create a PowerShell script that performs the same functionality as cd, but also checks for a .git folder (new directory is a git repository) and then if true subsequently fetches and performs git status.
I am trying to debug at the moment in PowerShell ISE, but in the debugger my script skips straight over the blocks inside of the if..else statements. Is this a syntax error, or should the if..else work correctly?
function gd {
#set parameters taken from program (only file location)
Param(
[Parameter(Position=0)]
[String]$location
)
#get current directory location
[String]$Cl = $(Get-Location)
Set-Location $location
[String]$Nl = $(Get-Location)
if ($Cl -eq $Nl) {
return
} else {
Get-ChildItem -Hidden | Where-Object {
$_.Name -eq ".git"
} | Write-Output "Eureka!";
git fetch;
git status;
return
Write-Output "No .git found here!"
}
}
P.S: I am aware that the long Where-Object pipe is awful (and indubitably non-functional as-is), but this is my 1st script. Would welcome any help with it but my main issue is the execution skipping the if/else code blocks.
$locationmandatory or defaulting to current location and checkingif (Test-Path (Join-Path $location ".git"))?git fetchandgit statusonly when you cd into the root of a git tree? Or for subfolders as well?git fetchandgit statuswere part of the pipeline and would only run ifWhere-Objectfound a match. That is not the case. Both commands will be run every time$Cland$Nlare not the same.