diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index ed824b556..f8a6751b0 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -136,19 +136,19 @@ function script:gitFiles($filter, $files) { ForEach-Object { if ($_ -like '* *') { "'$_'" } else { $_ } } } -function script:gitIndex($filter) { +function script:gitIndex($GitStatus, $filter) { gitFiles $filter $GitStatus.Index } -function script:gitAddFiles($filter) { +function script:gitAddFiles($GitStatus, $filter) { gitFiles $filter (@($GitStatus.Working.Unmerged) + @($GitStatus.Working.Modified) + @($GitStatus.Working.Added)) } -function script:gitCheckoutFiles($filter) { +function script:gitCheckoutFiles($GitStatus, $filter) { gitFiles $filter (@($GitStatus.Working.Unmerged) + @($GitStatus.Working.Modified) + @($GitStatus.Working.Deleted)) } -function script:gitDiffFiles($filter, $staged) { +function script:gitDiffFiles($GitStatus, $filter, $staged) { if ($staged) { gitFiles $filter $GitStatus.Index.Modified } @@ -157,11 +157,11 @@ function script:gitDiffFiles($filter, $staged) { } } -function script:gitMergeFiles($filter) { +function script:gitMergeFiles($GitStatus, $filter) { gitFiles $filter $GitStatus.Working.Unmerged } -function script:gitDeleted($filter) { +function script:gitDeleted($GitStatus, $filter) { gitFiles $filter $GitStatus.Working.Deleted } @@ -207,11 +207,11 @@ function script:expandParamValues($cmd, $param, $filter) { } function GitTabExpansion($lastBlock) { - $res = Invoke-Utf8ConsoleCommand { GitTabExpansionInternal $lastBlock } + $res = Invoke-Utf8ConsoleCommand { GitTabExpansionInternal $lastBlock $Global:GitStatus } $res } -function GitTabExpansionInternal($lastBlock) { +function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { $ignoreGitParams = '(?\s+-(?:[aA-zZ0-9]+|-[aA-zZ0-9][aA-zZ0-9-]*)(?:=\S+)?)*' if ($lastBlock -match "^$(Get-AliasPattern git) (?\S+)(? .*)$") { @@ -306,7 +306,7 @@ function GitTabExpansionInternal($lastBlock) { # Handles git reset HEAD # Handles git reset HEAD -- "^reset.* HEAD(?:\s+--)? (?\S*)$" { - gitIndex $matches['path'] + gitIndex $GitStatus $matches['path'] } # Handles git @@ -316,27 +316,27 @@ function GitTabExpansionInternal($lastBlock) { # Handles git add "^add.* (?\S*)$" { - gitAddFiles $matches['files'] + gitAddFiles $GitStatus $matches['files'] } # Handles git checkout -- "^checkout.* -- (?\S*)$" { - gitCheckoutFiles $matches['files'] + gitCheckoutFiles $GitStatus $matches['files'] } # Handles git rm "^rm.* (?\S*)$" { - gitDeleted $matches['index'] + gitDeleted $GitStatus $matches['index'] } # Handles git diff/difftool "^(?:diff|difftool)(?:.* (?(?:--cached|--staged))|.*) (?\S*)$" { - gitDiffFiles $matches['files'] $matches['staged'] + gitDiffFiles $GitStatus $matches['files'] $matches['staged'] } # Handles git merge/mergetool "^(?:merge|mergetool).* (?\S*)$" { - gitMergeFiles $matches['files'] + gitMergeFiles $GitStatus $matches['files'] } # Handles git checkout diff --git a/src/GitUtils.ps1 b/src/GitUtils.ps1 index 6848953dd..63bc05c4a 100644 --- a/src/GitUtils.ps1 +++ b/src/GitUtils.ps1 @@ -224,7 +224,7 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) { if ($cacheResponse.State) { $branch += "|" + $cacheResponse.State } } else { dbg 'Getting status' $sw - $status = Invoke-Utf8ConsoleCommand { git -c color.status=false status --short --branch 2>$null } + $status = Invoke-Utf8ConsoleCommand { git -c core.quotepath=false -c color.status=false status --short --branch 2>$null } if($settings.EnableStashStatus) { dbg 'Getting stash count' $sw $stashCount = $null | git stash list 2>$null | measure-object | Select-Object -expand Count diff --git a/test/TabExpansion.Tests.ps1 b/test/TabExpansion.Tests.ps1 index 191550ab6..f77c1671f 100644 --- a/test/TabExpansion.Tests.ps1 +++ b/test/TabExpansion.Tests.ps1 @@ -117,4 +117,32 @@ Describe 'TabExpansion Tests' { } } } + Context 'Add/Reset/Checkout TabExpansion Tests' { + BeforeEach { + $origPath = Get-Location + $temp = [System.IO.Path]::GetTempPath() + $repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName()) + + git init $repoPath + Set-Location $repoPath + } + AfterEach { + Set-Location $origPath + if (Test-Path $repoPath) { + Remove-Item $repoPath -Recurse -Force + } + } + It 'Tab completes non-ASCII file name' { + git config core.quotepath true # Problematic (default) config + + $fileName = "posh$([char]8226)git.txt" + New-Item $fileName + + $GitStatus = & $module Get-GitStatus + + $result = & $module GitTabExpansionInternal 'git add ' $GitStatus + + $result | Should BeExactly $fileName + } + } }