-
-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quote tab completion items with PS special chars. #413
Changes from 2 commits
4fb926e
8440c88
32c9a2b
39d559e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,15 @@ catch { | |
Write-Debug "Search for 'flow' in 'git help' output failed with error: $_" | ||
} | ||
|
||
filter quoteStringWithSpecialChars { | ||
if ($_ -and ($_ -match '\s+|#|@|\$|;|\{|\}|\(|\)')) { | ||
"'" + $_ + "'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
else { | ||
$_ | ||
} | ||
} | ||
|
||
function script:gitCommands($filter, $includeAliases) { | ||
$cmdList = @() | ||
if (-not $global:GitTabSettings.AllCommands) { | ||
|
@@ -86,7 +95,8 @@ function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') { | |
|
||
$branches | | ||
Where-Object { $_ -ne '(no branch)' -and $_ -like "$filter*" } | | ||
ForEach-Object { $prefix + $_ } | ||
ForEach-Object { $prefix + $_ } | | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitRemoteUniqueBranches($filter) { | ||
|
@@ -95,45 +105,49 @@ function script:gitRemoteUniqueBranches($filter) { | |
Group-Object -NoElement | | ||
Where-Object { $_.Count -eq 1 } | | ||
Select-Object -ExpandProperty Name | | ||
Where-Object { $_ -like "$filter*" } | ||
Where-Object { $_ -like "$filter*" } | | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitTags($filter, $prefix = '') { | ||
git tag | | ||
Where-Object { $_ -like "$filter*" } | | ||
ForEach-Object { $prefix + $_ } | ||
ForEach-Object { $prefix + $_ } | | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitFeatures($filter, $command){ | ||
$featurePrefix = git config --local --get "gitflow.prefix.$command" | ||
$branches = @(git branch --no-color | ForEach-Object { if ($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } }) | ||
$branches | | ||
Where-Object { $_ -ne '(no branch)' -and $_ -like "$filter*" } | | ||
ForEach-Object { $prefix + $_ } | ||
ForEach-Object { $prefix + $_ } | | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitRemoteBranches($remote, $ref, $filter, $prefix = '') { | ||
git branch --no-color -r | | ||
Where-Object { $_ -like " $remote/$filter*" } | | ||
ForEach-Object { $prefix + $ref + ($_ -replace " $remote/","") } | ||
ForEach-Object { $prefix + $ref + ($_ -replace " $remote/","") } | | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitStashes($filter) { | ||
(git stash list) -replace ':.*','' | | ||
Where-Object { $_ -like "$filter*" } | | ||
ForEach-Object { "'$_'" } | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitTfsShelvesets($filter) { | ||
(git tfs shelve-list) | | ||
Where-Object { $_ -like "$filter*" } | | ||
ForEach-Object { "'$_'" } | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitFiles($filter, $files) { | ||
$files | Sort-Object | | ||
Where-Object { $_ -like "$filter*" } | | ||
ForEach-Object { if ($_ -like '* *') { "'$_'" } else { $_ } } | ||
quoteStringWithSpecialChars | ||
} | ||
|
||
function script:gitIndex($GitStatus, $filter) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ Describe 'TabExpansion Tests' { | |
$temp = [System.IO.Path]::GetTempPath() | ||
$repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName()) | ||
|
||
git init $repoPath | ||
git.exe init $repoPath | ||
Set-Location $repoPath | ||
} | ||
AfterEach { | ||
|
@@ -137,16 +137,70 @@ Describe 'TabExpansion Tests' { | |
} | ||
} | ||
It 'Tab completes non-ASCII file name' { | ||
git config core.quotepath true # Problematic (default) config | ||
git.exe config core.quotepath true # Problematic (default) config | ||
|
||
$fileName = "posh$([char]8226)git.txt" | ||
New-Item $fileName | ||
New-Item $fileName -ItemType File | ||
|
||
$GitStatus = & $module Get-GitStatus | ||
|
||
$result = & $module GitTabExpansionInternal 'git add ' $GitStatus | ||
$gitStatus = & $module Get-GitStatus | ||
|
||
$result = & $module GitTabExpansionInternal 'git add ' $gitStatus | ||
$result | Should BeExactly $fileName | ||
} | ||
} | ||
|
||
Context 'PowerShell Special Chars Tests' { | ||
BeforeAll { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is bound to be a pretty common pattern. Is it possible to write a Pester helper that would encapsulate a Context 'Awesome test' {
TempRepo {
# Set up the repo
}
It 'Uses $repoPath' {
# ...
}
} |
||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')] | ||
$origPath = Get-Location | ||
$temp = [System.IO.Path]::GetTempPath() | ||
$repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName()) | ||
|
||
git.exe init $repoPath | ||
Set-Location $repoPath | ||
|
||
'readme' | Out-File .\README.md -Encoding ascii | ||
git.exe add .\README.md | ||
git.exe commit -m "initial commit." | ||
} | ||
AfterAll { | ||
Set-Location $origPath | ||
if (Test-Path $repoPath) { | ||
Remove-Item $repoPath -Recurse -Force | ||
} | ||
} | ||
AfterEach { | ||
Set-Location $repoPath | ||
git.exe reset HEAD --hard | ||
git.exe checkout master 2>$null | ||
} | ||
It 'Tab completes branch name with special char as quoted' { | ||
git.exe branch '#develop' 2>$null | ||
|
||
$result = & $module GitTabExpansionInternal 'git checkout #' | ||
$result | Should BeExactly "'#develop'" | ||
} | ||
It 'Tab completes git feature branch name with special char as quoted' { | ||
git.exe branch '#develop' 2>$null | ||
|
||
$result = & $module GitTabExpansionInternal 'git flow feature list #' | ||
$result | Should BeExactly "'#develop'" | ||
} | ||
It 'Tab completes a tag name with special char as quoted' { | ||
$tag = "v1.0.0;abcdef" | ||
git.exe tag $tag | ||
|
||
$result = & $module GitTabExpansionInternal 'git show v1' | ||
$result | Should BeExactly "'$tag'" | ||
} | ||
It 'Tab completes add file in working dir with special char as quoted' { | ||
$filename = 'foo{bar} (x86).txt'; | ||
New-Item $filename -ItemType File | ||
|
||
$gitStatus = & $module Get-GitStatus | ||
|
||
$result = & $module GitTabExpansionInternal 'git add ' $gitStatus | ||
$result | Should BeExactly "'$filename'" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
,