Skip to content

Commit

Permalink
Merge branch 'master' into git-status-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Jan 2, 2017
2 parents 2f13488 + b90f7df commit 675299a
Show file tree
Hide file tree
Showing 20 changed files with 975 additions and 344 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true

[*.{ps1,psd1,psm1}]
trim_trailing_whitespace = true
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch (current file)",
"script": "${file}",
"args": [],
"cwd": "${file}"
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.rulers": [ 120 ],
"powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1"
}
66 changes: 66 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${relativeFile}: the current opened file relative to workspaceRoot
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",

// Start PowerShell
"windows": {
"command": "${env.windir}\\sysnative\\windowspowershell\\v1.0\\PowerShell.exe"
},
"linux": {
"command": "/usr/bin/powershell"
},
"osx": {
"command": "/usr/local/bin/powershell"
},

// The command is a shell script
"isShellCommand": true,

// Show the output window always
"showOutput": "always",

"args": [
"-NoProfile", "-ExecutionPolicy", "Bypass"
],

// Associate with test task runner
"tasks": [
{
"taskName": "Test",
"suppressTaskName": true,
"isTestCommand": true,
"showOutput": "always",
"args": [
"Write-Host 'Invoking Pester'; Invoke-Pester test -PesterOption @{IncludeVSCodeMarker=$true};",
"Invoke-Command { Write-Host 'Completed Test task in task runner.' }"
],
"problemMatcher": [
{
"owner": "powershell",
"fileLocation": ["absolute"],
"severity": "error",
"pattern": [
{
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
"message": 1
},
{
"regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
"file": 1,
"line": 2
}
]
}
]
}
]
}
143 changes: 94 additions & 49 deletions GitPrompt.ps1

Large diffs are not rendered by default.

89 changes: 48 additions & 41 deletions GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ $gitflowsubcommands = @{

function script:gitCmdOperations($commands, $command, $filter) {
$commands.$command -split ' ' |
where { $_ -like "$filter*" }
Where-Object { $_ -like "$filter*" }
}


$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','shortlog','show','stash','status','submodule','svn','tag','whatchanged')
$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',
'shortlog','show','stash','status','submodule','svn','tag','whatchanged')
try {
if ((git help -a 2>&1 | Select-String flow) -ne $null) {
if ($null -ne (git help -a 2>&1 | Select-String flow)) {
$script:someCommands += 'flow'
}
}
catch {
Write-Debug "Search for 'flow' in 'git help' output failed with error: $_"
}

function script:gitCommands($filter, $includeAliases) {
Expand All @@ -44,20 +49,20 @@ function script:gitCommands($filter, $includeAliases) {
$cmdList += $someCommands -like "$filter*"
} else {
$cmdList += git help --all |
where { $_ -match '^ \S.*' } |
foreach { $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) } |
where { $_ -like "$filter*" }
Where-Object { $_ -match '^ \S.*' } |
ForEach-Object { $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) } |
Where-Object { $_ -like "$filter*" }
}

if ($includeAliases) {
$cmdList += gitAliases $filter
}
$cmdList | sort
$cmdList | Sort-Object
}

function script:gitRemotes($filter) {
git remote |
where { $_ -like "$filter*" }
Where-Object { $_ -like "$filter*" }
}

function script:gitBranches($filter, $includeHEAD = $false) {
Expand All @@ -66,49 +71,49 @@ function script:gitBranches($filter, $includeHEAD = $false) {
$prefix = $matches['from']
$filter = $matches['to']
}
$branches = @(git branch --no-color | foreach { if($_ -match "^\*?\s*(?<ref>.*)") { $matches['ref'] } }) +
@(git branch --no-color -r | foreach { if($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
$branches = @(git branch --no-color | ForEach-Object { if($_ -match "^\*?\s*(?<ref>.*)") { $matches['ref'] } }) +
@(git branch --no-color -r | ForEach-Object { if($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
@(if ($includeHEAD) { 'HEAD','FETCH_HEAD','ORIG_HEAD','MERGE_HEAD' })
$branches |
where { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
foreach { $prefix + $_ }
Where-Object { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
ForEach-Object { $prefix + $_ }
}

function script:gitTags($filter) {
git tag |
where { $_ -like "$filter*" }
Where-Object { $_ -like "$filter*" }
}

function script:gitFeatures($filter, $command){
$featurePrefix = git config --local --get "gitflow.prefix.$command"
$branches = @(git branch --no-color | foreach { if($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } })
$branches = @(git branch --no-color | ForEach-Object { if($_ -match "^\*?\s*$featurePrefix(?<ref>.*)") { $matches['ref'] } })
$branches |
where { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
foreach { $prefix + $_ }
Where-Object { $_ -ne '(no branch)' -and $_ -like "$filter*" } |
ForEach-Object { $prefix + $_ }
}

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

function script:gitStashes($filter) {
(git stash list) -replace ':.*','' |
where { $_ -like "$filter*" } |
foreach { "'$_'" }
Where-Object { $_ -like "$filter*" } |
ForEach-Object { "'$_'" }
}

function script:gitTfsShelvesets($filter) {
(git tfs shelve-list) |
where { $_ -like "$filter*" } |
foreach { "'$_'" }
Where-Object { $_ -like "$filter*" } |
ForEach-Object { "'$_'" }
}

function script:gitFiles($filter, $files) {
$files | sort |
where { $_ -like "$filter*" } |
foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
$files | Sort-Object |
Where-Object { $_ -like "$filter*" } |
ForEach-Object { if($_ -like '* *') { "'$_'" } else { $_ } }
}

function script:gitIndex($filter) {
Expand All @@ -126,7 +131,8 @@ function script:gitCheckoutFiles($filter) {
function script:gitDiffFiles($filter, $staged) {
if ($staged) {
gitFiles $filter $GitStatus.Index.Modified
} else {
}
else {
gitFiles $filter (@($GitStatus.Working.Unmerged) + @($GitStatus.Working.Modified) + @($GitStatus.Index.Modified))
}
}
Expand All @@ -140,38 +146,39 @@ function script:gitDeleted($filter) {
}

function script:gitAliases($filter) {
git config --get-regexp ^alias\. | foreach {
git config --get-regexp ^alias\. | ForEach-Object{
if($_ -match "^alias\.(?<alias>\S+) .*") {
$alias = $Matches['alias']
if($alias -like "$filter*") {
$alias
}
}
} | Sort
} | Sort-Object
}

function script:expandGitAlias($cmd, $rest) {
if((git config --get-regexp "^alias\.$cmd`$") -match "^alias\.$cmd (?<cmd>[^!].*)`$") {
if ((git config --get-regexp "^alias\.$cmd`$") -match "^alias\.$cmd (?<cmd>[^!].*)`$") {
return "git $($Matches['cmd'])$rest"
} else {
}
else {
return "git $cmd$rest"
}
}

function GitTabExpansion($lastBlock) {

if($lastBlock -match "^$(Get-AliasPattern git) (?<cmd>\S+)(?<args> .*)$") {
if ($lastBlock -match "^$(Get-AliasPattern git) (?<cmd>\S+)(?<args> .*)$") {
$lastBlock = expandGitAlias $Matches['cmd'] $Matches['args']
}

# Handles tgit <command> (tortoisegit)
if($lastBlock -match "^$(Get-AliasPattern tgit) (?<cmd>\S*)$") {
# Need return statement to prevent fall-through.
return $tortoiseGitCommands | where { $_ -like "$($matches['cmd'])*" }
if ($lastBlock -match "^$(Get-AliasPattern tgit) (?<cmd>\S*)$") {
# Need return statement to prevent fall-through.
return $tortoiseGitCommands | Where-Object { $_ -like "$($matches['cmd'])*" }
}

# Handles gitk
if($lastBlock -match "^$(Get-AliasPattern gitk).* (?<ref>\S*)$"){
if ($lastBlock -match "^$(Get-AliasPattern gitk).* (?<ref>\S*)$"){
return gitBranches $matches['ref'] $true
}

Expand Down Expand Up @@ -234,10 +241,11 @@ function GitTabExpansion($lastBlock) {
gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch']
}

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

# Handles git pull <remote>
Expand Down Expand Up @@ -292,8 +300,7 @@ function GitTabExpansion($lastBlock) {
}

$PowerTab_RegisterTabExpansion = if (Get-Module -Name powertab) { Get-Command Register-TabExpansion -Module powertab -ErrorAction SilentlyContinue }
if ($PowerTab_RegisterTabExpansion)
{
if ($PowerTab_RegisterTabExpansion) {
& $PowerTab_RegisterTabExpansion "git.exe" -Type Command {
param($Context, [ref]$TabExpansionHasOutput, [ref]$QuoteSpaces) # 1:

Expand Down
Loading

0 comments on commit 675299a

Please sign in to comment.