Skip to content

Search-Repo

Searches for text in a repo

param([string]$textPattern = "", [string]$path = "$PWD")


try {
	if ($textPattern -eq "" ) { $textPattern = Read-Host "Enter the text pattern, e.g. 'UFO'" }

	if (-not(Test-Path "$path" -pathType container)) { throw "Can't access Git repository at: $path" }

	$null = (git --version)
	if ($lastExitCode -ne 0) { throw "Can't execute 'git' - make sure Git is installed and available" }

	& git -C "$path" grep $textPattern
	if ($lastExitCode -ne 0) { throw "'git grep' failed with exit code $lastExitCode" }

	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the text pattern to search for

Specifies the file path to the local Git repository

An interactive directory of PowerShell scripts.