Skip to content
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

Autocomplete user-defined pretty formats #802

Merged
merged 3 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/GitParamTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,14 @@ $gitParamValues = @{
log = @{
decorate = 'short full no'
'no-walk' = 'sorted unsorted'
pretty = 'oneline short medium full fuller email raw'
format = 'oneline short medium full fuller email raw'
pretty = {
param($format)
gitConfigKeys 'pretty' $format 'oneline short medium full fuller email raw'
}
format = {
param($format)
gitConfigKeys 'pretty' $format 'oneline short medium full fuller email raw'
}
encoding = 'UTF-8'
date = 'relative local default iso rfc short raw'
}
Expand Down Expand Up @@ -189,8 +195,14 @@ $gitParamValues = @{
strategy = 'resolve recursive octopus ours subtree'
}
show = @{
pretty = 'oneline short medium full fuller email raw'
format = 'oneline short medium full fuller email raw'
pretty = {
param($format)
gitConfigKeys 'pretty' $format 'oneline short medium full fuller email raw'
}
format = {
param($format)
gitConfigKeys 'pretty' $format 'oneline short medium full fuller email raw'
}
encoding = 'utf-8'
}
status = @{
Expand Down
12 changes: 12 additions & 0 deletions src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ function script:gitRemoteUniqueBranches($filter) {
quoteStringWithSpecialChars
}

function script:gitConfigKeys($section, $filter, $defaultOptions = '') {
$completions = @($defaultOptions -split ' ')

git config --name-only --get-regexp ^$section\..* |
ForEach-Object { $completions += ($_ -replace "$section\.","") }

return $completions |
Where-Object { $_ -like "$filter*" } |
Sort-Object |
quoteStringWithSpecialChars
}

function script:gitTags($filter, $prefix = '') {
git tag |
Where-Object { $_ -like "$filter*" } |
Expand Down
106 changes: 106 additions & 0 deletions test/GitParamTabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,111 @@ Describe 'ParamsTabExpansion Tests' {
$result -contains '--recurse-submodules=on-demand' | Should -Be $true
}
}

Context 'Pretty/Format TabCompletion Tests - No Custom Formats' {
It 'Tab completes default formats for log --pretty' {
$result = & $module GitTabExpansionInternal 'git log --pretty='
$result -contains '--pretty=oneline' | Should -Be $true
$result -contains '--pretty=short' | Should -Be $true
$result -contains '--pretty=medium' | Should -Be $true
$result -contains '--pretty=full' | Should -Be $true
$result -contains '--pretty=fuller' | Should -Be $true
$result -contains '--pretty=email' | Should -Be $true
$result -contains '--pretty=raw' | Should -Be $true
}
It 'Tab completes default formats for log --format' {
$result = & $module GitTabExpansionInternal 'git log --format='
$result -contains '--format=oneline' | Should -Be $true
$result -contains '--format=short' | Should -Be $true
$result -contains '--format=medium' | Should -Be $true
$result -contains '--format=full' | Should -Be $true
$result -contains '--format=fuller' | Should -Be $true
$result -contains '--format=email' | Should -Be $true
$result -contains '--format=raw' | Should -Be $true
}
It 'Tab completes default formats for show --pretty' {
$result = & $module GitTabExpansionInternal 'git show --pretty='
$result -contains '--pretty=oneline' | Should -Be $true
$result -contains '--pretty=short' | Should -Be $true
$result -contains '--pretty=medium' | Should -Be $true
$result -contains '--pretty=full' | Should -Be $true
$result -contains '--pretty=fuller' | Should -Be $true
$result -contains '--pretty=email' | Should -Be $true
$result -contains '--pretty=raw' | Should -Be $true
}
It 'Tab completes default formats for show --format' {
$result = & $module GitTabExpansionInternal 'git show --format='
$result -contains '--format=oneline' | Should -Be $true
$result -contains '--format=short' | Should -Be $true
$result -contains '--format=medium' | Should -Be $true
$result -contains '--format=full' | Should -Be $true
$result -contains '--format=fuller' | Should -Be $true
$result -contains '--format=email' | Should -Be $true
$result -contains '--format=raw' | Should -Be $true
}
}

Context 'Pretty/Format TabCompletion Tests - With Custom Formats' {
BeforeEach {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$repoPath = NewGitTempRepo

# Test with custom formats
&$gitbin config pretty.birdseye "%C(auto)%h%d %s %C(bold blue)<%aN> %C(green)(%cr)%Creset"
&$gitbin config pretty.test2 "%h%d %s <%aN> (%cr)"
}
AfterEach {
RemoveGitTempRepo $repoPath
}

It 'Tab completes default and custom formats for log --pretty' {
$result = & $module GitTabExpansionInternal 'git log --pretty='
$result -contains '--pretty=oneline' | Should -Be $true
$result -contains '--pretty=short' | Should -Be $true
$result -contains '--pretty=medium' | Should -Be $true
$result -contains '--pretty=full' | Should -Be $true
$result -contains '--pretty=fuller' | Should -Be $true
$result -contains '--pretty=email' | Should -Be $true
$result -contains '--pretty=raw' | Should -Be $true
$result -contains '--pretty=birdseye' | Should -Be $true
$result -contains '--pretty=test2' | Should -Be $true
}
It 'Tab completes default and custom formats for log --format' {
$result = & $module GitTabExpansionInternal 'git log --format='
$result -contains '--format=oneline' | Should -Be $true
$result -contains '--format=short' | Should -Be $true
$result -contains '--format=medium' | Should -Be $true
$result -contains '--format=full' | Should -Be $true
$result -contains '--format=fuller' | Should -Be $true
$result -contains '--format=email' | Should -Be $true
$result -contains '--format=raw' | Should -Be $true
$result -contains '--format=birdseye' | Should -Be $true
$result -contains '--format=test2' | Should -Be $true
}
It 'Tab completes default and custom formats for show --pretty' {
$result = & $module GitTabExpansionInternal 'git show --pretty='
$result -contains '--pretty=oneline' | Should -Be $true
$result -contains '--pretty=short' | Should -Be $true
$result -contains '--pretty=medium' | Should -Be $true
$result -contains '--pretty=full' | Should -Be $true
$result -contains '--pretty=fuller' | Should -Be $true
$result -contains '--pretty=email' | Should -Be $true
$result -contains '--pretty=raw' | Should -Be $true
$result -contains '--pretty=birdseye' | Should -Be $true
$result -contains '--pretty=test2' | Should -Be $true
}
It 'Tab completes default and custom formats for show --format' {
$result = & $module GitTabExpansionInternal 'git show --format='
$result -contains '--format=oneline' | Should -Be $true
$result -contains '--format=short' | Should -Be $true
$result -contains '--format=medium' | Should -Be $true
$result -contains '--format=full' | Should -Be $true
$result -contains '--format=fuller' | Should -Be $true
$result -contains '--format=email' | Should -Be $true
$result -contains '--format=raw' | Should -Be $true
$result -contains '--format=birdseye' | Should -Be $true
$result -contains '--format=test2' | Should -Be $true
}
}
}