Skip to content

Commit 71a49dd

Browse files
authored
Merge pull request #535 from dahlbyk/rkeithhill/get-gitstatus-force
Fix #475 add -Force param to Get-GitStatus
2 parents 6877d9d + be23f67 commit 71a49dd

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

src/GitUtils.ps1

+38-6
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,42 @@ function GetUniquePaths($pathCollections) {
171171

172172
$castStringSeq = [Linq.Enumerable].GetMethod("Cast").MakeGenericMethod([string])
173173

174-
function Get-GitStatus($gitDir = (Get-GitDirectory)) {
174+
<#
175+
.SYNOPSIS
176+
Gets a Git status object that is used by Write-GitStatus.
177+
.DESCRIPTION
178+
Gets a Git status object that is used by Write-GitStatus.
179+
The status object provides the information to be displayed in the various
180+
sections of the posh-git prompt.
181+
.EXAMPLE
182+
PS C:\> $s = Get-GitStatus; Write-GitStatus $s
183+
Gets a Git status object. Then passes the object to Write-GitStatus which
184+
writes out a posh-git prompt (or returns a string in ANSI mode) with the
185+
information contained in the status object.
186+
.INPUTS
187+
None
188+
.OUTPUTS
189+
System.Management.Automation.PSObject
190+
.LINK
191+
Write-GitStatus
192+
#>
193+
function Get-GitStatus {
194+
param(
195+
# The path of a directory within a Git repository that you want to get
196+
# the Git status.
197+
[Parameter(Position=0)]
198+
$GitDir = (Get-GitDirectory),
199+
200+
# If specified, overrides $GitPromptSettings.EnablePromptStatus when it
201+
# is set to $false.
202+
[Parameter()]
203+
[switch]
204+
$Force
205+
)
206+
175207
$settings = $Global:GitPromptSettings
176-
$enabled = (-not $settings) -or $settings.EnablePromptStatus
177-
if ($enabled -and $gitDir) {
208+
$enabled = $Force -or !$settings -or $settings.EnablePromptStatus
209+
if ($enabled -and $GitDir) {
178210
if($settings.Debug) {
179211
$sw = [Diagnostics.Stopwatch]::StartNew(); Write-Host ''
180212
}
@@ -196,7 +228,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
196228
$filesUnmerged = New-Object System.Collections.Generic.List[string]
197229
$stashCount = 0
198230

199-
if($settings.EnableFileStatus -and !$(InDotGitOrBareRepoDir $gitDir) -and !$(InDisabledRepository)) {
231+
if($settings.EnableFileStatus -and !$(InDotGitOrBareRepoDir $GitDir) -and !$(InDisabledRepository)) {
200232
if ($null -eq $settings.EnableFileStatusFromCache) {
201233
$settings.EnableFileStatusFromCache = $null -ne (Get-Module GitStatusCachePoshClient)
202234
}
@@ -285,7 +317,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
285317
}
286318
}
287319

288-
if(!$branch) { $branch = Get-GitBranch $gitDir $sw }
320+
if(!$branch) { $branch = Get-GitBranch $GitDir $sw }
289321

290322
dbg 'Building status object' $sw
291323
#
@@ -307,7 +339,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
307339
Add-Member -Force -PassThru NoteProperty Unmerged $filesUnmerged.ToArray()
308340

309341
$result = New-Object PSObject -Property @{
310-
GitDir = $gitDir
342+
GitDir = $GitDir
311343
Branch = $branch
312344
AheadBy = $aheadBy
313345
BehindBy = $behindBy

0 commit comments

Comments
 (0)