From a1002f38318e9a30c4b02c1d25a83e0f75c92400 Mon Sep 17 00:00:00 2001 From: Brian Golden <bgold09@users.noreply.github.com> Date: Sun, 24 Jul 2022 10:45:28 -0400 Subject: [PATCH 1/3] Tab completion for sparse-checkout and its subcommands --- src/GitTabExpansion.ps1 | 9 ++++++++- test/TabExpansion.Tests.ps1 | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 5820da226..3871e0c22 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -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 = " @@ -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' @@ -462,6 +464,11 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { gitBranches $matches['ref'] } + # Handles git sparse-checkout <cmd> + "^sparse-checkout (?<cmd>$($subcommands.Keys -join '|'))\s+(?<op>\S*)$" { + gitCmdOperations $subcommands $matches['cmd'] $matches['op'] + } + # Handles git <cmd> <ref> "^(?:cherry|cherry-pick|diff|difftool|log|merge|rebase|reflog\s+show|reset|revert|show).* (?<ref>\S*)$" { gitBranches $matches['ref'] $true diff --git a/test/TabExpansion.Tests.ps1 b/test/TabExpansion.Tests.ps1 index 4138893e4..e79eaaf7a 100644 --- a/test/TabExpansion.Tests.ps1 +++ b/test/TabExpansion.Tests.ps1 @@ -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-' From fc2dd32b5ac72a3ec9e3a35268fa4f2910ff86bb Mon Sep 17 00:00:00 2001 From: Brian Golden <bgold09@users.noreply.github.com> Date: Sun, 24 Jul 2022 10:46:00 -0400 Subject: [PATCH 2/3] Tab completion for sparse-checkout parameters --- src/GitParamTabExpansion.ps1 | 8 ++++++++ src/GitTabExpansion.ps1 | 1 + test/GitParamTabExpansion.Tests.ps1 | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/GitParamTabExpansion.ps1 b/src/GitParamTabExpansion.ps1 index 9bf32d832..9313e1b2b 100644 --- a/src/GitParamTabExpansion.ps1 +++ b/src/GitParamTabExpansion.ps1 @@ -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' @@ -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= notes no-notes show-notes no-standard-notes standard-notes show-signature' + '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' @@ -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 = @{ diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 3871e0c22..fd595d7d7 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -71,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: # diff --git a/test/GitParamTabExpansion.Tests.ps1 b/test/GitParamTabExpansion.Tests.ps1 index 8eaf20d41..6eb2261dc 100644 --- a/test/GitParamTabExpansion.Tests.ps1 +++ b/test/GitParamTabExpansion.Tests.ps1 @@ -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-index 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 + } + } } From 1c9afa055f99caf23735b9f1076f4276497bd1f0 Mon Sep 17 00:00:00 2001 From: Brian Golden <bgold09@users.noreply.github.com> Date: Mon, 10 Apr 2023 16:22:13 -0400 Subject: [PATCH 3/3] fix expansion for long params --- src/GitTabExpansion.ps1 | 5 +++-- test/GitParamTabExpansion.Tests.ps1 | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index fd595d7d7..bcd08a329 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -466,8 +466,9 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } # Handles git sparse-checkout <cmd> - "^sparse-checkout (?<cmd>$($subcommands.Keys -join '|'))\s+(?<op>\S*)$" { - gitCmdOperations $subcommands $matches['cmd'] $matches['op'] + "sparse-checkout\s+(?<cmd>$sparseCheckoutCommandsWithLongParams).*--(?<param>\S*)$" + { + expandLongParams $longSparseCheckoutParams $matches['cmd'] $matches['param'] } # Handles git <cmd> <ref> diff --git a/test/GitParamTabExpansion.Tests.ps1 b/test/GitParamTabExpansion.Tests.ps1 index 6eb2261dc..c7c1fd3db 100644 --- a/test/GitParamTabExpansion.Tests.ps1 +++ b/test/GitParamTabExpansion.Tests.ps1 @@ -161,7 +161,7 @@ Describe 'ParamsTabExpansion Tests' { $result -contains '--stdin' | Should -Be $true } It 'Tab completes all long sparse-checkout reapply parameters' { - $result = & $module GitTabExpansionInternal 'git sparse-index reapply --' + $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