diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 194358c5e..93a631b2d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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" + ] } - ] + ] } diff --git a/README.md b/README.md index 49fb749b3..c5c443173 100644 --- a/README.md +++ b/README.md @@ -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 # diff --git a/src/GitPrompt.ps1 b/src/GitPrompt.ps1 index 106b5c06c..762d60387 100644 --- a/src/GitPrompt.ps1 +++ b/src/GitPrompt.ps1 @@ -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 { '' } diff --git a/src/GitUtils.ps1 b/src/GitUtils.ps1 index 70a822410..b606d0c72 100644 --- a/src/GitUtils.ps1 +++ b/src/GitUtils.ps1 @@ -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 diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 223c0376e..4df7ab707 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -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 @@ -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. @@ -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 @@ -91,6 +108,10 @@ function Add-PoshGitToProfile { [switch] $AllHosts, + [Parameter()] + [switch] + $AllUsers, + [Parameter()] [switch] $Force, @@ -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])) { @@ -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)'" diff --git a/src/en-US/about_posh-git.help.txt b/src/en-US/about_posh-git.help.txt index b5dbcf95c..3af7bf0d8 100644 --- a/src/en-US/about_posh-git.help.txt +++ b/src/en-US/about_posh-git.help.txt @@ -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