-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Improve tab expansion to handle params for push. #379
Conversation
eb01328
to
66612c9
Compare
src/GitTabExpansion.ps1
Outdated
$script:someCommands = @('add','am','annotate','archive','bisect','blame','branch','bundle','checkout','cherry', | ||
'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','revert','rm', | ||
'format-patch','gc','grep','gui','help','init','instaweb','ls-files','log','merge','mergetool', |
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.
Out of curiosity, why add ls-files
? You can get tab expansion for all commands (including plumbing like ls-files
) by setting $Global:GitTabSettings.AllCommands = $true
, but I'm not sure this belongs with the porcelain commands.
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.
I'll remove this. Didn't know about AllCommands
. Thanks.
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.
I think we're missing a few tests, otherwise this seems legit.
test/TabExpansion.Tests.ps1
Outdated
$result = & $module GitTabExpansionInternal 'git push --follow-tags -u origin ma' | ||
$result | Should BeExactly 'master' | ||
} | ||
} |
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.
Add tests to assert empty result when expanding a missing remote, branch, or remote/branch combination?
It wouldn't be a terrible idea to set a remote and/or branch name with a -
in it, as a sanity check for the gitParams
regex.
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.
I can add some more tests. Can a branch name start with - or --?
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.
No, that's one of the few non-system restrictions on branch/remote names.
src/GitTabExpansion.ps1
Outdated
gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch'] -prefix $matches['force'] | ||
} | ||
|
||
# Handles git push remote <ref> | ||
# Handles git push remote +<ref> | ||
# Handles git pull remote <ref> | ||
"^(?:push|pull).* (?:\S+) (?<force>\+?)(?<ref>[^\s\:]*)$" { | ||
"^(?:push|pull).* ${gitParams}(?<remote>[^\s-]\S*) (?<force>\+?)(?<ref>[^\s\:]*)$" { |
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.
Not sure how to keep this maintainable over time (other than a proper Git arg parser 🙄 ), but it's legal to have Git parameters between the remote and ref specs, and between individual ref specs (e.g. git push origin -f master -u my-branch
). I'm fine with this incremental improvement for now, but food for thought.
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.
Well, we could try "^(?:push|pull).* ${gitParams}(?<remote>[^\s-]\S*)${gitParams} (?<force>\+?)(?<ref>[^\s\:]*)$"
and add some more tests? I'm OK with the incremental improvement unless we think it would be as simple as the above tweaks to handle this situation.
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.
Something that like that seems like it should do the trick - give it a try?
66612c9
to
87afebd
Compare
@dahlbyk I don't have a good test case for the remote refspec (with |
OK I found some examples of refspec to add tests for. Found a regex bug in the process. Pester tests FTW! |
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.
So far, so good. Stretch goal, since you're already up to your neck in this: git push
supports multiple ref specs, so it's not unreasonable to expect tab to work at the end of git push -u origin HEAD:demo --follow-tags v0.1 +HEAD:ma
to complete with +HEAD:master
.
I took the liberty of simplifying your refs/heads/master:ma
sample specs with a more real-world test case, but managed to ignore the tests on the line after. Feel free to rebase -i
before a final merge.
test/TabExpansion.Tests.ps1
Outdated
It 'Tab completes all :branches' { | ||
$result = & $module GitTabExpansionInternal 'git push origin :' | ||
$result -contains ':master' | Should Be $true | ||
# Is the following a valid branch name in a refspec? |
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.
No, it would be awesome if the {remote}/HEAD -> {remote}/default
line from git branch -r
were ignored. I never actually created an issue, but this does bug me periodically.
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.
Thanks. I wasn't sure about that but it didn't look right (with spaces, ->). Thanks for updating the sample specs. I "think" the multiple ref specs should be easy to implement/test. I'll look at that tonight.
Oh sure, goad me on. :-) OK last commit addresses this I think. |
82ef1ae
to
013a00c
Compare
Not quite, since |
Yeah, getting into usages of git I'm not so familiar with. Well, you've fixed it. Want me to rebase or merge as is (didn't see any fixup)? |
Nevermind, there is a fixup. |
Fix #234 BTW if we decide this is an OK fix (need another set of eyes on my $gitParams regex), I'd like to review the fact that all these switch regex case statements fallthrough to the next (observed while debugging tab expansion). I don't believe that is necessary. I'm thinking that most (all) of these should have a break statement. Started a minimum set of Pester tests for tab completion. Would be good to flesh these out over time. Add debug configuration for VSCode that is dedicated to debugging Pester tests.
Add Pester tests for this feature.
Make multiple push spec test more complete
013a00c
to
dffe385
Compare
@dahlbyk FYI I rebased -i --autosquash this branch and pushed with --force-with-lease in case you want to make more changes. Otherwise, I'm feeling pretty good about merging this in. |
Fix #234 BTW if we decide this is an OK fix (need another set of eyes on my $gitParams regex), I'd like to review the fact that all these switch regex case statements fallthrough to the next (observed while debugging tab expansion). I don't believe that is necessary. I'm thinking that most (all) of these should have a break statement.
Started a minimum set of Pester tests for tab completion. Would be good to flesh these out over time.
BTW the latest PowerShell extension for VS Code release supports "attach to PS host process" which makes debugging tab expansion a breeze. VS Code FTW! :-)