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

git and Posh-git check #440

Merged
merged 2 commits into from
Mar 25, 2015
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: 23 additions & 3 deletions vendor/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,41 @@ if( -not $env:PSModulePath.Contains($CmderModulePath) ){
$env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;")
}

try {
Get-command -Name "git" -ErrorAction Stop >$null
Import-Module -Name "posh-git" -ErrorAction Stop >$null
$gitStatus = $true
} catch {
Write-Warning "Missing git support"
$gitStatus = $false
}

function checkGit($Path) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jackbennett @MartiUK
I don't understand the reason of this function. Posh-Git checks himself what you write, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled out the code that imported everything all the time from our vendor\psmodules in another commit (e811c60)

Posh-git needs a module manifest creating to behave with powershell's auto-loading behaviour. This checks if we have git and need the cmdlet only if we're actually in a git repository.

All in the name of speed. You don't need to wait for all the git stuff constantly especially if its not even used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. So e811c60

if (Test-Path -Path (Join-Path $Path '.git/') ) {
Write-VcsStatus
return
}
$SplitPath = split-path $path
if ($SplitPath) {
checkGit($SplitPath)
}
}

# Set up a Cmder prompt, adding the git prompt parts inside git repos
function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE
$Host.UI.RawUI.ForegroundColor = "White"
Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
if (Get-Module posh-git) {
Write-VcsStatus
if($gitStatus){
checkGit($pwd.ProviderPath)
}
$global:LASTEXITCODE = $realLASTEXITCODE
Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray"
return " "
}

# Load special features come from posh-git
if (Get-Module posh-git) {
if ($gitStatus) {
Enable-GitColors
Start-SshAgent -Quiet
}
Expand Down