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

Improve tab expansion to handle params for push. #379

Merged
merged 5 commits into from
Feb 2, 2017

Conversation

rkeithhill
Copy link
Collaborator

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! :-)

@rkeithhill rkeithhill force-pushed the rkeithhill/is234-fix-remote-push-tab-exp branch from eb01328 to 66612c9 Compare January 31, 2017 03:35
@rkeithhill rkeithhill self-assigned this Jan 31, 2017
@rkeithhill rkeithhill added this to the v0.7 milestone Jan 31, 2017
$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',
Copy link
Owner

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.

Copy link
Collaborator Author

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.

Copy link
Owner

@dahlbyk dahlbyk left a 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.

$result = & $module GitTabExpansionInternal 'git push --follow-tags -u origin ma'
$result | Should BeExactly 'master'
}
}
Copy link
Owner

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.

Copy link
Collaborator Author

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 --?

Copy link
Owner

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.

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\:]*)$" {
Copy link
Owner

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.

Copy link
Collaborator Author

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.

Copy link
Owner

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?

@rkeithhill rkeithhill force-pushed the rkeithhill/is234-fix-remote-push-tab-exp branch from 66612c9 to 87afebd Compare January 31, 2017 15:15
@rkeithhill
Copy link
Collaborator Author

@dahlbyk I don't have a good test case for the remote refspec (with : in it). Can you provide me with such a refspec that returns results?

@rkeithhill
Copy link
Collaborator Author

OK I found some examples of refspec to add tests for. Found a regex bug in the process. Pester tests FTW!

Copy link
Owner

@dahlbyk dahlbyk left a 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.

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?
Copy link
Owner

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.

Copy link
Collaborator Author

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.

@rkeithhill
Copy link
Collaborator Author

Stretch goal, since you're already up to your neck in this

Oh sure, goad me on. :-) OK last commit addresses this I think.

@dahlbyk dahlbyk force-pushed the rkeithhill/is234-fix-remote-push-tab-exp branch from 82ef1ae to 013a00c Compare February 2, 2017 16:52
@dahlbyk
Copy link
Owner

dahlbyk commented Feb 2, 2017

Stretch goal, since you're already up to your neck in this

Oh sure, goad me on. :-) OK last commit addresses this I think.

Not quite, since ref:branch can be mixed with other forms. I added/adjusted the tests and made the regex dumber between the remote and force/ref, so I think we're good.

@rkeithhill
Copy link
Collaborator Author

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)?

@rkeithhill
Copy link
Collaborator Author

Nevermind, there is a fixup.

rkeithhill and others added 5 commits February 2, 2017 13:35
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
@rkeithhill rkeithhill force-pushed the rkeithhill/is234-fix-remote-push-tab-exp branch from 013a00c to dffe385 Compare February 2, 2017 20:40
@rkeithhill
Copy link
Collaborator Author

@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.

@dahlbyk dahlbyk merged commit 3a098c0 into master Feb 2, 2017
@dahlbyk dahlbyk deleted the rkeithhill/is234-fix-remote-push-tab-exp branch February 2, 2017 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect tab expansion for git push --option <remote>
2 participants