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

Tab completion for sparse-checkout #915

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/GitParamTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $shortGitParams = @{
revert = 'e m n S s X'
rm = 'f n r q'
shortlog = 'n s e w'
'sparse-checkout' = ''
stash = 'p k u a q'
status = 's b u z'
submodule = 'q b f n N'
Expand Down Expand Up @@ -77,6 +78,7 @@ $longGitParams = @{
rm = 'force dry-run cached ignore-unmatch quiet'
shortlog = 'numbered summary email format='
show = 'pretty= format= abbrev-commit no-abbrev-commit oneline encoding= expand-tabs no-expand-tabs notes no-notes show-notes no-standard-notes standard-notes show-signature name-only name-status stat shortstat numstat'
'sparse-checkout' = ''
stash = 'patch no-keep-index keep-index include-untracked all quiet index'
status = 'short branch porcelain long untracked-files ignore-submodules ignored column no-column'
submodule = 'quiet branch force cached files summary-limit remote no-fetch checkout merge rebase init name reference recursive depth'
Expand Down Expand Up @@ -109,6 +111,12 @@ $longVstsParams = @{
update = " $longVstsGlobal"
}

$longSparseCheckoutParams = @{
add = "stdin"
set = "cone no-cone sparse-index no-sparse-index stdin"
reapply = "cone no-cone sparse-index no-sparse-index"
}

# Variable is used in GitTabExpansion.ps1
$gitParamValues = @{
blame = @{
Expand Down
11 changes: 10 additions & 1 deletion src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $subcommands = @{
get-url set-url show prune update
"
rerere = "clear forget diff remaining status gc"
'sparse-checkout' = "list set add reapply disable"
stash = 'push save list show apply clear drop pop create branch'
submodule = "add status init deinit update summary foreach sync"
svn = "
Expand Down Expand Up @@ -58,7 +59,8 @@ $script:someCommands = @('add','am','annotate','archive','bisect','blame','branc
'cherry-pick','citool','clean','clone','commit','config','describe','diff','difftool','fetch',
'format-patch','gc','grep','gui','help','init','instaweb','log','merge','mergetool','mv',
'notes','prune','pull','push','rebase','reflog','remote','rerere','reset','restore','revert','rm',
'shortlog','show','stash','status','submodule','svn','switch','tag','whatchanged', 'worktree')
'shortlog','show','sparse-checkout','stash','status','submodule','svn','switch','tag','whatchanged',
'worktree')

if ((($PSVersionTable.PSVersion.Major -eq 5) -or $IsWindows) -and ($script:GitVersion -ge [System.Version]'2.16.2')) {
$script:someCommands += 'update-git-for-windows'
Expand All @@ -69,6 +71,7 @@ $script:gitCommandsWithShortParams = $shortGitParams.Keys -join '|'
$script:gitCommandsWithParamValues = $gitParamValues.Keys -join '|'
$script:vstsCommandsWithShortParams = $shortVstsParams.Keys -join '|'
$script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|'
$script:sparseCheckoutCommandsWithLongParams = $longSparseCheckoutParams.Keys -join '|'

# The regular expression here is roughly follows this pattern:
#
Expand Down Expand Up @@ -462,6 +465,12 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) {
gitBranches $matches['ref']
}

# Handles git sparse-checkout <cmd>
"sparse-checkout\s+(?<cmd>$sparseCheckoutCommandsWithLongParams).*--(?<param>\S*)$"
{
expandLongParams $longSparseCheckoutParams $matches['cmd'] $matches['param']
}

# Handles git <cmd> <ref>
"^(?:cherry|cherry-pick|diff|difftool|log|merge|rebase|reflog\s+show|reset|revert|show).* (?<ref>\S*)$" {
gitBranches $matches['ref'] $true
Expand Down
22 changes: 22 additions & 0 deletions test/GitParamTabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,27 @@ Describe 'ParamsTabExpansion Tests' {
$result -contains '--format=test2' | Should -Be $true
}
}

Context 'Sparse-Checkout Parameters TabExpansion Tests' {
It 'Tab completes all long sparse-checkout set parameters' {
$result = & $module GitTabExpansionInternal 'git sparse-checkout set --'
$result -contains '--cone' | Should -Be $true
$result -contains '--no-cone' | Should -Be $true
$result -contains '--sparse-index' | Should -Be $true
$result -contains '--no-sparse-index' | Should -Be $true
$result -contains '--stdin' | Should -Be $true
}
It 'Tab completes all long sparse-checkout reapply parameters' {
$result = & $module GitTabExpansionInternal 'git sparse-checkout reapply --'
$result -contains '--cone' | Should -Be $true
$result -contains '--no-cone' | Should -Be $true
$result -contains '--sparse-index' | Should -Be $true
$result -contains '--no-sparse-index' | Should -Be $true
}
It 'Tab completes all long sparse-checkout add parameters' {
$result = & $module GitTabExpansionInternal 'git sparse-checkout add --'
$result -contains '--stdin' | Should -Be $true
}
}
}

10 changes: 10 additions & 0 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ Describe 'TabExpansion Tests' {
$result2 -contains 'set-head' | Should -Be $true
$result2 -contains 'set-url' | Should -Be $true
}
It 'Tab completes sparse-checkout subcommands' {
$result = & $module GitTabExpansionInternal 'git sparse-checkout '

$result -contains '' | Should -Be $false
$result -contains 'list' | Should -Be $true
$result -contains 'set' | Should -Be $true
$result -contains 'add' | Should -Be $true
$result -contains 'reapply' | Should -Be $true
$result -contains 'disable' | Should -Be $true
}
It 'Tab completes update-git-for-windows only on Windows' {
$result = & $module GitTabExpansionInternal 'git update-'

Expand Down