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

Update develop from master #517

Merged
merged 25 commits into from
Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
44e8583
Directory names that contain [brackets] cause GitPrompt to fail
duncansmart Nov 10, 2017
65658bf
Merge pull request #502 from duncansmart/patch-1
dahlbyk Nov 11, 2017
f252031
Add `Add-PoshGitToProfile -AllUsers` support
dahlbyk Dec 8, 2017
4dac43f
Fix duplicated tab completion of branches that exist locally and on t…
bergmeister Dec 12, 2017
82b84c4
use select-object because of performance and to keep order of arrays …
bergmeister Dec 12, 2017
111b59a
Make comment start with an upper case letter to poke the hanging PR b…
bergmeister Dec 13, 2017
42e31cc
Optimise git checkout completion fix by working in pipeline to avoid …
bergmeister Dec 14, 2017
d96a350
Cleanup unnecessary array syntax
bergmeister Dec 14, 2017
4e95488
Merge pull request #512 from dahlbyk/gh505
dahlbyk Dec 14, 2017
9819b07
Extract Test-Administrator helper
dahlbyk Dec 27, 2017
557f47e
Add elevated user error for -AllUsers
dahlbyk Dec 27, 2017
0a2dd63
Merge branch 'master' into AllUsers
dahlbyk Dec 27, 2017
364aa25
Fix #500 errors generated by Add-Member
rkeithhill Dec 31, 2017
c7a8261
Update tasks.json to 2.0.0 schema and pwsh
rkeithhill Dec 31, 2017
c9402bd
Clean up wording for work dir local status
rkeithhill Dec 31, 2017
9bb813b
Undo change that shouldn't be part of this PR
rkeithhill Jan 1, 2018
0b7a485
Merge pull request #515 from dahlbyk/rkeithhill/update-tasks-json
rkeithhill Jan 1, 2018
464ff69
Merge branch 'master' into rkeithhill/fix-status-legend
rkeithhill Jan 1, 2018
ae3603d
Merge branch 'master' into rkeithhill/fix-add-member-err-master
rkeithhill Jan 1, 2018
2ecf05a
Merge pull request #514 from dahlbyk/rkeithhill/fix-add-member-err-ma…
dahlbyk Jan 1, 2018
76d52f5
Adjust AllUsers elevated host error message
dahlbyk Jan 1, 2018
08d73ec
Merge branch 'master' into AllUsers
dahlbyk Jan 1, 2018
bf0ec4a
Merge pull request #504 from dahlbyk/AllUsers
dahlbyk Jan 1, 2018
bd06c5f
Merge branch 'master' into rkeithhill/fix-status-legend
dahlbyk Jan 1, 2018
fc692c5
Merge pull request #516 from dahlbyk/rkeithhill/fix-status-legend
dahlbyk Jan 1, 2018
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
63 changes: 30 additions & 33 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,46 @@
// 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",
"version": "2.0.0",

// Start PowerShell
"windows": {
"command": "${env:windir}\\System32\\windowspowershell\\v1.0\\PowerShell.exe"
"options": {
"shell": {
"executable": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [ "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command" ]
}
}
},
"linux": {
"command": "/usr/bin/powershell"
"options": {
"shell": {
"executable": "/usr/bin/pwsh",
"args": [ "-NoProfile", "-Command" ]
}
}
},
"osx": {
"command": "/usr/local/bin/powershell"
"options": {
"shell": {
"executable": "/usr/local/bin/pwsh",
"args": [ "-NoProfile", "-Command" ]
}
}
},

// 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": "$pester"
"label": "Test",
"type": "shell",
"command": "Invoke-Pester test -PesterOption @{IncludeVSCodeMarker=$true}",
"group": {
"kind": "test",
"isDefault": true
},
"problemMatcher": [
"$pester"
]
}
]
]
}
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,17 @@ By default, the status summary has the following format:
* `-` = Removed files
* `!` = Conflicted files
* As in `git status`, index status is dark green and working directory status is dark red
*
* W represents the status of the working folder
* `!` = There are untracked changes in the working tree (`LocalStagedStatus`)
* `~` = There are staged changes in the working tree waiting to be committed (`LocalWorkingStatus`)
* None = There are no uncommitted or unstaged changes to the working tree (`LocalDefault`)

* W represents the overall status of the working directory
* `!` = There are unstaged changes in the working tree (`LocalWorkingStatus`)
* `~` = There are uncommitted changes i.e. staged changes in the working tree waiting to be committed (`LocalStagedStatus`)
* None = There are no unstaged or uncommitted changes to the working tree (`LocalDefault`)
* `]` (`AfterText`)

The symbols and surrounding text can be customized by the corresponding properties on `$GitPromptSettings`.

For example, a status of `[master ≡ +0 ~2 -1 | +1 ~1 -0]` corresponds to the following `git status`:



```powershell
# On branch master
#
Expand Down
11 changes: 1 addition & 10 deletions src/GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,7 @@ $global:GitPromptSettings = [pscustomobject]@{
TruncatedBranchSuffix = '...'
}

# PowerShell 5.x only runs on Windows so use .NET types to determine isAdminProcess
# Or if we are on v6 or higher, check the $IsWindows pre-defined variable.
if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) {
$currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdminProcess = $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
else {
# Must be Linux or OSX, so use the id util. Root has userid of 0.
$isAdminProcess = 0 -eq (id -u)
}
$isAdminProcess = Test-Administrator

$adminHeader = if ($isAdminProcess) { 'Administrator: ' } else { '' }

Expand Down
9 changes: 6 additions & 3 deletions src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,12 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) {

# Handles git checkout <ref>
"^(?:checkout).* (?<ref>\S*)$" {
gitBranches $matches['ref'] $true
gitRemoteUniqueBranches $matches['ref']
gitTags $matches['ref']
& {
gitBranches $matches['ref'] $true
gitRemoteUniqueBranches $matches['ref']
gitTags $matches['ref']
# Return only unique branches (to eliminate duplicates where the branch exists locally and on the remote)
} | Select-Object -Unique
}

# Handles git worktree add <path> <ref>
Expand Down
18 changes: 9 additions & 9 deletions src/GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Get-GitDirectory {
$Env:GIT_DIR -replace '\\|/', [System.IO.Path]::DirectorySeparatorChar
}
else {
$currentDir = Get-Item $pathInfo -Force
$currentDir = Get-Item -LiteralPath $pathInfo -Force
while ($currentDir) {
$gitDirPath = Join-Path $currentDir.FullName .git
if (Test-Path -LiteralPath $gitDirPath -PathType Container) {
Expand Down Expand Up @@ -295,16 +295,16 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {
$indexPaths = @(GetUniquePaths $indexAdded,$indexModified,$indexDeleted,$indexUnmerged)
$workingPaths = @(GetUniquePaths $filesAdded,$filesModified,$filesDeleted,$filesUnmerged)
$index = (,$indexPaths) |
Add-Member -PassThru NoteProperty Added $indexAdded.ToArray() |
Add-Member -PassThru NoteProperty Modified $indexModified.ToArray() |
Add-Member -PassThru NoteProperty Deleted $indexDeleted.ToArray() |
Add-Member -PassThru NoteProperty Unmerged $indexUnmerged.ToArray()
Add-Member -Force -PassThru NoteProperty Added $indexAdded.ToArray() |
Add-Member -Force -PassThru NoteProperty Modified $indexModified.ToArray() |
Add-Member -Force -PassThru NoteProperty Deleted $indexDeleted.ToArray() |
Add-Member -Force -PassThru NoteProperty Unmerged $indexUnmerged.ToArray()

$working = (,$workingPaths) |
Add-Member -PassThru NoteProperty Added $filesAdded |
Add-Member -PassThru NoteProperty Modified $filesModified.ToArray() |
Add-Member -PassThru NoteProperty Deleted $filesDeleted.ToArray() |
Add-Member -PassThru NoteProperty Unmerged $filesUnmerged.ToArray()
Add-Member -Force -PassThru NoteProperty Added $filesAdded |
Add-Member -Force -PassThru NoteProperty Modified $filesModified.ToArray() |
Add-Member -Force -PassThru NoteProperty Deleted $filesDeleted.ToArray() |
Add-Member -Force -PassThru NoteProperty Unmerged $filesUnmerged.ToArray()

$result = New-Object PSObject -Property @{
GitDir = $gitDir
Expand Down
37 changes: 33 additions & 4 deletions src/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) {
}
}

function Test-Administrator {
# PowerShell 5.x only runs on Windows so use .NET types to determine isAdminProcess
# Or if we are on v6 or higher, check the $IsWindows pre-defined variable.
if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) {
$currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

# Must be Linux or OSX, so use the id util. Root has userid of 0.
return 0 -eq (id -u)
}

<#
.SYNOPSIS
Configures your PowerShell profile (startup) script to import the posh-git
Expand All @@ -65,7 +77,12 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) {
.PARAMETER AllHosts
By default, this command modifies the CurrentUserCurrentHost profile
script. By specifying the AllHosts switch, the command updates the
CurrentUserAllHosts profile.
CurrentUserAllHosts profile (or AllUsersAllHosts, given -AllUsers).
.PARAMETER AllUsers
By default, this command modifies the CurrentUserCurrentHost profile
script. By specifying the AllUsers switch, the command updates the
AllUsersCurrentHost profile (or AllUsersAllHosts, given -AllHosts).
Requires elevated permissions.
.PARAMETER Force
Do not check if the specified profile script is already importing
posh-git. Just add Import-Module posh-git command.
Expand All @@ -76,7 +93,7 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) {
Updates your profile script for the current PowerShell host to import the
posh-git module when the current PowerShell host starts.
.EXAMPLE
PS C:\> Add-PoshGitToProfile -AllHost
PS C:\> Add-PoshGitToProfile -AllHosts
Updates your profile script for all PowerShell hosts to import the posh-git
module whenever any PowerShell host starts.
.INPUTS
Expand All @@ -91,6 +108,10 @@ function Add-PoshGitToProfile {
[switch]
$AllHosts,

[Parameter()]
[switch]
$AllUsers,

[Parameter()]
[switch]
$Force,
Expand All @@ -104,9 +125,18 @@ function Add-PoshGitToProfile {
$TestParams
)

if ($AllUsers -and !(Test-Administrator)) {
throw 'Adding posh-git to an AllUsers profile requires an elevated host.'
}

$underTest = $false

$profilePath = if ($AllHosts) { $PROFILE.CurrentUserAllHosts } else { $PROFILE.CurrentUserCurrentHost }
$profileName = $(if ($AllUsers) { 'AllUsers' } else { 'CurrentUser' }) `
+ $(if ($AllHosts) { 'AllHosts' } else { 'CurrentHost' })
Write-Verbose "`$profileName = '$profileName'"

$profilePath = $PROFILE.$profileName
Write-Verbose "`$profilePath = '$profilePath'"

# Under test, we override some variables using $args as a backdoor.
if (($TestParams.Count -gt 0) -and ($TestParams[0] -is [string])) {
Expand Down Expand Up @@ -149,7 +179,6 @@ function Add-PoshGitToProfile {

if (!$profilePath) {
Write-Warning "Skipping add of posh-git import to profile; no profile found."
Write-Verbose "`$profilePath = '$profilePath'"
Write-Verbose "`$PROFILE = '$PROFILE'"
Write-Verbose "CurrentUserCurrentHost = '$($PROFILE.CurrentUserCurrentHost)'"
Write-Verbose "CurrentUserAllHosts = '$($PROFILE.CurrentUserAllHosts)'"
Expand Down
9 changes: 5 additions & 4 deletions src/en-US/about_posh-git.help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ GIT STATUS SUMMARY
* Index status is dark green and working directory status is dark red
reflecting the colors used by 'git status'.

* W represents the status of the working directory
* ! = There are untracked changes (LocalStagedStatus)
* ~ = There are staged changes waiting to be committed (LocalWorkingStatus)
* None = There are no uncommitted or unstaged changes (LocalDefault)
* W represents the overall status of the working directory
* ! = There are unstaged changes (LocalWorkingStatus)
* ~ = There are uncommitted changes i.e. staged changes waiting to be
committed (LocalStagedStatus)
* None = There are no unstaged or uncommitted changes (LocalDefault)
* ] (AfterText)

The (symbols) and surrounding text can be customized by the corresponding
Expand Down