# encoding: ascii
# api: powershell
# title: Get-GitInfoForDirectory
# description: Get-GitInfoForDirectory Function – Git repo folder info gather function to Display Git Repo Status and Branch in the PowerShell Prompt. – Add Function to your Profile Script, and call from within the Prompt Function – Must have Git For Windows installed and its install directory added to the PATH
# version: 0.1
# type: function
# author: JayDeuce
# license: CC0
# function: Get-GitInfoForDirectory
# x-poshcode-id: 6235
# x-archived: 2016-03-26T12:17:01
# x-published: 2016-02-25T05:16:00
#
#
function Get-GitInfoForDirectory {
param (
)
begin {
$gitBranch = (git branch)
$gitStatus = (git status)
$gitTextLine = ""
}
process {
try {
foreach ($branch in $gitBranch) {
if ($branch -match '^\* (.*)') {
$gitBranchName = 'Git Repo - Branch: ' + $matches[1].ToUpper()
}
}
if (!($gitStatus -like '*working directory clean*')) {
$gitStatusMark = ' ' + '/' + ' Status: ' + 'NEEDS UPDATING'
}
elseif ($gitStatus -like '*Your branch is ahead*') {
$gitStatusMark = ' ' + '/' + ' Status: ' + 'PUBLISH COMMITS'
}
else {
$gitStatusMark = ' ' + '/' + ' Status: ' + 'UP TO DATE'
}
}
catch {
}
}
end {
if ($gitBranch) {
$gitTextLine = ' {' + $gitBranchName + $gitStatusMark + '}'
}
return $gitTextLine
}
}