Skip to content

Commit

Permalink
Removed error thrown by symbolic-ref and describe
Browse files Browse the repository at this point in the history
git describe can be replaced by tag --points-at <commitish>. Other than symbolic-ref, describe does not have a --quiet switch, thus always adds to $error in case of a detached head with no tag pointing to that commit. Using tag --point-at HEAD will return a tag if one is found but not throw an error when there is none.
  • Loading branch information
JanDeDobbeleer committed Oct 8, 2016
1 parent c39da78 commit f11b006
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
1 change: 0 additions & 1 deletion GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
EnablePromptStatus = !$Global:GitMissing
EnableFileStatus = $true
RepositoriesInWhichToDisableFileStatus = @( ) # Array of repository paths
DescribeStyle = ''

EnableWindowTitle = 'posh~git ~ '

Expand Down
11 changes: 3 additions & 8 deletions GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,11 @@ function Get-GitBranch($gitDir = $(Get-GitDirectory), [Diagnostics.Stopwatch]$sw
}

$b = Invoke-NullCoalescing `
{ dbg 'Trying symbolic-ref' $sw; git symbolic-ref HEAD 2>$null } `
{ dbg 'Trying symbolic-ref' $sw; git symbolic-ref HEAD -q 2>$null } `
{ '({0})' -f (Invoke-NullCoalescing `
{
dbg 'Trying describe' $sw
switch ($Global:GitPromptSettings.DescribeStyle) {
'contains' { git describe --contains HEAD 2>$null }
'branch' { git describe --contains --all HEAD 2>$null }
'describe' { git describe HEAD 2>$null }
default { git describe --tags --exact-match HEAD 2>$null }
}
dbg 'Trying tag' $sw
git tag --points-at HEAD 2>$null
} `
{
dbg 'Falling back on parsing HEAD' $sw
Expand Down

0 comments on commit f11b006

Please # to comment.