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

Support git push <remote> +<tab> #343

Merged
merged 3 commits into from
Jan 4, 2017
Merged
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
26 changes: 14 additions & 12 deletions GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ function script:gitRemotes($filter) {
Where-Object { $_ -like "$filter*" }
}

function script:gitBranches($filter, $includeHEAD = $false) {
$prefix = $null
function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') {
if ($filter -match "^(?<from>\S*\.{2,3})(?<to>.*)") {
$prefix = $matches['from']
$prefix += $matches['from']
$filter = $matches['to']
}
$branches = @(git branch --no-color | ForEach-Object { if($_ -match "^\*?\s*(?<ref>.*)") { $matches['ref'] } }) +
Expand All @@ -79,9 +78,10 @@ function script:gitBranches($filter, $includeHEAD = $false) {
ForEach-Object { $prefix + $_ }
}

function script:gitTags($filter) {
function script:gitTags($filter, $prefix = '') {
git tag |
Where-Object { $_ -like "$filter*" }
Where-Object { $_ -like "$filter*" } |
ForEach-Object { $prefix + $_ }
}

function script:gitFeatures($filter, $command){
Expand All @@ -92,10 +92,10 @@ function script:gitFeatures($filter, $command){
ForEach-Object { $prefix + $_ }
}

function script:gitRemoteBranches($remote, $ref, $filter) {
function script:gitRemoteBranches($remote, $ref, $filter, $prefix = '') {
git branch --no-color -r |
Where-Object { $_ -like " $remote/$filter*" } |
ForEach-Object { $ref + ($_ -replace " $remote/","") }
ForEach-Object { $prefix + $ref + ($_ -replace " $remote/","") }
}

function script:gitStashes($filter) {
Expand Down Expand Up @@ -237,15 +237,17 @@ function GitTabExpansion($lastBlock) {
}

# Handles git push remote <ref>:<branch>
"^push.* (?<remote>\S+) (?<ref>[^\s\:]*\:)(?<branch>\S*)$" {
gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch']
# Handles git push remote +<ref>:<branch>
"^push.* (?<remote>\S+) (?<force>\+?)(?<ref>[^\s\:]*\:)(?<branch>\S*)$" {
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+) (?<ref>[^\s\:]*)$" {
gitBranches $matches['ref']
gitTags $matches['ref']
"^(?:push|pull).* (?:\S+) (?<force>\+?)(?<ref>[^\s\:]*)$" {
gitBranches $matches['ref'] -prefix $matches['force']
gitTags $matches['ref'] -prefix $matches['force']
}

# Handles git pull <remote>
Expand Down