Skip to content

Commit

Permalink
Merge pull request #517 from dahlbyk/master
Browse files Browse the repository at this point in the history
Update develop from master
  • Loading branch information
dahlbyk committed Jan 1, 2018
2 parents 84d8635 + fc692c5 commit 1e9c231
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 66 deletions.
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 @@ -114,16 +114,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
16 changes: 8 additions & 8 deletions src/GitUtils.ps1
Original file line number Diff line number Diff line change
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

0 comments on commit 1e9c231

Please sign in to comment.