diff --git a/vendor/clink.lua b/vendor/clink.lua index a0f15c5..2d35e47 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -339,32 +339,27 @@ local function get_svn_branch(svn_dir) end --- --- Get the status of working dir --- @return {bool} +-- Get the status and conflict status of working dir +-- @return {bool , bool } --- local function get_git_status() local file = io_popenyield("git --no-optional-locks status --porcelain 2>nul") + local conflict_found = false + local is_status = true for line in file:lines() do - file:close() - return false + local code = line:sub(1, 2) + -- print (string.format("code: %s, line: %s", code, line)) + if code == "DD" or code == "AU" or code == "UD" or code == "UA" or code == "DU" or code == "AA" or code == "UU" then + is_status = false + conflict_found = true + break + -- unversioned files are ignored, comment out 'code ~= "!!"' to unignore them + elseif code ~= "!!" and code ~= "??" then + is_status = false + end end file:close() - - return true -end - ---- --- Gets the conflict status --- @return {bool} indicating true for conflict, false for no conflicts ---- -function get_git_conflict() - local file = io_popenyield("git diff --name-only --diff-filter=U 2>nul") - for line in file:lines() do - file:close() - return true; - end - file:close() - return false + return { status = is_status, conflict = conflict_found } end @@ -404,7 +399,7 @@ end --- local function get_git_info_table() local info = clink_promptcoroutine(function () - return { status=get_git_status(), conflict=get_git_conflict() } + return get_git_status() end) if not info then info = cached_info.git_info or {} diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index ad9182a..ea3df01 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -3,6 +3,7 @@ # !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED # !!! Use "%CMDER_ROOT%\config\user_profile.ps1" to add your own startup commands +$CMDER_INIT_START=$(Get-Date -UFormat %s) # Compatibility with PS major versions <= 2 if(!$PSScriptRoot) { @@ -39,13 +40,48 @@ if(-not $moduleInstallerAvailable -and -not $env:PSModulePath.Contains($CmderMod $env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;") } -try { - # Check if git is on PATH, i.e. Git already installed on system - Get-command -Name "git" -ErrorAction Stop >$null -} catch { - if (test-path "$env:CMDER_ROOT\vendor\git-for-windows") { - Configure-Git "$env:CMDER_ROOT\vendor\git-for-windows" +$gitVersionVendor = (readVersion -gitPath "$ENV:CMDER_ROOT\vendor\git-for-windows\cmd") +# write-host "GIT VENDOR: ${gitVersionVendor}" + +# Get user installed Git Version[s] and Compare with vendored if found. +foreach ($git in (get-command -ErrorAction SilentlyContinue -all 'git')) { + # write-host "GIT Path: " + $git.Path + $gitDir = Split-Path -Path $git.Path + $gitDir = isGitShim -gitPath $gitDir + $gitVersionUser = (readVersion -gitPath $gitDir) + # write-host "GIT USER: ${gitVersionUser}" + + $useGitVersion = compare_git_versions -userVersion $gitVersionUser -vendorVersion $gitVersionVendor + # write-host "Using GIT Version: ${useGitVersion}" + + # Use user installed Git + if ($gitPathUser -eq $null) { + if ($gitDir -match '\\mingw32\\bin' -or $gitDir -match '\\mingw64\\bin') { + $gitPathUser = ($gitDir.subString(0,$gitDir.Length - 12)) + } else { + $gitPathUser = ($gitDir.subString(0,$gitDir.Length - 4)) + } } + + if ($useGitVersion -eq $gitVersionUser) { + # write-host "Using GIT Dir: ${gitDir}" + $ENV:GIT_INSTALL_ROOT = $gitPathUser + $ENV:GIT_INSTALL_TYPE = 'USER' + break + } +} + +# User vendored Git. +if ($ENV:GIT_INSTALL_ROOT -eq $null -and $gitVersionVendor -ne $null) { + $ENV:GIT_INSTALL_ROOT = "$ENV:CMDER_ROOT\vendor\git-for-windows" + $ENV:GIT_INSTALL_TYPE = 'VENDOR' +} + +# write-host "GIT_INSTALL_ROOT: ${ENV:GIT_INSTALL_ROOT}" +# write-host "GIT_INSTALL_TYPE: ${ENV:GIT_INSTALL_TYPE}" + +if (-not($ENV:GIT_INSTALL_ROOT -eq $null)) { + $env:Path = Configure-Git -gitRoot "$ENV:GIT_INSTALL_ROOT" -gitType $ENV:GIT_INSTALL_TYPE -gitPathUser $gitPathUser } if ( Get-command -Name "vim" -ErrorAction silentlycontinue) { @@ -177,3 +213,6 @@ if ( $(get-command prompt).Definition -match 'PS \$\(\$executionContext.SessionS # if (!$(get-command Prompt).Options -match 'ReadOnly') {Set-Item -Path function:\prompt -Value $Prompt -Options ReadOnly} Set-Item -Path function:\prompt -Value $Prompt -Options ReadOnly } + +$CMDER_INIT_END=$(Get-Date -UFormat %s) +# write-host "Elapsed Time: $(get-Date) `($($CMDER_INIT_END - $CMDER_INIT_START) total`)" diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 59eae1e..eb782e5 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -1,18 +1,117 @@ -function Configure-Git($GIT_INSTALL_ROOT){ - $env:Path += $(";" + $GIT_INSTALL_ROOT + "\cmd") +function readVersion($gitPath) { + $gitExecutable = "${gitPath}\git.exe" - # Add "$GIT_INSTALL_ROOT\usr\bin" to the path if exists and not done already - $GIT_INSTALL_ROOT_ESC=$GIT_INSTALL_ROOT.replace('\','\\') - if ((test-path "$GIT_INSTALL_ROOT\usr\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\usr\\bin")) { - $env:path = "$env:path;$GIT_INSTALL_ROOT\usr\bin" - } + if (!(test-path "$gitExecutable")) { + return $null + } - # Add "$GIT_INSTALL_ROOT\mingw[32|64]\bin" to the path if exists and not done already - if ((test-path "$GIT_INSTALL_ROOT\mingw32\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw32\\bin")) { - $env:path = "$env:path;$GIT_INSTALL_ROOT\mingw32\bin" - } elseif ((test-path "$GIT_INSTALL_ROOT\mingw64\bin") -and -not ($env:path -match "$GIT_INSTALL_ROOT_ESC\\mingw64\\bin")) { - $env:path = "$env:path;$GIT_INSTALL_ROOT\mingw64\bin" - } + $gitVersion = (cmd /c "${gitExecutable}" --version) + + if ($gitVersion -match 'git version') { + ($trash1, $trash2, $gitVersion) = $gitVersion.split(' ', 3) + } else { + pause + return $null + } + + return $gitVersion.toString() +} + +function isGitShim($gitPath) { + # check if there's shim - and if yes follow the path + + if (test-path "${gitPath}\git.shim") { + $shim = (get-content "${gitPath}\git.shim") + ($trash, $gitPath) = $shim.replace(' ','').split('=') + + $gitPath=$gitPath.replace('\git.exe','') + } + + return $gitPath.toString() +} + +function compareVersions($userVersion, $vendorVersion) { + if (-not($userVersion -eq $null)) { + ($userMajor, $userMinor, $userPatch, $userBuild) = $userVersion.split('.', 4) + } else { + return -1 + } + + if (-not($vendorVersion -eq $null)) { + ($vendorMajor, $vendorMinor, $vendorPatch, $vendorBuild) = $vendorVersion.split('.', 4) + } else { + return 1 + } + + if (($userMajor -eq $vendorMajor) -and ($userMinor -eq $vendorMinor) -and ($userPatch -eq $vendorPatch) -and ($userBuild -eq $vendorBuild)) { + return 1 + } + + if ($userMajor -gt $vendorMajor) {return 1} + if ($userMajor -lt $vendorMajor) {return -1} + + if ($userMinor -gt $vendorMinor) {return 1} + if ($userMinor -lt $vendorMinor) {return -1} + + if ($userPatch -gt $vendorPatch) {return 1} + if ($userPatch -lt $vendorPatch) {return -1} + + if ($userBuild -gt $vendorBuild) {return 1} + if ($userBuild -lt $vendorBuild) {return -1} + + return 0 +} + +function compare_git_versions($userVersion, $vendorVersion) { + $result = compareVersions -userVersion $userVersion -vendorVersion $vendorVersion + + # write-host "Compare Versions Result: ${result}" + if ($result -ge 0) { + return $userVersion + } else { + return $vendorVersion + } +} + +function Configure-Git($gitRoot, $gitType, $gitPathUser){ + # Proposed Behavior + + # Modify the path if we are using VENDORED Git do nothing if using USER Git. + # If User Git is installed but older match its path config adding paths + # in the same path positions allowing a user to configure Cmder Git path + # using locally installed Git Path Config. + if ($gitType -eq 'VENDOR') { + # If User Git is installed replace its path config with Newer Vendored Git Path + if ($gitPathUser -ne '' -and $gitPathUser -ne $null) { + write-host -foregroundcolor yellow "Cmder 'profile.ps1': Replacing older user Git path '$gitPathUser' with newer vendored Git path '$gitRoot' in the system path..." + + $newPath = ($env:path -ireplace [regex]::Escape($gitPathUser), $gitRoot) + } else { + if (!($env:Path -match [regex]::Escape("$gitRoot\cmd"))) { + # write-host "Adding $gitRoot\cmd to the path" + $newPath = $($gitRoot + "\cmd" + ";" + $env:Path) + } + + # Add "$gitRoot\mingw[32|64]\bin" to the path if exists and not done already + if ((test-path "$gitRoot\mingw32\bin") -and -not ($env:path -match [regex]::Escape("$gitRoot\mingw32\bin"))) { + # write-host "Adding $gitRoot\mingw32\bin to the path" + $newPath = "$newPath;$gitRoot\mingw32\bin" + } elseif ((test-path "$gitRoot\mingw64\bin") -and -not ($env:path -match [regex]::Escape("$gitRoot\mingw64\bin"))) { + # write-host "Adding $gitRoot\mingw64\bin to the path" + $newPath = "$newPath;$gitRoot\mingw64\bin" + } + + # Add "$gitRoot\usr\bin" to the path if exists and not done already + if ((test-path "$gitRoot\usr\bin") -and -not ($env:path -match [regex]::Escape("$gitRoot\usr\bin"))) { + # write-host "Adding $gitRoot\usr\bin to the path" + $newPath = "$newPath;$gitRoot\usr\bin" + } + } + + return $newPath + } + + return $env:path } function Import-Git(){ @@ -32,7 +131,7 @@ function Import-Git(){ return $true } -function checkGit($Path) { +function checkGit($Path) { if (Test-Path -Path (Join-Path $Path '.git') ) { if($env:gitLoaded -eq 'false') { $env:gitLoaded = Import-Git