From ca068f569675b8bc4d8e68210476e584fb417f92 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 17:22:50 +0000 Subject: [PATCH 01/12] Initial plan From 96842bf09e78e9f94636074c086160dcfec358e2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 17:29:08 +0000 Subject: [PATCH 02/12] Refactor Cmder.ps1 with PowerShell naming conventions and optimizations Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/profile.ps1 | 12 +- vendor/psmodules/Cmder.ps1 | 259 ++++++++++++++++++++----------------- 2 files changed, 145 insertions(+), 126 deletions(-) diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index c77e81a..99426e4 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -44,18 +44,18 @@ if (-not $moduleInstallerAvailable -and -not $env:PSModulePath.Contains($CmderMo } # Read vendored Git Version -$gitVersionVendor = (readGitVersion -gitPath "$ENV:CMDER_ROOT\vendor\git-for-windows\cmd") +$gitVersionVendor = Get-GitVersion -GitPath "$ENV:CMDER_ROOT\vendor\git-for-windows\cmd" Write-Debug "GIT VENDOR: ${gitVersionVendor}" # Get user installed Git version(s) if found, and compare them with vendored version. foreach ($git in (Get-Command -ErrorAction SilentlyContinue 'git')) { Write-Debug "GIT PATH: {$git.Path}" $gitDir = Split-Path -Path $git.Path - $gitDir = isGitShim -gitPath $gitDir - $gitVersionUser = (readGitVersion -gitPath $gitDir) + $gitDir = Get-GitShimPath -GitPath $gitDir + $gitVersionUser = Get-GitVersion -GitPath $gitDir Write-Debug "GIT USER: ${gitVersionUser}" - $useGitVersion = compare_git_versions -userVersion $gitVersionUser -vendorVersion $gitVersionVendor + $useGitVersion = Compare-GitVersion -UserVersion $gitVersionUser -VendorVersion $gitVersionVendor Write-Debug "Using Git Version: ${useGitVersion}" # Use user installed Git @@ -85,7 +85,7 @@ Write-Debug "GIT_INSTALL_ROOT: ${ENV:GIT_INSTALL_ROOT}" Write-Debug "GIT_INSTALL_TYPE: ${ENV:GIT_INSTALL_TYPE}" if ($null -ne $ENV:GIT_INSTALL_ROOT) { - $env:Path = Configure-Git -gitRoot "$ENV:GIT_INSTALL_ROOT" -gitType $ENV:GIT_INSTALL_TYPE -gitPathUser $gitPathUser + $env:Path = Set-GitPath -GitRoot "$ENV:GIT_INSTALL_ROOT" -GitType $ENV:GIT_INSTALL_TYPE -GitPathUser $gitPathUser } # Create 'vi' alias for 'vim' if vim is available @@ -131,7 +131,7 @@ $env:gitLoaded = $null $Host.UI.RawUI.ForegroundColor = "White" Microsoft.PowerShell.Utility\Write-Host "PS " -NoNewline -ForegroundColor $color Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green - checkGit($pwd.ProviderPath) + Show-GitStatus -Path $pwd.ProviderPath Microsoft.PowerShell.Utility\Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray" } diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index a72da65..fb703a5 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -1,178 +1,197 @@ -function readGitVersion($gitPath) { - $gitExecutable = "${gitPath}\git.exe" +function Get-GitVersion { + param( + [Parameter(Mandatory = $true)] + [string]$GitPath + ) - if (-not (Test-Path "$gitExecutable")) { + $gitExecutable = Join-Path $GitPath "git.exe" + + if (-not (Test-Path $gitExecutable)) { return $null } - $gitVersion = (cmd /c "${gitExecutable}" --version) + $gitVersion = & $gitExecutable --version 2>$null - if ($gitVersion -match 'git version') { - ($trash1, $trash2, $gitVersion) = $gitVersion.split(' ', 3) - } else { - pause - return $null + if ($gitVersion -match 'git version\s+(\S+)') { + return $Matches[1] } - return $gitVersion.toString() + return $null } -function isGitShim($gitPath) { - # Check if there is a shim file - if yes, read the actual executable path - # See: github.com/ScoopInstaller/Shim +function Get-GitShimPath { + param( + [Parameter(Mandatory = $true)] + [string]$GitPath + ) - if (Test-Path "${gitPath}\git.shim") { - $shim = (get-content "${gitPath}\git.shim") - ($trash, $gitPath) = $shim.replace(' ', '').split('=') - - $gitPath = $gitPath.replace('\git.exe', '') + $shimFile = Join-Path $GitPath "git.shim" + if (Test-Path $shimFile) { + $shimContent = Get-Content $shimFile -Raw + if ($shimContent -match 'path\s*=\s*(.+)') { + $GitPath = $Matches[1].Trim().Replace('\git.exe', '') + } } - return $gitPath.toString() + return $GitPath } -function compareVersions($userVersion, $vendorVersion) { - if ($null -ne $userVersion) { - ($userMajor, $userMinor, $userPatch, $userBuild) = $userVersion.split('.', 4) - } else { - return -1 +function Compare-Version { + param( + [Parameter(Mandatory = $false)] + [AllowNull()] + [string]$UserVersion, + [Parameter(Mandatory = $false)] + [AllowNull()] + [string]$VendorVersion + ) + + if ($null -eq $UserVersion) { return -1 } + if ($null -eq $VendorVersion) { return 1 } + + try { + $userVer = [version]$UserVersion + $vendorVer = [version]$VendorVersion + return $userVer.CompareTo($vendorVer) + } catch { + # Fallback to string comparison if version parsing fails + return [string]::Compare($UserVersion, $VendorVersion) } - - if ($null -ne $vendorVersion) { - ($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 +function Compare-GitVersion { + param( + [Parameter(Mandatory = $false)] + [AllowNull()] + [string]$UserVersion, + [Parameter(Mandatory = $false)] + [AllowNull()] + [string]$VendorVersion + ) - Write-Debug "Compare Versions Result: ${result}" + $result = Compare-Version -UserVersion $UserVersion -VendorVersion $VendorVersion + + Write-Debug "Compare Versions Result: $result" if ($result -ge 0) { - return $userVersion - } - else { - return $vendorVersion + return $UserVersion } + return $VendorVersion } -function Configure-Git($gitRoot, $gitType, $gitPathUser) { - # Proposed Behavior +function Set-GitPath { + param( + [Parameter(Mandatory = $true)] + [string]$GitRoot, + [Parameter(Mandatory = $true)] + [string]$GitType, + [Parameter(Mandatory = $false)] + [string]$GitPathUser + ) - # Modify the path if we are using VENDORED Git, do nothing if using USER Git. - # If User Git is installed but is 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 (($null -ne $gitPathUser) -and ($gitPathUser -ne '')) { - Write-Verbose "Cmder 'profile.ps1': Replacing older user Git path '$gitPathUser' with newer vendored Git path '$gitRoot' in the system path..." + if ($GitType -ne 'VENDOR') { + return $env:Path + } - $newPath = ($env:path -ireplace [regex]::Escape($gitPathUser), $gitRoot) + $newPath = $env:Path + + # Replace user Git path with vendored Git if user path exists + if ($GitPathUser) { + Write-Verbose "Cmder 'profile.ps1': Replacing older user Git path '$GitPathUser' with newer vendored Git path '$GitRoot' in the system path..." + $newPath = $newPath -ireplace [regex]::Escape($GitPathUser), $GitRoot + } else { + # Add Git cmd directory + $gitCmd = Join-Path $GitRoot "cmd" + if (-not ($newPath -match [regex]::Escape($gitCmd))) { + Write-Debug "Adding $gitCmd to the path" + $newPath = "$gitCmd;$newPath" } - else { - if (-not ($env:Path -match [regex]::Escape("$gitRoot\cmd"))) { - Write-Debug "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-Debug "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-Debug "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-Debug "Adding $gitRoot\usr\bin to the path" - $newPath = "$newPath;$gitRoot\usr\bin" + # Add mingw bin directory + foreach ($mingw in @('mingw64', 'mingw32')) { + $mingwBin = Join-Path $GitRoot "$mingw\bin" + if ((Test-Path $mingwBin) -and -not ($newPath -match [regex]::Escape($mingwBin))) { + Write-Debug "Adding $mingwBin to the path" + $newPath = "$newPath;$mingwBin" + break } } - return $newPath + # Add usr bin directory + $usrBin = Join-Path $GitRoot "usr\bin" + if ((Test-Path $usrBin) -and -not ($newPath -match [regex]::Escape($usrBin))) { + Write-Debug "Adding $usrBin to the path" + $newPath = "$newPath;$usrBin" + } } - return $env:path + return $newPath } -function Import-Git() { - $GitModule = Get-Module -Name Posh-Git -ListAvailable - if ($GitModule | Select-Object version | Where-Object version -le ([version]"0.6.1.20160330")) { - Import-Module Posh-Git > $null - } - if ($GitModule | Select-Object version | Where-Object version -ge ([version]"1.0.0")) { - Import-Module Posh-Git > $null - $GitPromptSettings.AnsiConsole = $false - } - if (-not $GitModule) { - Write-Host -NoNewline "`r`n" +function Import-Git { + $gitModule = Get-Module -Name Posh-Git -ListAvailable + + if (-not $gitModule) { + Microsoft.PowerShell.Utility\Write-Host -NoNewline "`r`n" Write-Warning "Missing git support, install posh-git with 'Install-Module posh-git' and restart Cmder." - Write-Host -NoNewline "`r$([char]0x1B)[A" + Microsoft.PowerShell.Utility\Write-Host -NoNewline "`r$([char]0x1B)[A" return $false } - # Make sure we only run once by always returning true + + Import-Module Posh-Git -ErrorAction SilentlyContinue | Out-Null + + if (($gitModule.Version -ge [version]"1.0.0") -and (Get-Variable -Name GitPromptSettings -ErrorAction SilentlyContinue)) { + $GitPromptSettings.AnsiConsole = $false + } + return $true } -function checkGit($Path) { +function Show-GitStatus { + param( + [Parameter(Mandatory = $true)] + [string]$Path + ) + if (-not (Get-Command git -ErrorAction SilentlyContinue)) { return } - if (-not (Test-Path -Path (Join-Path $Path '.git'))) { - $SplitPath = Split-Path $path - if ($SplitPath) { checkGit($SplitPath) } + + $gitDir = Join-Path $Path '.git' + if (-not (Test-Path $gitDir)) { + $parentPath = Split-Path $Path + if ($parentPath) { + Show-GitStatus -Path $parentPath + } return } - if (getGitStatusSetting -eq $true) { + + if (Get-GitStatusSetting) { if ($null -eq $env:gitLoaded) { $env:gitLoaded = Import-Git } if ($env:gitLoaded -eq $true) { Write-VcsStatus } - } - else { - $headContent = Get-Content (Join-Path $Path '.git/HEAD') - if ($headContent -like "ref: refs/heads/*") { - $branchName = $headContent.Substring(16) + } else { + $headFile = Join-Path $gitDir 'HEAD' + if (Test-Path $headFile) { + $headContent = Get-Content $headFile -Raw + if ($headContent -match 'ref: refs/heads/(.+)') { + $branchName = $Matches[1].Trim() + } else { + $shortHash = $headContent.Substring(0, [Math]::Min(7, $headContent.Length)) + $branchName = "HEAD detached at $shortHash" + } + Microsoft.PowerShell.Utility\Write-Host " [$branchName]" -NoNewline -ForegroundColor White } - else { - $branchName = "HEAD detached at $($headContent.Substring(0, 7))" - } - Write-Host " [$branchName]" -NoNewline -ForegroundColor White } } -function getGitStatusSetting() { - $gitStatus = (git --no-pager config -l) | Out-String +function Get-GitStatusSetting { + $gitConfig = git --no-pager config -l 2>$null | Out-String - foreach ($line in $($gitStatus -split "`r`n")) { - if (($line -match 'cmder.status=false') -or ($line -match 'cmder.psstatus=false')) { - return $false - } + if ($gitConfig -match 'cmder\.(ps)?status=false') { + return $false } return $true From 7df73096d6a2a6b6674d5455af6331e62548ce81 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 18:38:59 +0000 Subject: [PATCH 03/12] Fix regex to match whole lines only in Get-GitStatusSetting Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/psmodules/Cmder.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index fb703a5..548c324 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -190,7 +190,7 @@ function Show-GitStatus { function Get-GitStatusSetting { $gitConfig = git --no-pager config -l 2>$null | Out-String - if ($gitConfig -match 'cmder\.(ps)?status=false') { + if ($gitConfig -match '(?m)^cmder\.(ps)?status=false') { return $false } From bc970e7f78a6f56806704c1469ca9a8cfd7642ff Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 19:00:56 +0000 Subject: [PATCH 04/12] Add end-of-line anchor and explanatory comment to Get-GitStatusSetting regex Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/psmodules/Cmder.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 548c324..18075e0 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -190,7 +190,10 @@ function Show-GitStatus { function Get-GitStatusSetting { $gitConfig = git --no-pager config -l 2>$null | Out-String - if ($gitConfig -match '(?m)^cmder\.(ps)?status=false') { + # Check if git status display is disabled via config + # Matches: cmder.status=false or cmder.psstatus=false (PowerShell-specific) + # Anchored to match complete lines only to avoid false positives + if ($gitConfig -match '(?m)^cmder\.(ps)?status=false$') { return $false } From 9b64482f37c04e626072ff5fb36f6587b01dd07d Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sat, 8 Nov 2025 23:50:52 +0330 Subject: [PATCH 05/12] add the same message from lib_git.cmd in PS1 script --- vendor/psmodules/Cmder.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 18075e0..8d7790a 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -16,6 +16,10 @@ function Get-GitVersion { return $Matches[1] } + Write-Debug "Git executable path: $gitExecutable" + Write-Error "'git --version' returned an improper version string!" + Write-Error "Unable to determine Git version from output: $gitVersion" + return $null } From 60045d8c4fb261528301d555d78c3eb2c1a92074 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sat, 8 Nov 2025 23:52:45 +0330 Subject: [PATCH 06/12] simplification --- vendor/psmodules/Cmder.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 8d7790a..aff6425 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -196,7 +196,6 @@ function Get-GitStatusSetting { # Check if git status display is disabled via config # Matches: cmder.status=false or cmder.psstatus=false (PowerShell-specific) - # Anchored to match complete lines only to avoid false positives if ($gitConfig -match '(?m)^cmder\.(ps)?status=false$') { return $false } From c039d977c2b484fc921b266b76e120c4afd3dc12 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 20:52:58 +0000 Subject: [PATCH 07/12] Skip mingw64 check on 32-bit systems for better performance Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/psmodules/Cmder.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index aff6425..1564a3b 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -111,7 +111,11 @@ function Set-GitPath { } # Add mingw bin directory - foreach ($mingw in @('mingw64', 'mingw32')) { + # Prefer mingw64 on 64-bit systems, mingw32 on 32-bit systems + $is64Bit = [Environment]::Is64BitOperatingSystem + $mingwDirs = if ($is64Bit) { @('mingw64', 'mingw32') } else { @('mingw32') } + + foreach ($mingw in $mingwDirs) { $mingwBin = Join-Path $GitRoot "$mingw\bin" if ((Test-Path $mingwBin) -and -not ($newPath -match [regex]::Escape($mingwBin))) { Write-Debug "Adding $mingwBin to the path" From f6adae5fb27dd44bb5ce70f5dc1fe2b17f34c95a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 21:00:30 +0000 Subject: [PATCH 08/12] Fix version comparison to handle Git version strings correctly Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/psmodules/Cmder.ps1 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 1564a3b..0eeed5c 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -53,14 +53,22 @@ function Compare-Version { if ($null -eq $UserVersion) { return -1 } if ($null -eq $VendorVersion) { return 1 } - try { - $userVer = [version]$UserVersion - $vendorVer = [version]$VendorVersion - return $userVer.CompareTo($vendorVer) - } catch { - # Fallback to string comparison if version parsing fails - return [string]::Compare($UserVersion, $VendorVersion) + # Extract all numeric parts from version strings (e.g., "2.49.0.windows.1" -> 2, 49, 0, 1) + # This handles Git version strings like "2.49.0.windows.1" correctly + $userParts = [regex]::Matches($UserVersion, '\d+') | ForEach-Object { [int]$_.Value } + $vendorParts = [regex]::Matches($VendorVersion, '\d+') | ForEach-Object { [int]$_.Value } + + # Compare each numeric part sequentially + $maxLength = [Math]::Max($userParts.Count, $vendorParts.Count) + for ($i = 0; $i -lt $maxLength; $i++) { + $userPart = if ($i -lt $userParts.Count) { $userParts[$i] } else { 0 } + $vendorPart = if ($i -lt $vendorParts.Count) { $vendorParts[$i] } else { 0 } + + if ($userPart -gt $vendorPart) { return 1 } + if ($userPart -lt $vendorPart) { return -1 } } + + return 0 } function Compare-GitVersion { From 456ddcc59ed94adfe4e1ea1ba80347648f680eef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 21:11:36 +0000 Subject: [PATCH 09/12] Improve version comparison using dot-notation segment comparison Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/psmodules/Cmder.ps1 | 47 ++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 0eeed5c..45e3b5b 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -50,22 +50,45 @@ function Compare-Version { [string]$VendorVersion ) - if ($null -eq $UserVersion) { return -1 } - if ($null -eq $VendorVersion) { return 1 } + if ([string]::IsNullOrEmpty($UserVersion)) { return -1 } + if ([string]::IsNullOrEmpty($VendorVersion)) { return 1 } - # Extract all numeric parts from version strings (e.g., "2.49.0.windows.1" -> 2, 49, 0, 1) - # This handles Git version strings like "2.49.0.windows.1" correctly - $userParts = [regex]::Matches($UserVersion, '\d+') | ForEach-Object { [int]$_.Value } - $vendorParts = [regex]::Matches($VendorVersion, '\d+') | ForEach-Object { [int]$_.Value } + # Split version strings by dots to compare segment by segment + # For "2.49.0.windows.1", we get: ["2", "49", "0", "windows", "1"] + $userParts = $UserVersion -split '\.' + $vendorParts = $VendorVersion -split '\.' - # Compare each numeric part sequentially $maxLength = [Math]::Max($userParts.Count, $vendorParts.Count) - for ($i = 0; $i -lt $maxLength; $i++) { - $userPart = if ($i -lt $userParts.Count) { $userParts[$i] } else { 0 } - $vendorPart = if ($i -lt $vendorParts.Count) { $vendorParts[$i] } else { 0 } - if ($userPart -gt $vendorPart) { return 1 } - if ($userPart -lt $vendorPart) { return -1 } + for ($i = 0; $i -lt $maxLength; $i++) { + $userPart = if ($i -lt $userParts.Count) { $userParts[$i] } else { '' } + $vendorPart = if ($i -lt $vendorParts.Count) { $vendorParts[$i] } else { '' } + + # Check if both parts are purely numeric + $userIsNumeric = $userPart -match '^\d+$' + $vendorIsNumeric = $vendorPart -match '^\d+$' + + if ($userIsNumeric -and $vendorIsNumeric) { + # Both numeric: compare as integers (so 49 > 5, not lexicographic) + $userNum = [int]$userPart + $vendorNum = [int]$vendorPart + + if ($userNum -gt $vendorNum) { return 1 } + if ($userNum -lt $vendorNum) { return -1 } + } + elseif ($userIsNumeric -and -not $vendorIsNumeric) { + # Numeric segment comes before text segment (e.g., "2.0" < "2.0.rc1") + return -1 + } + elseif (-not $userIsNumeric -and $vendorIsNumeric) { + # Text segment comes after numeric segment + return 1 + } + else { + # Both are text: use case-insensitive lexicographic comparison + $cmp = [string]::Compare($userPart, $vendorPart, $true) + if ($cmp -ne 0) { return [Math]::Sign($cmp) } + } } return 0 From a1def7195e8050d0f964f292d51c695e0e07dbef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 21:24:18 +0000 Subject: [PATCH 10/12] Restore posh-git support for all versions in Import-Git Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/psmodules/Cmder.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 45e3b5b..309edde 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -176,8 +176,10 @@ function Import-Git { return $false } + # Import posh-git module (works for all versions) Import-Module Posh-Git -ErrorAction SilentlyContinue | Out-Null + # Apply version-specific settings for posh-git 1.0.0+ if (($gitModule.Version -ge [version]"1.0.0") -and (Get-Variable -Name GitPromptSettings -ErrorAction SilentlyContinue)) { $GitPromptSettings.AnsiConsole = $false } From fc24040e5ea1a07b4c49d29ae8ec1ea2c09a5c38 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sun, 9 Nov 2025 01:14:28 +0330 Subject: [PATCH 11/12] adjust comments --- vendor/psmodules/Cmder.ps1 | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 309edde..0c78b6e 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -10,6 +10,7 @@ function Get-GitVersion { return $null } + # Execute 'git --version' and capture output $gitVersion = & $gitExecutable --version 2>$null if ($gitVersion -match 'git version\s+(\S+)') { @@ -28,11 +29,13 @@ function Get-GitShimPath { [Parameter(Mandatory = $true)] [string]$GitPath ) + # Check if there is a shim file - if yes, read the actual executable path + # See: github.com/ScoopInstaller/Shim $shimFile = Join-Path $GitPath "git.shim" if (Test-Path $shimFile) { $shimContent = Get-Content $shimFile -Raw - if ($shimContent -match 'path\s*=\s*(.+)') { + if ($shimContent -match '^\s*path\s*=\s*(.+)\s*$') { $GitPath = $Matches[1].Trim().Replace('\git.exe', '') } } @@ -123,6 +126,13 @@ function Set-GitPath { [string]$GitPathUser ) + # Proposed Behavior + + # Modify the path if we are using VENDORED Git, do nothing if using USER Git. + # If User Git is installed but is 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 -ne 'VENDOR') { return $env:Path } @@ -134,19 +144,24 @@ function Set-GitPath { Write-Verbose "Cmder 'profile.ps1': Replacing older user Git path '$GitPathUser' with newer vendored Git path '$GitRoot' in the system path..." $newPath = $newPath -ireplace [regex]::Escape($GitPathUser), $GitRoot } else { - # Add Git cmd directory + # Add Git cmd directory to the path $gitCmd = Join-Path $GitRoot "cmd" if (-not ($newPath -match [regex]::Escape($gitCmd))) { Write-Debug "Adding $gitCmd to the path" $newPath = "$gitCmd;$newPath" } +<<<<<<< HEAD + # Add mingw[32|64]\bin directories to the path, if they exist and not already present + foreach ($mingw in @('mingw64', 'mingw32')) { +======= # Add mingw bin directory # Prefer mingw64 on 64-bit systems, mingw32 on 32-bit systems $is64Bit = [Environment]::Is64BitOperatingSystem $mingwDirs = if ($is64Bit) { @('mingw64', 'mingw32') } else { @('mingw32') } foreach ($mingw in $mingwDirs) { +>>>>>>> a1def7195e8050d0f964f292d51c695e0e07dbef $mingwBin = Join-Path $GitRoot "$mingw\bin" if ((Test-Path $mingwBin) -and -not ($newPath -match [regex]::Escape($mingwBin))) { Write-Debug "Adding $mingwBin to the path" @@ -155,7 +170,7 @@ function Set-GitPath { } } - # Add usr bin directory + # Add usr\bin directory to the path $usrBin = Join-Path $GitRoot "usr\bin" if ((Test-Path $usrBin) -and -not ($newPath -match [regex]::Escape($usrBin))) { Write-Debug "Adding $usrBin to the path" From 697c122faf88791f134b9538671862820e92040e Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sun, 9 Nov 2025 02:48:02 +0330 Subject: [PATCH 12/12] adjust comments --- vendor/psmodules/Cmder.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 0c78b6e..6de808e 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -151,17 +151,12 @@ function Set-GitPath { $newPath = "$gitCmd;$newPath" } -<<<<<<< HEAD # Add mingw[32|64]\bin directories to the path, if they exist and not already present - foreach ($mingw in @('mingw64', 'mingw32')) { -======= - # Add mingw bin directory # Prefer mingw64 on 64-bit systems, mingw32 on 32-bit systems $is64Bit = [Environment]::Is64BitOperatingSystem $mingwDirs = if ($is64Bit) { @('mingw64', 'mingw32') } else { @('mingw32') } foreach ($mingw in $mingwDirs) { ->>>>>>> a1def7195e8050d0f964f292d51c695e0e07dbef $mingwBin = Join-Path $GitRoot "$mingw\bin" if ((Test-Path $mingwBin) -and -not ($newPath -match [regex]::Escape($mingwBin))) { Write-Debug "Adding $mingwBin to the path"