From b959f8143e9f14c2f79f7c9b730fc2af407608d2 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 04:54:49 +0330 Subject: [PATCH 01/17] fix(legacy): bound launcher paths and validate option values Backport the launcher safety checks from current Cmder without importing Windows Terminal or changing legacy launch behavior. Exercise the production source on Win32 and x64 with malformed arguments and boundary paths. --- launcher/src/CmderLauncher.cpp | 78 ++++++-- launcher/tests/.gitignore | 2 + launcher/tests/CmderLauncherTests.cpp | 211 ++++++++++++++++++++++ launcher/tests/CmderLauncherTests.vcxproj | 44 +++++ 4 files changed, 316 insertions(+), 19 deletions(-) create mode 100644 launcher/tests/.gitignore create mode 100644 launcher/tests/CmderLauncherTests.cpp create mode 100644 launcher/tests/CmderLauncherTests.vcxproj diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index b4609f169..20149be17 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -82,6 +82,26 @@ void ShowErrorAndExit(DWORD ec, const wchar_t * func, int line) exit(1); } +template +void CopyPathOrExit(const std::wstring& source, wchar_t (&destination)[N]) +{ + if (source.length() >= N) + { + ShowErrorAndExit(ERROR_FILENAME_EXCED_RANGE, __WFUNCTION__, __LINE__); + } + wcscpy_s(destination, source.c_str()); +} + +template +void GetExecutablePath(wchar_t (&path)[N]) +{ + const DWORD length = GetModuleFileName(NULL, path, static_cast(N)); + if (length == 0 || length >= N) + { + ShowErrorAndExit(length == 0 ? GetLastError() : ERROR_FILENAME_EXCED_RANGE, __WFUNCTION__, __LINE__); + } +} + typedef struct _option { std::wstring name; @@ -148,10 +168,9 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr std::wstring cmderTitle = title; std::wstring cmderConEmuArgs = conemu_args; - std::copy(cfgRoot.begin(), cfgRoot.end(), userConfigDirPath); - userConfigDirPath[cfgRoot.length()] = 0; + CopyPathOrExit(cfgRoot, userConfigDirPath); - GetModuleFileName(NULL, exeDir, sizeof(exeDir)); + GetExecutablePath(exeDir); #if USE_TASKBAR_API wcscpy_s(appId, exeDir); @@ -161,8 +180,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr if (PathFileExists(iconPath.c_str())) { - std::copy(iconPath.begin(), iconPath.end(), icoPath); - icoPath[iconPath.length()] = 0; + CopyPathOrExit(iconPath, icoPath); } else { @@ -530,7 +548,7 @@ void RegisterShellMenu(std::wstring opt, wchar_t* keyBaseName, std::wstring cfgR wchar_t exePath[MAX_PATH] = { 0 }; wchar_t icoPath[MAX_PATH] = { 0 }; - GetModuleFileName(NULL, exePath, sizeof(exePath)); + GetExecutablePath(exePath); wchar_t commandStr[MAX_PATH + 20] = { 0 }; wchar_t baseCommandStr[MAX_PATH + 20] = { 0 }; @@ -546,8 +564,7 @@ void RegisterShellMenu(std::wstring opt, wchar_t* keyBaseName, std::wstring cfgR swprintf_s(commandStr, L"%s \"%%V\"", baseCommandStr); } else { - std::copy(cfgRoot.begin(), cfgRoot.end(), userConfigDirPath); - userConfigDirPath[cfgRoot.length()] = 0; + CopyPathOrExit(cfgRoot, userConfigDirPath); swprintf_s(commandStr, L"%s /c \"%s\" \"%%V\"", baseCommandStr, userConfigDirPath); } @@ -608,9 +625,18 @@ cmderOptions GetOption() { cmderOptions cmderOptions; LPWSTR *szArgList; - int argCount; + int argCount = 0; szArgList = CommandLineToArgvW(GetCommandLine(), &argCount); + if (szArgList == NULL) + { + cmderOptions.error = true; + return cmderOptions; + } + auto hasValue = [&](int index) { + return index + 1 < argCount && szArgList[index + 1][0] != L'\0' && + szArgList[index + 1][0] != L'/' && _wcsicmp(L"--", szArgList[index + 1]) != 0; + }; for (int i = 1; i < argCount; i++) { @@ -619,15 +645,20 @@ cmderOptions GetOption() if (cmderOptions.error == false) { if (_wcsicmp(L"/c", szArgList[i]) == 0) { - TCHAR userProfile[MAX_PATH]; + TCHAR userProfile[MAX_PATH] = { 0 }; const DWORD ret = GetEnvironmentVariable(L"USERPROFILE", userProfile, MAX_PATH); + if (ret == 0 || ret >= MAX_PATH) + { + cmderOptions.error = true; + continue; + } wchar_t cmderCfgRoot[MAX_PATH] = { 0 }; PathCombine(cmderCfgRoot, userProfile, L"cmder_cfg"); cmderOptions.cmderCfgRoot = cmderCfgRoot; - if (szArgList[i + 1] != NULL && szArgList[i + 1][0] != '/') + if (hasValue(i) && _wcsicmp(L"--", szArgList[i + 1]) != 0) { cmderOptions.cmderCfgRoot = szArgList[i + 1]; i++; @@ -635,6 +666,11 @@ cmderOptions GetOption() } else if (_wcsicmp(L"/start", szArgList[i]) == 0) { + if (!hasValue(i)) + { + cmderOptions.error = true; + continue; + } int len = wcslen(szArgList[i + 1]); if (wcscmp(&szArgList[i + 1][len - 1], L"\"") == 0) { @@ -653,16 +689,19 @@ cmderOptions GetOption() } else if (_wcsicmp(L"/task", szArgList[i]) == 0) { + if (!hasValue(i)) { cmderOptions.error = true; continue; } cmderOptions.cmderTask = szArgList[i + 1]; i++; } else if (_wcsicmp(L"/title", szArgList[i]) == 0) { + if (!hasValue(i)) { cmderOptions.error = true; continue; } cmderOptions.cmderTitle = szArgList[i + 1]; i++; } else if (_wcsicmp(L"/icon", szArgList[i]) == 0) { + if (!hasValue(i)) { cmderOptions.error = true; continue; } cmderOptions.cmderIcon = szArgList[i + 1]; i++; } @@ -678,7 +717,7 @@ cmderOptions GetOption() { cmderOptions.registerApp = true; cmderOptions.unRegisterApp = false; - if (szArgList[i + 1] != NULL) + if (i + 1 < argCount) { if (_wcsicmp(L"all", szArgList[i + 1]) == 0 || _wcsicmp(L"user", szArgList[i + 1]) == 0) { @@ -691,7 +730,7 @@ cmderOptions GetOption() { cmderOptions.unRegisterApp = true; cmderOptions.registerApp = false; - if (szArgList[i + 1] != NULL) + if (i + 1 < argCount) { if (_wcsicmp(L"all", szArgList[i + 1]) == 0 || _wcsicmp(L"user", szArgList[i + 1]) == 0) { @@ -703,6 +742,7 @@ cmderOptions GetOption() /* Used for passing arguments to conemu prog */ else if (_wcsicmp(L"/x", szArgList[i]) == 0) { + if (!hasValue(i)) { cmderOptions.error = true; continue; } cmderOptions.cmderConEmuArgs = szArgList[i + 1]; i++; } @@ -720,6 +760,7 @@ cmderOptions GetOption() else if (cmderOptions.cmderStart == L"") { int len = wcslen(szArgList[i]); + if (len == 0) { cmderOptions.error = true; continue; } if (wcscmp(&szArgList[i][len - 1], L"\"") == 0) { szArgList[i][len - 1] = '\0'; @@ -728,7 +769,6 @@ cmderOptions GetOption() if (PathFileExists(szArgList[i])) { cmderOptions.cmderStart = szArgList[i]; - i++; } else { @@ -769,7 +809,11 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, cmderOptions cmderOptions = GetOption(); - if (cmderOptions.registerApp == true) + if (cmderOptions.error == true) + { + return 1; + } + else if (cmderOptions.registerApp == true) { RegisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_PATH_BACKGROUND, cmderOptions.cmderCfgRoot, cmderOptions.cmderSingle); RegisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_PATH_LISTITEM, cmderOptions.cmderCfgRoot, cmderOptions.cmderSingle); @@ -783,10 +827,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UnregisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_DRIVE_PATH_BACKGROUND); UnregisterShellMenu(cmderOptions.cmderRegScope, SHELL_MENU_REGISTRY_DRIVE_PATH_LISTITEM); } - else if (cmderOptions.error == true) - { - return 1; - } else { StartCmder(cmderOptions.cmderStart, cmderOptions.cmderSingle, cmderOptions.cmderTask, cmderOptions.cmderTitle, cmderOptions.cmderIcon, cmderOptions.cmderCfgRoot, cmderOptions.cmderUserCfg, cmderOptions.cmderConEmuArgs); diff --git a/launcher/tests/.gitignore b/launcher/tests/.gitignore new file mode 100644 index 000000000..4ded7c4c7 --- /dev/null +++ b/launcher/tests/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/obj/ diff --git a/launcher/tests/CmderLauncherTests.cpp b/launcher/tests/CmderLauncherTests.cpp new file mode 100644 index 000000000..42b624e08 --- /dev/null +++ b/launcher/tests/CmderLauncherTests.cpp @@ -0,0 +1,211 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +// Exercise the production launcher without dialogs, shell launches, or registry +// writes. Only process input and the executable-path API are replaced. +struct LauncherExit { int code; }; +static std::wstring testCommandLine = L"Cmder.exe"; +static std::wstring testExecutable = L"C:\\Cmder\\Cmder.exe"; +static bool failModulePath = false; +static DWORD modulePathCapacity = 0; +static int helpDialogs = 0; +static int registryWrites = 0; +static int terminalLaunches = 0; +static WORD nativeArchitecture = PROCESSOR_ARCHITECTURE_AMD64; +static std::wstring lastTerminalPath; + +[[noreturn]] static void TestExit(int code) { throw LauncherExit{code}; } +static LPWSTR WINAPI TestGetCommandLineW() { return &testCommandLine[0]; } +static DWORD WINAPI TestGetModuleFileNameW(HMODULE, LPWSTR path, DWORD capacity) +{ + modulePathCapacity = capacity; + if (failModulePath) { + SetLastError(ERROR_ACCESS_DENIED); + return 0; + } + if (testExecutable.length() >= capacity) { + wcsncpy_s(path, capacity, testExecutable.c_str(), _TRUNCATE); + return capacity; + } + wcscpy_s(path, capacity, testExecutable.c_str()); + return static_cast(testExecutable.length()); +} +static int WINAPI TestMessageBoxW(HWND, LPCWSTR, LPCWSTR, UINT) { return IDOK; } +static HRESULT WINAPI TestTaskDialogIndirect(const TASKDIALOGCONFIG*, int*, int*, BOOL*) +{ + ++helpDialogs; + return S_OK; +} +static LSTATUS WINAPI TestRegCreateKeyExW(HKEY, LPCWSTR, DWORD, LPWSTR, DWORD, + REGSAM, const LPSECURITY_ATTRIBUTES, PHKEY, LPDWORD) +{ + ++registryWrites; + return ERROR_ACCESS_DENIED; +} +static BOOL WINAPI TestCreateProcessW(LPCWSTR application, LPWSTR, LPSECURITY_ATTRIBUTES, + LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION) +{ + ++terminalLaunches; + lastTerminalPath = application; + SetLastError(ERROR_FILE_NOT_FOUND); + return FALSE; +} +static void WINAPI TestGetNativeSystemInfo(LPSYSTEM_INFO info) +{ + ZeroMemory(info, sizeof(*info)); + info->wProcessorArchitecture = nativeArchitecture; +} + +#define exit TestExit +#define GetCommandLineW TestGetCommandLineW +#define GetModuleFileNameW TestGetModuleFileNameW +#define MessageBoxW TestMessageBoxW +#define TaskDialogIndirect TestTaskDialogIndirect +#define RegCreateKeyExW TestRegCreateKeyExW +#define CreateProcessW TestCreateProcessW +#define GetNativeSystemInfo TestGetNativeSystemInfo +#include "../src/CmderLauncher.cpp" +#undef exit +#undef GetCommandLineW +#undef GetModuleFileNameW +#undef MessageBoxW +#undef TaskDialogIndirect +#undef RegCreateKeyExW +#undef CreateProcessW +#undef GetNativeSystemInfo + +static void Check(bool condition, const char* message) +{ + if (!condition) { throw std::runtime_error(message); } +} + +template +static void ExpectControlledExit(F action) +{ + try { action(); } + catch (const LauncherExit& error) { + Check(error.code == 1, "Unexpected launcher error code"); + return; + } + throw std::runtime_error("Launcher accepted an invalid path"); +} + +static void TestPathBounds() +{ + wchar_t path[MAX_PATH] = {}; + const std::wstring longestPath(MAX_PATH - 1, L'a'); + CopyPathOrExit(longestPath, path); + Check(longestPath == path, "259-character copy failed"); + for (size_t length : {size_t(MAX_PATH), size_t(MAX_PATH + 1), size_t(4096)}) { + const std::wstring oversized(length, L'a'); + ExpectControlledExit([&]() { CopyPathOrExit(oversized, path); }); + Check(longestPath == path, "Rejected input changed the destination"); + ExpectControlledExit([&]() { StartCmder(L"", false, L"", L"", L"", oversized); }); + ExpectControlledExit([&]() { RegisterShellMenu(L"USER", const_cast(L"unused"), oversized, false); }); + } + + GetExecutablePath(path); + Check(modulePathCapacity == MAX_PATH, "Module API received bytes instead of characters"); + Check(testExecutable == path, "Executable path changed"); + testExecutable.assign(MAX_PATH - 1, L'a'); + GetExecutablePath(path); + Check(testExecutable == path, "259-character executable path failed"); + testExecutable.assign(MAX_PATH, L'a'); + ExpectControlledExit([&]() { GetExecutablePath(path); }); + testExecutable.assign(MAX_PATH + 1, L'a'); + ExpectControlledExit([&]() { GetExecutablePath(path); }); + testExecutable = L"C:\\Cmder\\Cmder.exe"; + failModulePath = true; + ExpectControlledExit([&]() { GetExecutablePath(path); }); + failModulePath = false; + Check(registryWrites == 0, "Rejected configuration path reached registry writes"); +} + +static cmderOptions Parse(const std::wstring& arguments) +{ + testCommandLine = L"Cmder.exe " + arguments; + return GetOption(); +} + +static void WriteFixture(const std::wstring& path, const std::string& content) +{ + HANDLE file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + Check(file != INVALID_HANDLE_VALUE, "Could not create fixture file"); + DWORD written = 0; + const BOOL result = WriteFile(file, content.data(), static_cast(content.length()), &written, NULL); + CloseHandle(file); + Check(result && written == content.length(), "Could not write fixture file"); +} + +static std::string ReadFixture(const std::wstring& path) +{ + HANDLE file = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + Check(file != INVALID_HANDLE_VALUE, "Could not open fixture file"); + char content[256] = {}; + DWORD read = 0; + const BOOL result = ReadFile(file, content, sizeof(content), &read, NULL); + CloseHandle(file); + Check(result != 0, "Could not read fixture file"); + return std::string(content, read); +} + +static void TestArgumentParsing() +{ + wchar_t temporaryPath[MAX_PATH] = {}; + wchar_t fixturePath[MAX_PATH] = {}; + Check(GetTempPathW(MAX_PATH, temporaryPath) != 0, "Could not get temporary path"); + Check(GetTempFileNameW(temporaryPath, L"cmd", 0, fixturePath) != 0, "Could not allocate fixture path"); + Check(DeleteFileW(fixturePath) != 0, "Could not prepare fixture directory"); + Check(CreateDirectoryW(fixturePath, NULL) != 0, "Could not create fixture directory"); + const std::wstring root(fixturePath); + + for (const wchar_t* arguments : {L"/start", L"/start \"\"", L"/task", L"/task \"\"", + L"/task --", L"/title", L"/title \"\"", L"/icon", L"/icon \"\"", L"/x", L"/x \"\"", L"\"\""}) { + const int dialogs = helpDialogs; + Check(Parse(arguments).error, "Malformed arguments did not produce an error"); + Check(helpDialogs == dialogs + 1, "Malformed arguments did not display help"); + } + auto options = Parse(L"\"" + root + L"\" /task Custom"); + Check(!options.error && options.cmderStart == root && options.cmderTask == L"Custom", + "A positional folder consumed the next switch"); + options = Parse(L"/start \"" + root + L"\" /task Custom"); + Check(!options.error && options.cmderStart == root && options.cmderTask == L"Custom", + "Explicit start folder or task changed"); + options = Parse(L"/c -- -new_console"); + Check(!options.error && !options.cmderCfgRoot.empty() && options.cmderConEmuArgs == L"-new_console", + "Optional configuration root consumed the argument separator"); + options = Parse(L"/task Custom /x \"-foo bar\" /single /m /title Custom /icon custom.ico"); + Check(!options.error && options.cmderTask == L"Custom" && options.cmderConEmuArgs == L"-foo bar" && + options.cmderSingle && !options.cmderUserCfg && options.cmderTitle == L"Custom" && options.cmderIcon == L"custom.ico", + "Legacy ConEmu arguments changed"); + Check(!Parse(L"/register USER").error && !Parse(L"/unregister ALL").error, + "Valid registration arguments changed"); + Parse(L"/register /start"); + Check(_tWinMain(NULL, NULL, NULL, 0) == 1 && registryWrites == 0, + "Invalid registration command reached registry writes"); + Parse(L"/unregister /icon"); + Check(_tWinMain(NULL, NULL, NULL, 0) == 1 && registryWrites == 0, + "Invalid unregister command reached registry writes"); + Check(terminalLaunches == 0, "Invalid arguments launched a terminal"); + Check(RemoveDirectoryW(root.c_str()) != 0, "Could not remove fixture directory"); +} + +int wmain() +{ + try { + TestPathBounds(); + TestArgumentParsing(); + std::cout << "Legacy launcher regression tests passed.\n"; + return 0; + } + catch (const std::exception& error) { + std::cerr << error.what() << '\n'; + return 1; + } +} \ No newline at end of file diff --git a/launcher/tests/CmderLauncherTests.vcxproj b/launcher/tests/CmderLauncherTests.vcxproj new file mode 100644 index 000000000..e703dd59c --- /dev/null +++ b/launcher/tests/CmderLauncherTests.vcxproj @@ -0,0 +1,44 @@ + + + + + Release + Win32 + + + Release + x64 + + + + {CCF7B995-F8CB-4CA2-96A5-58C431E72A51} + Win32Proj + 10.0 + + + + Application + v143 + Unicode + + + + $(ProjectDir)bin\$(Platform)\ + $(ProjectDir)obj\$(Platform)\ + + + + Level3 + true + MultiThreaded + + + Console + shell32.lib;advapi32.lib;user32.lib;%(AdditionalDependencies) + + + + + + + From dd0a81dee38d8ce12c99a408d8b0a8eff6f1a4f2 Mon Sep 17 00:00:00 2001 From: Kobi Hikri Date: Tue, 28 Jul 2026 18:56:22 +0300 Subject: [PATCH 02/17] ci: read the PR head ref from the environment instead of interpolating it into PowerShell (cherry picked from commit f4aceeed132bb944f543a5953f234f2c4f607136) --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1454b8898..bb8caff76 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,8 @@ jobs: - name: Summary - Repository checkout shell: pwsh + env: + HEAD_REF: ${{ github.head_ref }} run: | # Get Cmder version . scripts/utils.ps1 @@ -50,7 +52,7 @@ jobs: # Determine branch and PR information $refName = "${{ github.ref_name }}" - $headRef = "${{ github.head_ref }}" + $headRef = $env:HEAD_REF $eventName = "${{ github.event_name }}" $prNumber = $null $actualBranchName = $refName From f7dc8f8ccd4914c6a840222ca06e6e0057ad31ed Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 04:55:16 +0330 Subject: [PATCH 03/17] fix(legacy): restore historical TCC and TCCLE defaults Restore only the four defaults removed during the shell-helper refactor, matching 6dcc0fb and the prior implementation. Keep the legacy init.bat and its existing behavior intact. Add ten helper regression cases, including existing user overrides. --- scripts/test-shell-detection.ps1 | 65 ++++++++++++++++++++++++++++++++ vendor/lib/lib_base.cmd | 4 ++ 2 files changed, 69 insertions(+) create mode 100644 scripts/test-shell-detection.ps1 diff --git a/scripts/test-shell-detection.ps1 b/scripts/test-shell-detection.ps1 new file mode 100644 index 000000000..9c0503e09 --- /dev/null +++ b/scripts/test-shell-detection.ps1 @@ -0,0 +1,65 @@ +[CmdletBinding()] +param() + +$ErrorActionPreference = 'Stop' +$helper = Join-Path $PSScriptRoot '..\vendor\lib\lib_base.cmd' +$cmdExecutable = Join-Path ([Environment]::SystemDirectory) 'cmd.exe' + +# These exercise the batch helper under cmd.exe; they do not start a TCC shell. +$cases = @( + @{ Name = 'cmd defaults'; Shell = 'cmd'; Clink = ''; Aliases = ''; ExpectedClink = '1'; ExpectedAliases = '1' }, + @{ Name = 'cmd overrides'; Shell = 'cmd'; Clink = '0'; Aliases = '0'; ExpectedClink = '0'; ExpectedAliases = '0' }, + @{ Name = 'TCC defaults'; Shell = 'tcc'; Clink = ''; Aliases = ''; ExpectedClink = '0'; ExpectedAliases = '0' }, + @{ Name = 'TCCLE defaults'; Shell = 'tccle'; Clink = ''; Aliases = ''; ExpectedClink = '0'; ExpectedAliases = '0' }, + @{ Name = 'TCC mixed case'; Shell = 'TcC'; Clink = ''; Aliases = ''; ExpectedClink = '0'; ExpectedAliases = '0' }, + @{ Name = 'TCCLE mixed case'; Shell = 'TcClE'; Clink = ''; Aliases = ''; ExpectedClink = '0'; ExpectedAliases = '0' }, + @{ Name = 'TCC overrides'; Shell = 'tcc'; Clink = '2'; Aliases = '1'; ExpectedClink = '2'; ExpectedAliases = '1' }, + @{ Name = 'TCCLE overrides'; Shell = 'tccle'; Clink = '1'; Aliases = '1'; ExpectedClink = '1'; ExpectedAliases = '1' }, + @{ Name = 'TCC Clink override only'; Shell = 'tcc'; Clink = '2'; Aliases = ''; ExpectedClink = '2'; ExpectedAliases = '0' }, + @{ Name = 'TCCLE aliases override only'; Shell = 'tccle'; Clink = ''; Aliases = '1'; ExpectedClink = '0'; ExpectedAliases = '1' } +) + +foreach ($case in $cases) { + $startInfo = New-Object System.Diagnostics.ProcessStartInfo + $startInfo.FileName = $cmdExecutable + $startInfo.Arguments = '/d /v:off /c call "{0}" detect_comspec "C:\JPSoft\{1}.exe" & set CMDER_SHELL & set CMDER_CLINK & set CMDER_ALIASES' -f $helper, $case.Shell + $startInfo.UseShellExecute = $false + $startInfo.CreateNoWindow = $true + $startInfo.RedirectStandardOutput = $true + $startInfo.RedirectStandardError = $true + $startInfo.EnvironmentVariables['CMDER_CLINK'] = $case.Clink + $startInfo.EnvironmentVariables['CMDER_ALIASES'] = $case.Aliases + $startInfo.EnvironmentVariables.Remove('CMDER_SHELL') + + $process = New-Object System.Diagnostics.Process + $process.StartInfo = $startInfo + try { + $null = $process.Start() + $output = $process.StandardOutput.ReadToEnd() + $errors = $process.StandardError.ReadToEnd() + $process.WaitForExit() + if ($process.ExitCode -ne 0 -or $errors) { + throw "$($case.Name): helper failed (exit $($process.ExitCode)). $errors $output" + } + + $actual = @{} + foreach ($line in ($output -split '\r?\n')) { + if ($line -match '^(CMDER_(?:SHELL|CLINK|ALIASES))=(.*)$') { + $actual[$Matches[1]] = $Matches[2] + } + } + + if ($actual.CMDER_SHELL -cne $case.Shell -or + $actual.CMDER_CLINK -ne $case.ExpectedClink -or + $actual.CMDER_ALIASES -ne $case.ExpectedAliases) { + throw "$($case.Name): unexpected shell defaults. $output" + } + + Write-Host "Passed: $($case.Name)" + } + finally { + $process.Dispose() + } +} + +Write-Host "All $($cases.Count) shell detection cases passed. Real TCC/TCCLE testing is separate." diff --git a/vendor/lib/lib_base.cmd b/vendor/lib/lib_base.cmd index 39371c71e..438164048 100644 --- a/vendor/lib/lib_base.cmd +++ b/vendor/lib/lib_base.cmd @@ -85,9 +85,13 @@ exit /b set CMDER_SHELL=%~n1 if not defined CMDER_CLINK ( set CMDER_CLINK=1 + if /i "%CMDER_SHELL%" equ "tcc" set CMDER_CLINK=0 + if /i "%CMDER_SHELL%" equ "tccle" set CMDER_CLINK=0 ) if not defined CMDER_ALIASES ( set CMDER_ALIASES=1 + if /i "%CMDER_SHELL%" equ "tcc" set CMDER_ALIASES=0 + if /i "%CMDER_SHELL%" equ "tccle" set CMDER_ALIASES=0 ) exit /b From 8f99a55a986bbe33e36ce5998ffe9bf57a483610 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 04:55:50 +0330 Subject: [PATCH 04/17] ci(legacy): test and build the maintenance branch independently Target legacy/1.x PRs and v1 tags, run launcher and historical-shell regressions, and keep branch names out of inline PowerShell. Remove obsolete development synchronization and the cross-branch vendor updater from this maintenance lane. Kobi Hikri original build-summary fix is preserved in the preceding cherry-pick. --- .github/workflows/branches.yml | 79 ---- .github/workflows/build.yml | 8 +- .github/workflows/codeql.yml | 10 +- .github/workflows/tests.yml | 29 +- .github/workflows/vendor.yml | 709 --------------------------------- 5 files changed, 31 insertions(+), 804 deletions(-) delete mode 100644 .github/workflows/branches.yml delete mode 100644 .github/workflows/vendor.yml diff --git a/.github/workflows/branches.yml b/.github/workflows/branches.yml deleted file mode 100644 index 6c4428ec4..000000000 --- a/.github/workflows/branches.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: Update branches - -# Controls when the action will run. -on: - # Triggers the workflow on push events for the development branch - push: - branches: [ master ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -permissions: - actions: write - contents: write - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This job updates the development branch with the master branch - update-development: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it - - uses: actions/checkout@v7 - with: - fetch-depth: 0 # fetch all history for all branches and tags - - - name: Summary - Merge operation started - shell: bash - run: | - repo_url="${{ github.server_url }}/${{ github.repository }}" - source_branch_url="$repo_url/tree/master" - target_branch_url="$repo_url/tree/development" - actor_handle="${{ github.actor }}" - actor_label="@${actor_handle}" - actor_label="${actor_label//[/\\[}" - actor_label="${actor_label//]/\\]}" - actor_url="${{ github.server_url }}/${{ github.actor }}" - actor_avatar_url="${{ github.server_url }}/${{ github.actor }}.png?size=32" - commit_url="$repo_url/commit/${{ github.sha }}" - - echo "## ๐Ÿ”€ Update Branches - Workflow Summary" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Merge Operation" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY - echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY - echo "| Source Branch | [\`master\`]($source_branch_url) |" >> $GITHUB_STEP_SUMMARY - echo "| Target Branch | [\`development\`]($target_branch_url) |" >> $GITHUB_STEP_SUMMARY - echo "| Triggered by | [avatar/ $actor_label]($actor_url) |" >> $GITHUB_STEP_SUMMARY - echo "| Commit | [\`${{ github.sha }}\`]($commit_url) |" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - # Runs a single command using the runners shell - - name: Merge master into development - run: | - git config user.name "${{ github.actor }}" - git config user.email "${{ github.actor }}@users.noreply.github.com" - git checkout development - git merge --no-ff master - git push origin development - - - name: Summary - Merge completed - if: success() - shell: bash - run: | - repo_url="${{ github.server_url }}/${{ github.repository }}" - source_branch_url="$repo_url/tree/master" - target_branch_url="$repo_url/tree/development" - - echo "### โœ… Merge Successful" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "The [\`master\`]($source_branch_url) branch has been successfully merged into [\`development\`]($target_branch_url)." >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "**Merge type:** No fast-forward merge" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "> The [\`development\`]($target_branch_url) branch is now synchronized with the latest changes from [\`master\`]($source_branch_url)." >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb8caff76..0b71ac0bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,14 +4,14 @@ name: Build Cmder -# Controls when the action will run. Triggers the workflow on push or pull request events but only for the main branch +# Build the maintenance line independently of current Cmder development. on: push: - branches: [ "master" ] + branches: [ "legacy/1.x" ] tags: - - "v*" + - "v1.*" pull_request: - branches: [ "master", "development" ] + branches: [ "legacy/1.x" ] workflow_dispatch: #---------------------------------# diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index da3728cd6..da702c5e2 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -8,19 +8,17 @@ name: "CodeQL" on: push: - branches: [ "master", "development" ] + branches: [ "legacy/1.x" ] paths-ignore: - '**/*.md' - '**/*.txt' - - '.github/**' - '**/.gitignore' pull_request: # The branches below must be a subset of the branches above - branches: [ "master", "development" ] + branches: [ "legacy/1.x" ] paths-ignore: - '**/*.md' - '**/*.txt' - - '.github/**' - '**/.gitignore' schedule: - cron: '30 19 * * 0' @@ -49,9 +47,11 @@ jobs: - name: Summary - CodeQL analysis started shell: pwsh + env: + PR_HEAD_REF: ${{ github.head_ref }} run: | $refName = "${{ github.ref_name }}" - $headRef = "${{ github.head_ref }}" + $headRef = $env:PR_HEAD_REF $eventName = "${{ github.event_name }}" $prNumber = $null $actualBranchName = $refName diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f6b2e53f1..445de23bd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,21 +3,17 @@ name: Run Tests on: push: branches: - - master - - development + - legacy/1.x paths-ignore: - '**/*.md' - '**/*.txt' - - '.github/**' - '**/.gitignore' pull_request: branches: - - master - - development + - legacy/1.x paths-ignore: - '**/*.md' - '**/*.txt' - - '.github/**' - '**/.gitignore' defaults: @@ -50,15 +46,34 @@ jobs: shell: pwsh run: .\scripts\test-update.ps1 + - name: Test historical shell defaults + shell: pwsh + run: .\scripts\test-shell-detection.ps1 + + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v3 + + - name: Test legacy launcher production source + shell: pwsh + run: | + foreach ($platform in @('Win32', 'x64')) { + msbuild launcher\tests\CmderLauncherTests.vcxproj /p:Configuration=Release /p:Platform=$platform /verbosity:minimal + if ($LASTEXITCODE -ne 0) { throw "Launcher test build failed: $platform" } + & ".\launcher\tests\bin\$platform\CmderLauncherTests.exe" + if ($LASTEXITCODE -ne 0) { throw "Launcher tests failed: $platform" } + } + - name: Summary - Test execution started shell: pwsh + env: + PR_HEAD_REF: ${{ github.head_ref }} run: | # Get Cmder version . scripts/utils.ps1 $cmderVersion = Get-VersionStr $refName = "${{ github.ref_name }}" - $headRef = "${{ github.head_ref }}" + $headRef = $env:PR_HEAD_REF $eventName = "${{ github.event_name }}" $prNumber = $null $actualBranchName = $refName diff --git a/.github/workflows/vendor.yml b/.github/workflows/vendor.yml deleted file mode 100644 index 7fcbc1938..000000000 --- a/.github/workflows/vendor.yml +++ /dev/null @@ -1,709 +0,0 @@ -name: Update Vendor - -on: - workflow_dispatch: - schedule: - # At 13:37 UTC every day. - - cron: '37 13 * * *' - -concurrency: - group: vendor-update - cancel-in-progress: false - -env: - # Fork owners can opt in by setting this Actions repository variable to true. - AUTO_MERGE_MINOR_VENDOR_UPDATES: ${{ vars.AUTO_MERGE_MINOR_VENDOR_UPDATES || 'false' }} - -defaults: - run: - shell: pwsh - -permissions: - contents: read - -jobs: - vendor: - - runs-on: windows-latest - continue-on-error: false - timeout-minutes: 15 - permissions: - contents: write - pull-requests: write - - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - - name: Configure auto-merge policy - shell: pwsh - run: | - $rawValue = [string]$env:AUTO_MERGE_MINOR_VENDOR_UPDATES - $normalizedValue = $rawValue.Trim().ToLowerInvariant() - $enabled = $normalizedValue -in @('true', '1', 'yes', 'on') - - if ($enabled) { - Add-Content -Path $env:GITHUB_ENV -Value "AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED=True" - } else { - Add-Content -Path $env:GITHUB_ENV -Value "AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED=False" - } - - - name: Summary - Workflow started - shell: pwsh - run: | - $summary = @" - ## ๐Ÿ“ฆ Update Vendor - Workflow Summary - - Checking for vendor dependency updates... - - "@ - - $summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 - - - id: make-changes - name: Checking for updates - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - $currentVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json) - . .\scripts\update.ps1 -verbose - - # Export count of updated packages (update.ps1 is expected to set $count) - if (-not ($count)) { $count = 0 } - Set-GHVariable -Name COUNT_UPDATED -Value $count - - $newVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json) - # Source utility functions - . scripts/utils.ps1 - - function Add-GitHubEnvMultiline { - param( - [Parameter(Mandatory = $true)] - [string]$Name, - - [AllowEmptyString()] - [string]$Value - ) - - $delimiter = [System.Guid]::NewGuid().ToString('N') - Add-Content -Path $env:GITHUB_ENV -Value "$Name<<$delimiter" - Add-Content -Path $env:GITHUB_ENV -Value $Value - Add-Content -Path $env:GITHUB_ENV -Value $delimiter - } - - function Get-GitHubReleaseInfo { - param( - [Parameter(Mandatory = $true)] - [string]$DownloadUrl, - - [Parameter(Mandatory = $true)] - [string]$OldVersion, - - [Parameter(Mandatory = $true)] - [string]$NewVersion - ) - - $uri = [uri]$DownloadUrl - $segments = $uri.AbsolutePath.Trim('/').Split('/') - if ($uri.Host -ne 'github.com' -or $segments.Count -lt 2) { - return $null - } - - $owner = $segments[0] - $repo = $segments[1] - $repoPath = "$owner/$repo" - $repoUrl = "https://github.com/$repoPath" - $tagName = $null - - for ($i = 0; $i -lt $segments.Count; $i++) { - if ($segments[$i] -eq 'download' -and $i + 1 -lt $segments.Count) { - $tagName = $segments[$i + 1] - break - } - - if ($segments[$i] -eq 'archive' -and $i + 1 -lt $segments.Count) { - $tagName = $segments[$i + 1] -replace '\.tar\.gz$', '' -replace '\.zip$', '' - break - } - } - - if ([string]::IsNullOrWhiteSpace($tagName)) { - $tagName = "v$NewVersion" - } - - if ($tagName -match [regex]::Escape($NewVersion)) { - $oldTagName = $tagName -replace [regex]::Escape($NewVersion), $OldVersion - } else { - $oldTagName = "v$OldVersion" - } - - return @{ - RepoPath = $repoPath - RepoUrl = $repoUrl - ReleasesUrl = "$repoUrl/releases" - ReleaseUrl = "$repoUrl/releases/tag/$tagName" - CompareUrl = "$repoUrl/compare/$oldTagName...$tagName" - OldTagName = $oldTagName - TagName = $tagName - } - } - - function Invoke-GitHubApi { - param( - [Parameter(Mandatory = $true)] - [string]$Uri, - - [string]$Method = 'Get', - - [object]$Body - ) - - $headers = @{ - Accept = 'application/vnd.github+json' - 'X-GitHub-Api-Version' = '2022-11-28' - } - - if (-not [string]::IsNullOrWhiteSpace($env:GITHUB_TOKEN)) { - $headers.Authorization = "Bearer $env:GITHUB_TOKEN" - } - - $params = @{ - Uri = $Uri - Method = $Method - Headers = $headers - ErrorAction = 'Stop' - } - - if ($null -ne $Body) { - $params.Body = ($Body | ConvertTo-Json -Depth 8) - $params.ContentType = 'application/json' - } - - return Invoke-RestMethod @params - } - - function Get-ReadmeBuildStatusBadge { - param( - [Parameter(Mandatory = $true)] - [string]$RepoPath - ) - - try { - $readme = Invoke-GitHubApi -Uri "https://api.github.com/repos/$RepoPath/readme" - if ([string]::IsNullOrWhiteSpace($readme.content)) { - return 'โ€”' - } - - $bytes = [System.Convert]::FromBase64String(($readme.content -replace '\s', '')) - $markdown = [System.Text.Encoding]::UTF8.GetString($bytes) - $matches = [regex]::Matches($markdown, '\[!\[(?[^\]]*)\]\((?[^)]*)\)\]\((?[^)]*)\)') - - $bestBadge = $null - $bestScore = 0 - foreach ($match in $matches) { - $alt = $match.Groups['alt'].Value - $image = $match.Groups['image'].Value - $target = $match.Groups['target'].Value - $haystack = "$alt $image $target".ToLowerInvariant() - $score = 0 - - if ($alt -match '(?i)\b(build|status|ci|check)\b') { - $score += 8 - } - if ($image -match '(?i)(actions/workflows|/workflows/|dev\.azure\.com|badge\.svg)') { - $score += 6 - } - if ($target -match '(?i)(/actions|actions/workflows|dev\.azure\.com|/_build/)') { - $score += 4 - } - if ($haystack -match '(?i)(codecov|gitter|discord|covenant|visualstudiocode|open%20in)') { - $score -= 8 - } - - if ($score -gt $bestScore) { - $bestScore = $score - $bestBadge = $match.Value - } - } - - if ($bestScore -gt 0 -and -not [string]::IsNullOrWhiteSpace($bestBadge)) { - return $bestBadge - } - } catch { - Write-Verbose "Unable to fetch README build badge for ${RepoPath}: $($_.Exception.Message)" -Verbose - } - - return 'โ€”' - } - - function Get-ReleaseTitle { - param( - [Parameter(Mandatory = $true)] - [object]$Release - ) - - if (-not [string]::IsNullOrWhiteSpace($Release.name)) { - return $Release.name - } - - return $Release.tag_name - } - - function Get-ReleaseNotesForRange { - param( - [Parameter(Mandatory = $true)] - [hashtable]$ReleaseInfo, - - [Parameter(Mandatory = $true)] - [string]$ChangeType - ) - - $typeLabel = switch ($ChangeType) { - 'major' { 'Major changelog' } - 'minor' { 'Minor changelog' } - 'patch' { 'Patch changelog' } - default { 'Release changelog' } - } - - try { - $releases = @(Invoke-GitHubApi -Uri "https://api.github.com/repos/$($ReleaseInfo.RepoPath)/releases?per_page=100") - if ($releases.Count -gt 0) { - $newIndex = -1 - $oldIndex = -1 - for ($i = 0; $i -lt $releases.Count; $i++) { - if ($releases[$i].tag_name -eq $ReleaseInfo.TagName) { - $newIndex = $i - } - if ($releases[$i].tag_name -eq $ReleaseInfo.OldTagName) { - $oldIndex = $i - } - } - - if ($newIndex -ge 0) { - if ($oldIndex -gt $newIndex) { - $rangeReleases = @($releases[$newIndex..($oldIndex - 1)]) - } else { - $rangeReleases = @($releases[$newIndex]) - } - - $maxReleaseCount = 8 - $omittedReleaseCount = [Math]::Max(0, $rangeReleases.Count - $maxReleaseCount) - $rangeReleases = @($rangeReleases | Select-Object -First $maxReleaseCount) - - $notes = "**$typeLabel**`n" - foreach ($release in $rangeReleases) { - $title = Get-ReleaseTitle -Release $release - $releaseUrl = if (-not [string]::IsNullOrWhiteSpace($release.html_url)) { - $release.html_url - } else { - "$($ReleaseInfo.RepoUrl)/releases/tag/$($release.tag_name)" - } - - $notes += "`n### [$title]($releaseUrl)`n`n" - if ([string]::IsNullOrWhiteSpace($release.body)) { - $notes += "No release notes were published for this release.`n" - } else { - $releaseBody = $release.body.Trim() - if ($releaseBody.Length -gt 1200) { - $releaseBody = $releaseBody.Substring(0, 1200).TrimEnd() + "...`n`n_Release notes truncated; open the release link for the full text._" - } - - $notes += $releaseBody + "`n" - } - } - - if ($omittedReleaseCount -gt 0) { - $notes += "`n...and $omittedReleaseCount more releases. Open the compare link for the full range.`n" - } - - return $notes.Trim() - } - } - } catch { - Write-Verbose "Unable to fetch release range notes for $($ReleaseInfo.RepoPath) $($ReleaseInfo.OldTagName)...$($ReleaseInfo.TagName): $($_.Exception.Message)" -Verbose - } - - try { - $release = Invoke-GitHubApi -Uri "https://api.github.com/repos/$($ReleaseInfo.RepoPath)/releases/tags/$($ReleaseInfo.TagName)" - if (-not [string]::IsNullOrWhiteSpace($release.body)) { - $title = Get-ReleaseTitle -Release $release - return "**$typeLabel**`n`n### [$title]($($release.html_url))`n`n$($release.body.Trim())" - } - } catch { - Write-Verbose "Unable to fetch release notes for $($ReleaseInfo.RepoPath) $($ReleaseInfo.TagName): $($_.Exception.Message)" -Verbose - } - - return "No release notes were found for the requested release range." - } - - function ConvertTo-BlockQuote { - param( - [AllowEmptyString()] - [string]$Markdown, - - [int]$MaxLength = 2500 - ) - - $text = if ([string]::IsNullOrWhiteSpace($Markdown)) { - "No release notes were found." - } else { - $Markdown.Trim() - } - - if ($text.Length -gt $MaxLength) { - $text = $text.Substring(0, $MaxLength).TrimEnd() + "...`n`n_Release notes truncated; open the release links for the full text._" - } - - return (($text -split "`r?`n") | ForEach-Object { "> $_" }) -join "`n" - } - - function Get-VersionFromSources { - param( - [object[]]$Sources, - - [Parameter(Mandatory = $true)] - [string]$Name - ) - - return ($Sources | Where-Object { $_.name -eq $Name } | Select-Object -First 1).version - } - - $previousPrVersion = $null - $fetchPreviousPrBranchOutput = & git fetch origin update-vendor 2>&1 - if ($LASTEXITCODE -eq 0) { - $previousPrSourcesJson = & git show FETCH_HEAD:vendor/sources.json 2>$null - if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($previousPrSourcesJson)) { - $previousPrVersion = $previousPrSourcesJson | ConvertFrom-Json - } - } else { - Write-Verbose "No existing update-vendor branch was found to use as notification baseline: $fetchPreviousPrBranchOutput" -Verbose - } - - $notificationBaselineVersion = if ($null -ne $previousPrVersion) { $previousPrVersion } else { $currentVersion } - $listUpdated = "" - $updateMessage = "| Name | Old Version | New Version | Build Status |`n| :--- | :---: | :---: | :---: |`n" - $changelogSection = "" - $hasBreakingChanges = $false - $hasMinorOrMajorSinceLastPrUpdate = $false - $usedEmojis = [System.Collections.Generic.List[string]]::new() - $emojiDescriptions = [ordered]@{ - '๐Ÿ”ฅ' = 'Major version update.' - '๐Ÿš€' = 'Minor version update.' - 'โฌ†๏ธ' = 'Patch version update.' - '๐Ÿ”„' = 'Version change could not be classified.' - } - $singleDepName = "" - $singleDepOldVersion = "" - $singleDepNewVersion = "" - foreach ($s in $newVersion) { - $oldVersion = ($currentVersion | Where-Object {$_.name -eq $s.name}).version - if ($s.version -ne $oldVersion) { - $releaseInfo = Get-GitHubReleaseInfo -DownloadUrl $s.url -OldVersion $oldVersion -NewVersion $s.version - if ($null -ne $releaseInfo) { - $repoUrl = $releaseInfo.ReleasesUrl - $releaseUrl = $releaseInfo.ReleaseUrl - $statusBadge = Get-ReadmeBuildStatusBadge -RepoPath $releaseInfo.RepoPath - } else { - $repoUrl = ($repoUrl = $s.Url.Replace("/archive/", "/releases/")).Substring(0, $repoUrl.IndexOf("/releases/")) + "/releases" - $releaseUrl = $repoUrl - $statusBadge = "โ€”" - } - - # Store single dependency info for messages (only if this is the only update) - if ($count -eq 1) { - $singleDepName = $s.name - $singleDepOldVersion = $oldVersion - $singleDepNewVersion = $s.version - } - - # Determine change type and emoji using shared function - $result = Get-VersionChangeType -OldVersion $oldVersion -NewVersion $s.version - $changeType = $result.ChangeType - $emoji = $result.Emoji - $isMajor = $result.IsMajor - - if (-not $usedEmojis.Contains($emoji)) { - $usedEmojis.Add($emoji) - } - - if ($changeType -in @('major', 'downgrade', 'unknown')) { - $hasBreakingChanges = $true - } - - $previousPrUpdateVersion = Get-VersionFromSources -Sources $notificationBaselineVersion -Name $s.name - if (-not [string]::IsNullOrWhiteSpace($previousPrUpdateVersion) -and $previousPrUpdateVersion -ne $s.version) { - $notificationChangeType = Get-VersionChangeType -OldVersion $previousPrUpdateVersion -NewVersion $s.version - if ($notificationChangeType.ChangeType -in @('major', 'minor')) { - $hasMinorOrMajorSinceLastPrUpdate = $true - } - } - - if ($null -ne $releaseInfo) { - $releaseNotes = Get-ReleaseNotesForRange -ReleaseInfo $releaseInfo -ChangeType $changeType - $changelogSection += "
`n" - $changelogSection += "$($s.name)`n`n" - $changelogSection += "[Release notes]($($releaseInfo.ReleaseUrl)) ยท [Compare changes]($($releaseInfo.CompareUrl))`n`n" - $changelogSection += (ConvertTo-BlockQuote -Markdown $releaseNotes -MaxLength 6000) + "`n`n" - $changelogSection += "
`n`n" - } - - $listUpdated += "$($s.name) v$($s.version), " - $updateMessage += "| $emoji **[$($s.name)]($repoUrl)** | ``$oldVersion`` | **[``$($s.version)``]($releaseUrl)** | $statusBadge |`n" - } - } - - if ($count -eq 0) { return } - - Set-GHVariable -Name LIST_UPDATED -Value $listUpdated.Trim(', ') - # Set single dependency variables (they will only be used if COUNT_UPDATED is 1) - # Use safe fallback values in case variables weren't set (shouldn't happen but prevents errors) - if ([string]::IsNullOrEmpty($singleDepName) -and $count -eq 1) { - # This shouldn't happen, but if it does, log a warning - Write-Warning "Single dependency name not set despite count being 1" - $singleDepName = "unknown-package" - $singleDepOldVersion = "unknown" - $singleDepNewVersion = "unknown" - } elseif ([string]::IsNullOrEmpty($singleDepName)) { - # For multiple dependencies, set placeholder values (won't be used) - $singleDepName = "" - $singleDepOldVersion = "" - $singleDepNewVersion = "" - } - - Set-GHVariable -Name SINGLE_DEP_NAME -Value $singleDepName - Set-GHVariable -Name SINGLE_DEP_OLD_VERSION -Value $singleDepOldVersion - Set-GHVariable -Name SINGLE_DEP_NEW_VERSION -Value $singleDepNewVersion - - $emojiLegend = "**Legend**`n`n" - foreach ($usedEmoji in $usedEmojis) { - $emojiLegend += "$usedEmoji $($emojiDescriptions[$usedEmoji])`n" - } - - if ([string]::IsNullOrWhiteSpace($changelogSection)) { - $changelogSection = "" - } else { - $changelogSection = "`n### Release notes for updated vendors`n`n$changelogSection" - } - - $reviewTeam = "" - if ($hasMinorOrMajorSinceLastPrUpdate -and $env:GITHUB_REPOSITORY_OWNER -eq 'cmderdev') { - $reviewTeam = "trusted-contributors" - } - - Add-GitHubEnvMultiline -Name UPDATE_MESSAGE -Value $updateMessage - Add-GitHubEnvMultiline -Name CHANGELOG_SECTION -Value $changelogSection - Add-GitHubEnvMultiline -Name EMOJI_LEGEND -Value $emojiLegend - - if ($hasBreakingChanges) { - Add-Content -Path $env:GITHUB_ENV -Value "HAS_BREAKING_CHANGES=True" - } else { - Add-Content -Path $env:GITHUB_ENV -Value "HAS_BREAKING_CHANGES=False" - } - Add-Content -Path $env:GITHUB_ENV -Value "HAS_MINOR_OR_MAJOR_SINCE_LAST_PR_UPDATE=$hasMinorOrMajorSinceLastPrUpdate" - Add-Content -Path $env:GITHUB_ENV -Value "REVIEW_TEAM=$reviewTeam" - - - name: Summary - Update check results - shell: pwsh - run: | - $count = [int]$env:COUNT_UPDATED - - if ($count -eq 0) { - $summary = "### โœ… No Updates Available`n`nAll vendor dependencies are up to date! ๐ŸŽ‰`n" - } else { - $word = if ($count -eq 1) { 'dependency' } else { 'dependencies' } - $summary = "### ๐Ÿ”„ Updates Found`n`n" - if ($count -eq 1) { - $summary += '๐Ÿ“ฆ **' + $env:SINGLE_DEP_NAME + '** updated from `' + $env:SINGLE_DEP_OLD_VERSION + '` to `' + $env:SINGLE_DEP_NEW_VERSION + '`' + "`n" + "`n" - } else { - $summary += '๐Ÿ“ฆ **' + $count + '** vendor ' + $word + ' updated:' + "`n" + "`n" - } - } - - $summary += $env:UPDATE_MESSAGE + "`n" - - # Check if we can auto-merge (only minor/patch changes, opt-in only). - $hasBreaking = $env:HAS_BREAKING_CHANGES -eq 'True' - $autoMergeEnabled = $env:AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED -eq 'True' - if ($hasBreaking) { - $summary += '> โš ๏ธ **Note:** This update contains major version changes that may include breaking changes.' - } elseif ($autoMergeEnabled) { - $summary += '> โ„น๏ธ **Note:** This update only contains minor or patch changes, and auto-merge is enabled.' - } else { - $summary += '> โ„น๏ธ **Note:** This update only contains minor or patch changes. Auto-merge is disabled by default; set the `AUTO_MERGE_MINOR_VENDOR_UPDATES` Actions repository variable to `true` to opt in.' - } - - $summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 - - - name: Auto-merge minor updates - if: env.COUNT_UPDATED > 0 && env.HAS_BREAKING_CHANGES != 'True' && env.AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED == 'True' - shell: pwsh - run: | - function Get-PushFailureReason { - param( - [string[]]$PushOutput - ) - - $text = ($PushOutput -join "`n").Trim() - - if ([string]::IsNullOrWhiteSpace($text)) { - return "Git rejected the push to `master`." - } - - if ($text -match 'GH006: Protected branch' -or $text -match 'protected branch hook declined') { - return "GitHub rejected the push because `master` is protected and direct pushes are blocked." - } - - if ($text -match 'non-fast-forward|fetch first|failed to push some refs') { - return "The remote branch moved ahead of the local commit, so the push was rejected as non-fast-forward." - } - - if ($text -match 'not authorized|permission denied|write access') { - return "The workflow token does not have permission to push to `master`." - } - - return (($text -split "`r?`n" | Where-Object { $_ -match '^(remote:|! \[remote rejected\]|error:|To )' } | Select-Object -First 4) -join '; ') - } - - try { - echo "### ๐Ÿš€ Auto-merging Updates" >> $env:GITHUB_STEP_SUMMARY - echo "" >> $env:GITHUB_STEP_SUMMARY - echo "Attempting to automatically merge non-breaking changes to master..." >> $env:GITHUB_STEP_SUMMARY - - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - - # Commit the changes - git add vendor/sources.json - $commitResult = git commit -m "โฌ†๏ธ Update dependencies ($env:LIST_UPDATED)" - $commitSuccess = $LASTEXITCODE -eq 0 - - if ($commitSuccess) { - # Push directly to master - $pushOutput = & git push origin HEAD:master 2>&1 - $pushSuccess = $LASTEXITCODE -eq 0 - if (-not $pushSuccess) { - $pushFailureReason = Get-PushFailureReason -PushOutput @($pushOutput) - if (-not [string]::IsNullOrWhiteSpace($pushFailureReason)) { - Add-Content -Path $env:GITHUB_ENV -Value "AUTO_MERGE_FAILURE_REASON=$pushFailureReason" - } - $pushErrorMessage = if ([string]::IsNullOrWhiteSpace($pushFailureReason)) { - "Failed to push to master (exit code: $LASTEXITCODE)" - } else { - "Failed to push to master (exit code: $LASTEXITCODE): $pushFailureReason" - } - } - - if ($pushSuccess) { - echo "" >> $env:GITHUB_STEP_SUMMARY - echo "โœ… **Success!** Updates have been automatically merged to master." >> $env:GITHUB_STEP_SUMMARY - echo "" >> $env:GITHUB_STEP_SUMMARY - echo "**Updated dependencies:** $env:LIST_UPDATED" >> $env:GITHUB_STEP_SUMMARY - - # Set a flag to skip PR creation - echo "AUTO_MERGED=true" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 - } else { - throw $pushErrorMessage - } - } else { - throw "Failed to commit changes (exit code: $LASTEXITCODE)" - } - } catch { - echo "" >> $env:GITHUB_STEP_SUMMARY - echo "โš ๏ธ **Warning:** Unable to automatically merge updates." >> $env:GITHUB_STEP_SUMMARY - echo "" >> $env:GITHUB_STEP_SUMMARY - echo "**Error:** $($_.Exception.Message)" >> $env:GITHUB_STEP_SUMMARY - echo "" >> $env:GITHUB_STEP_SUMMARY - echo "Falling back to creating a pull request..." >> $env:GITHUB_STEP_SUMMARY - - Write-Warning "Failed to auto-merge: $($_.Exception.Message)" - - # Set flag to create PR instead - echo "AUTO_MERGED=false" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 - $global:LASTEXITCODE = 0 - exit 0 - } - - - id: create-pr - uses: peter-evans/create-pull-request@v8 - if: fromJSON(env.COUNT_UPDATED) > 0 && env.AUTO_MERGED != 'true' - with: - title: ${{ env.COUNT_UPDATED == 1 && format('โฌ†๏ธ Update {0}', env.LIST_UPDATED) || format('โฌ†๏ธ Update {0} vendored dependencies', env.COUNT_UPDATED) }} - body: | - ### ${{ env.COUNT_UPDATED == 1 && format('๐Ÿ“ฆ Updated {0} from `{1}` to `{2}`', env.SINGLE_DEP_NAME, env.SINGLE_DEP_OLD_VERSION, env.SINGLE_DEP_NEW_VERSION) || format('๐Ÿ“ฆ Automatically updated `{0}` dependencies', env.COUNT_UPDATED) }} - - ${{ env.UPDATE_MESSAGE }} - - ${{ env.CHANGELOG_SECTION }} - - --- - - ${{ env.EMOJI_LEGEND }} - - ${{ env.HAS_BREAKING_CHANGES == 'True' && '**Review note:** This update contains version changes that may require manual review.' || '**Review note:** This update only contains minor or patch changes.' }} - - Please verify and then **Merge** the pull request to apply the updates. - commit-message: 'โฌ†๏ธ Update dependencies (${{ env.LIST_UPDATED }})' - branch: update-vendor - base: master - labels: | - ๐Ÿ‘† Dependencies - ๐Ÿ—ƒ๏ธ Vendor - team-reviewers: ${{ env.REVIEW_TEAM }} - - - name: Summary - Pull request result - if: env.COUNT_UPDATED > 0 && env.AUTO_MERGED != 'true' - shell: pwsh - env: - PR_URL: ${{ steps.create-pr.outputs.pull-request-url }} - PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }} - PR_OPERATION: ${{ steps.create-pr.outputs.pull-request-operation }} - AUTO_MERGE_FAILURE_REASON: ${{ env.AUTO_MERGE_FAILURE_REASON }} - AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED: ${{ env.AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED }} - run: | - $updateVendorBranchUrl = "$($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/tree/update-vendor" - $summary = @" - ### ๐ŸŽ‰ Pull Request Result - - **Branch:** [``update-vendor``]($updateVendorBranchUrl) - - $(if (-not [string]::IsNullOrEmpty($env:LIST_UPDATED)) { "**Updated dependencies:** $env:LIST_UPDATED" } else { "**Updated dependencies:** " }) - - "@ - - switch ($env:PR_OPERATION) { - 'created' { - $summary += "A new pull request has been created: [#$($env:PR_NUMBER)]($($env:PR_URL))`n`n" - } - 'updated' { - $summary += "An existing pull request has been updated: [#$($env:PR_NUMBER)]($($env:PR_URL))`n`n" - } - 'none' { - $summary += "No pull request was created because [update-vendor]($updateVendorBranchUrl) no longer differs from ``master``.`n`n" - } - default { - if (-not [string]::IsNullOrWhiteSpace($env:PR_URL)) { - $summary += "A pull request was reported, but the operation type was not recognized: [#$($env:PR_NUMBER)]($($env:PR_URL))`n`n" - } else { - $summary += "A pull request was requested, but no PR link was returned.`n`n" - } - } - } - - if (-not [string]::IsNullOrWhiteSpace($env:AUTO_MERGE_FAILURE_REASON)) { - $summary += "> โš ๏ธ **Auto-merge failure:** $env:AUTO_MERGE_FAILURE_REASON`n`n" - } - - if ($env:HAS_BREAKING_CHANGES -eq 'True') { - $summary += "> โš ๏ธ **Manual review required:** This update contains major version changes." - } elseif ($env:PR_OPERATION -eq 'none') { - $summary += "> โ„น๏ธ **Note:** No pull request was created because there were no differences left to propose." - } elseif ($env:AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED -ne 'True') { - $summary += "> โ„น๏ธ **Note:** Auto-merge is disabled by configuration. Set the ``AUTO_MERGE_MINOR_VENDOR_UPDATES`` Actions repository variable to ``true`` to opt in." - } else { - $summary += "> โ„น๏ธ **Note:** Auto-merge failed, manual review required." - } - - $summary += "`n> Please review and merge the pull request to apply the updates.`n`n" - - $summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 From f4cb8e5ebd29a4b54c84d03a3c172199b032fa9c Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 04:57:08 +0330 Subject: [PATCH 05/17] fix(legacy): keep Windows Terminal out of ConEmu packages Keep cmder.zip, cmder.7z, cmder_mini.zip and init.bat unchanged as the 1.x contract. Drop the unused WT download and exclude existing WT directories from every maintenance archive. Verify real packer output, Git selection, archive integrity, and SHA256 with disposable fixtures. --- .github/workflows/tests.yml | 4 ++ scripts/pack.ps1 | 6 +-- scripts/test-legacy-packaging.ps1 | 69 +++++++++++++++++++++++++++++++ vendor/sources.json | 5 --- 4 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 scripts/test-legacy-packaging.ps1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 445de23bd..3b0b58dd8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,6 +50,10 @@ jobs: shell: pwsh run: .\scripts\test-shell-detection.ps1 + - name: Test legacy package contents + shell: pwsh + run: .\scripts\test-legacy-packaging.ps1 + - name: Add MSBuild to PATH uses: microsoft/setup-msbuild@v3 diff --git a/scripts/pack.ps1 b/scripts/pack.ps1 index da6fc6e0d..bbe2df435 100644 --- a/scripts/pack.ps1 +++ b/scripts/pack.ps1 @@ -42,9 +42,9 @@ $ErrorActionPreference = "Stop" Ensure-Executable "7z" $targets = @{ - "cmder.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on"; - "cmder.zip" = "-mm=Deflate -mfb=128 -mpass=3"; - "cmder_mini.zip" = "-xr!`"vendor\git-for-windows`""; + "cmder.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\windows-terminal`""; + "cmder.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\windows-terminal`""; + "cmder_mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\windows-terminal`""; } Push-Location -Path $cmderRoot diff --git a/scripts/test-legacy-packaging.ps1 b/scripts/test-legacy-packaging.ps1 new file mode 100644 index 000000000..30ca44a92 --- /dev/null +++ b/scripts/test-legacy-packaging.ps1 @@ -0,0 +1,69 @@ +[CmdletBinding()] +param() + +$ErrorActionPreference = 'Stop' +$tempRoot = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()) +$fixture = Join-Path $tempRoot ('cmder-legacy-pack-' + [guid]::NewGuid().ToString('N')) +$packScript = Join-Path $PSScriptRoot 'pack.ps1' +$expected = @('cmder.7z', 'cmder.zip', 'cmder_mini.zip') + +try { + $null = New-Item -ItemType Directory -Path $fixture + foreach ($name in @('conemu-maximus5', 'git-for-windows', 'windows-terminal')) { + $directory = Join-Path $fixture "vendor\$name" + $null = New-Item -ItemType Directory -Path $directory -Force + Set-Content -LiteralPath (Join-Path $directory 'marker.txt') -Value $name + } + Set-Content -LiteralPath (Join-Path $fixture 'vendor\init.bat') -Value '@rem Legacy initialization' + Set-Content -LiteralPath (Join-Path $fixture 'Cmder.exe') -Value 'Launcher fixture' + Copy-Item -LiteralPath (Join-Path $PSScriptRoot '..\packignore') -Destination $fixture + + # Supply local version metadata without relying on the caller's repository. + git -C $fixture init --quiet + if ($LASTEXITCODE -ne 0) { throw 'Cannot initialize fixture version metadata.' } + git -C $fixture -c user.name=Fixture -c user.email=fixture@example.invalid commit --allow-empty --quiet -m Fixture + if ($LASTEXITCODE -ne 0) { throw 'Cannot create fixture version metadata.' } + git -C $fixture tag v1.3.26-fixture + if ($LASTEXITCODE -ne 0) { throw 'Cannot tag fixture version metadata.' } + + # The real packer operates only on this disposable fixture, never the checkout. + & $packScript -cmderRoot $fixture -saveTo (Join-Path $fixture 'build') + $actual = @(Get-ChildItem -LiteralPath (Join-Path $fixture 'build') -File | Sort-Object Name) + if (($actual.Name -join ',') -ne (($expected + 'hashes.txt' | Sort-Object) -join ',')) { + throw "Unexpected legacy asset names: $($actual.Name -join ', ')" + } + + foreach ($name in $expected) { + $archive = Join-Path $fixture "build\$name" + & 7z t $archive | Out-Null + if ($LASTEXITCODE -ne 0) { throw "Invalid archive: $name" } + $listing = (& 7z l -slt $archive) -join "`n" + if ($LASTEXITCODE -ne 0) { throw "Cannot list archive: $name" } + if ($listing -match '(?m)^Path = vendor[\\/]windows-terminal(?:[\\/]|\r?$)') { + throw "Legacy archive includes Windows Terminal: $name" + } + foreach ($required in @('Cmder.exe', 'vendor[\\/]init.bat', 'vendor[\\/]conemu-maximus5[\\/]marker.txt')) { + if ($listing -notmatch "(?m)^Path = $required`r?$" ) { + throw "Missing $required in $name" + } + } + $hasGit = $listing -match 'Path = vendor[\\/]git-for-windows[\\/]marker.txt' + if ($hasGit -eq ($name -eq 'cmder_mini.zip')) { + throw "Wrong Git contents in $name" + } + $hash = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash + if ((Get-Content -LiteralPath (Join-Path $fixture 'build\hashes.txt')) -notcontains "$name`t$hash") { + throw "Missing or incorrect SHA256 for $name" + } + Write-Host "Passed: $name contents, integrity, and SHA256" + } +} +finally { + $resolvedFixture = [IO.Path]::GetFullPath($fixture) + if (-not $resolvedFixture.StartsWith((Join-Path $tempRoot 'cmder-legacy-pack-'), [StringComparison]::OrdinalIgnoreCase)) { + throw 'Refusing to remove a fixture outside the expected temporary path.' + } + if (Test-Path -LiteralPath $resolvedFixture) { + Remove-Item -LiteralPath $resolvedFixture -Recurse -Force + } +} diff --git a/vendor/sources.json b/vendor/sources.json index df1ae3e5f..b34f88f95 100644 --- a/vendor/sources.json +++ b/vendor/sources.json @@ -14,11 +14,6 @@ "version": "23.07.24", "url": "https://github.com/ConEmu/ConEmu/releases/download/v23.07.24/ConEmuPack.230724.7z" }, - { - "name": "windows-terminal", - "version": "1.23.12811.0", - "url": "https://github.com/microsoft/terminal/releases/download/v1.23.12811.0/Microsoft.WindowsTerminal_1.23.12811.0_x64.zip" - }, { "name": "clink-completions", "version": "0.6.7", From 70f5e98d16d796ced8e1d45b578d988313b4172e Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 04:57:57 +0330 Subject: [PATCH 06/17] docs(legacy): prepare scoped unreleased 1.3.26 notes Document the preserved 1.x archive and init.bat contract, substantive work already present since 1.3.25, safety backports, and inherited component pins. Keep the section unreleased and avoid implying obsolete Windows support. --- CHANGELOG.md | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 10 ++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eca18db4c..355945d52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,44 @@ # Change Log +## [1.3.26](https://github.com/cmderdev/cmder/compare/v1.3.25...legacy/1.x) (UNRELEASED) + +### Maintenance scope + +- Keep the ConEmu launcher, `vendor\init.bat`, and existing archive names: + `cmder.zip`, `cmder.7z`, and `cmder_mini.zip`. +- Continue maintenance on `legacy/1.x`. Current development continues on `main`; + fixes can be backported without merging the new launcher or initialization model. +- Do not download or bundle Windows Terminal in this ConEmu-only maintenance line. + +### Fixes since 1.3.25 + +- Reject missing launcher option values and oversized configuration, icon, or + executable paths. Preserve switches after a positional starting directory and + reject invalid arguments before attempting context-menu registration. +- Restore the previous TCC and TCCLE shell-helper defaults for Clink and aliases, + preserving explicit user settings and the existing `init.bat` behavior. +- Support Git repositories that use reftables in the Clink prompt. +- Make Mercurial prompt updates asynchronous and fix its branch handling. +- Quote Git locale paths, avoid temporary-file name collisions, and respect + `PATHEXT` while building the command search path. +- Improve PowerShell Git version comparisons, posh-git compatibility, and debug + output. Keep the existing terminal shell-integration sequences. +- Filter prerelease and downgrade vendor candidates and fix the vendor update + helper command. Run legacy launcher, shell-default, and package-content checks + independently of current development. +- Read pull-request branch names through the environment in workflow summaries. + +### Components + +- Git for Windows 2.52.0.windows.1, Clink 1.9.5, ConEmu 23.07.24, and + clink-completions 0.6.7 are the inherited maintenance pins. +- The Full archives include Git. The Mini archive uses an external Git install. + Embedded components have their own Windows requirements; a 1.x archive does + not imply Windows 7 support. See the + [Git for Windows requirements](https://gitforwindows.org/requirements.html). +- This section records unreleased work. A final release must document the actual + selected component versions and archive verification. + ## [1.3.25](https://github.com/cmderdev/cmder/tree/v1.3.25) (2024-05-31) ### Changes diff --git a/README.md b/README.md index 7b8a6fda5..386c7da86 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ # Cmder -[![Join the chat at https://gitter.im/cmderdev/cmder](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cmderdev/cmder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Amaster) +This is the `legacy/1.x` maintenance line. Current Cmder development and the 2.x +releases are on [`main`](https://github.com/cmderdev/cmder/tree/main). This branch +keeps the ConEmu launcher, `vendor\init.bat`, and the existing Full +(`cmder.zip`, `cmder.7z`) and Mini (`cmder_mini.zip`) archive names. +See the [unreleased 1.3.26 notes](CHANGELOG.md) for the maintenance changes. + +[![Join the chat at https://gitter.im/cmderdev/cmder](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cmderdev/cmder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=legacy%2F1.x)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x) Cmder is a **software package** created out of pure frustration over absence of usable console emulator on Windows. It is based on [ConEmu](https://conemu.github.io/) with *major* config overhaul, comes with a Monokai color scheme, amazing [clink](https://chrisant996.github.io/clink/) (further enhanced by [clink-completions](https://github.com/vladimir-kotikov/clink-completions)) and a custom prompt layout. @@ -392,7 +398,7 @@ You can download the latest successful builds of the current [`master`](https:// | Branch | Build Status | Download Artifacts | |--------|-------------|-------------------| -| ๐Ÿ”’ [`master`](https://github.com/cmderdev/cmder/tree/master) | [![master build status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Amaster+is%3Asuccess) | [๐Ÿ“ฆ Artifacts](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Amaster+is%3Asuccess) | +| ๐Ÿ”’ [`master`](https://github.com/cmderdev/cmder/tree/master) | [![master build status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=legacy%2F1.x)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x+is%3Asuccess) | [๐Ÿ“ฆ Artifacts](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x+is%3Asuccess) | | ๐Ÿ”ง [`development`](https://github.com/cmderdev/cmder/tree/development) | [![development build status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=development)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apull_request+branch%3Adevelopment+is%3Asuccess) | [๐Ÿ“ฆ Artifacts](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apull_request+branch%3Adevelopment+is%3Asuccess) | ## License From cbefb807949ec858ae7b108eb2c708e3bec6a0a1 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:02:29 +0330 Subject: [PATCH 07/17] fix(legacy): preserve forwarded switches and explicit config paths Keep slash-prefixed ConEmu /x arguments valid. Read USERPROFILE only for the default /c path, reject failed path combination, and cover explicit configuration with an absent profile in both launcher test builds. --- launcher/src/CmderLauncher.cpp | 29 +++++++++++++-------------- launcher/tests/CmderLauncherTests.cpp | 18 ++++++++++++++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 20149be17..294f3b885 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -645,24 +645,23 @@ cmderOptions GetOption() if (cmderOptions.error == false) { if (_wcsicmp(L"/c", szArgList[i]) == 0) { - TCHAR userProfile[MAX_PATH] = { 0 }; - const DWORD ret = GetEnvironmentVariable(L"USERPROFILE", userProfile, MAX_PATH); - if (ret == 0 || ret >= MAX_PATH) - { - cmderOptions.error = true; - continue; - } - - wchar_t cmderCfgRoot[MAX_PATH] = { 0 }; - PathCombine(cmderCfgRoot, userProfile, L"cmder_cfg"); - - cmderOptions.cmderCfgRoot = cmderCfgRoot; - - if (hasValue(i) && _wcsicmp(L"--", szArgList[i + 1]) != 0) + if (hasValue(i)) { cmderOptions.cmderCfgRoot = szArgList[i + 1]; i++; } + else + { + TCHAR userProfile[MAX_PATH] = { 0 }; + const DWORD ret = GetEnvironmentVariable(L"USERPROFILE", userProfile, MAX_PATH); + wchar_t cmderCfgRoot[MAX_PATH] = { 0 }; + if (ret == 0 || ret >= MAX_PATH || PathCombine(cmderCfgRoot, userProfile, L"cmder_cfg") == NULL) + { + cmderOptions.error = true; + continue; + } + cmderOptions.cmderCfgRoot = cmderCfgRoot; + } } else if (_wcsicmp(L"/start", szArgList[i]) == 0) { @@ -742,7 +741,7 @@ cmderOptions GetOption() /* Used for passing arguments to conemu prog */ else if (_wcsicmp(L"/x", szArgList[i]) == 0) { - if (!hasValue(i)) { cmderOptions.error = true; continue; } + if (i + 1 >= argCount || szArgList[i + 1][0] == L'\0') { cmderOptions.error = true; continue; } cmderOptions.cmderConEmuArgs = szArgList[i + 1]; i++; } diff --git a/launcher/tests/CmderLauncherTests.cpp b/launcher/tests/CmderLauncherTests.cpp index 42b624e08..dd6ce68d8 100644 --- a/launcher/tests/CmderLauncherTests.cpp +++ b/launcher/tests/CmderLauncherTests.cpp @@ -184,6 +184,22 @@ static void TestArgumentParsing() Check(!options.error && options.cmderTask == L"Custom" && options.cmderConEmuArgs == L"-foo bar" && options.cmderSingle && !options.cmderUserCfg && options.cmderTitle == L"Custom" && options.cmderIcon == L"custom.ico", "Legacy ConEmu arguments changed"); + options = Parse(L"/x \"/run cmd\""); + Check(!options.error && options.cmderConEmuArgs == L"/run cmd", + "Slash-prefixed ConEmu arguments were rejected"); + const DWORD profileSize = GetEnvironmentVariableW(L"USERPROFILE", NULL, 0); + std::vector savedProfile(profileSize); + if (profileSize != 0) { GetEnvironmentVariableW(L"USERPROFILE", savedProfile.data(), profileSize); } + Check(SetEnvironmentVariableW(L"USERPROFILE", NULL) != 0, "Could not clear fixture USERPROFILE"); + options = Parse(L"/c \"" + root + L"\""); + Check(!options.error && options.cmderCfgRoot == root, + "Explicit configuration path depended on USERPROFILE"); + Check(Parse(L"/c").error, "Missing default profile was accepted"); + Check(SetEnvironmentVariableW(L"USERPROFILE", std::wstring(MAX_PATH - 1, L'a').c_str()) != 0, + "Could not set fixture USERPROFILE"); + Check(Parse(L"/c").error, "Oversized combined default configuration path was accepted"); + Check(SetEnvironmentVariableW(L"USERPROFILE", profileSize == 0 ? NULL : savedProfile.data()) != 0, + "Could not restore USERPROFILE"); Check(!Parse(L"/register USER").error && !Parse(L"/unregister ALL").error, "Valid registration arguments changed"); Parse(L"/register /start"); @@ -208,4 +224,4 @@ int wmain() std::cerr << error.what() << '\n'; return 1; } -} \ No newline at end of file +} From 18d8f37751b6a833dfa5bafa98dfb0b5b4e966fc Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:02:31 +0330 Subject: [PATCH 08/17] docs(legacy): link maintenance build artifacts consistently --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 386c7da86..33dae372e 100644 --- a/README.md +++ b/README.md @@ -394,12 +394,11 @@ If you do not have a `[cmder_root]/config/user[-|_]conemu.xml`, you are running ## Latest Builds -You can download the latest successful builds of the current [`master`](https://github.com/cmderdev/cmder/tree/master) and [`development`](https://github.com/cmderdev/cmder/tree/development) branches from the **GitHub Actions > Artifacts** section following the links below: +You can download successful `legacy/1.x` maintenance builds from **GitHub Actions > Artifacts** using the link below. Current 2.x development is on [`main`](https://github.com/cmderdev/cmder/tree/main); use its [build artifacts](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Amain+is%3Asuccess) for the new release line. | Branch | Build Status | Download Artifacts | |--------|-------------|-------------------| -| ๐Ÿ”’ [`master`](https://github.com/cmderdev/cmder/tree/master) | [![master build status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=legacy%2F1.x)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x+is%3Asuccess) | [๐Ÿ“ฆ Artifacts](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x+is%3Asuccess) | -| ๐Ÿ”ง [`development`](https://github.com/cmderdev/cmder/tree/development) | [![development build status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=development)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apull_request+branch%3Adevelopment+is%3Asuccess) | [๐Ÿ“ฆ Artifacts](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apull_request+branch%3Adevelopment+is%3Asuccess) | +| ๐Ÿ”’ [`legacy/1.x`](https://github.com/cmderdev/cmder/tree/legacy/1.x) | [![legacy build status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=legacy%2F1.x)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x+is%3Asuccess) | [๐Ÿ“ฆ Artifacts](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x+is%3Asuccess) | ## License From 2697f62dbbff260d9badd038fc08b435910840cb Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:04:00 +0330 Subject: [PATCH 09/17] fix(legacy): backport safe archive and vendor build helpers Selectively port 0da8567 and 668120d for issue3118. Keep three legacy asset names and WT exclusions while passing native archive arguments as data. Validate every custom vendor name before vendor operations, preserve failed extraction inputs, restore location after compression failures, and use SHA256 and robust Git version fallback. All27 helper cases and all3 package fixtures pass under PowerShell5.1 and7. --- .github/workflows/tests.yml | 8 +++ CHANGELOG.md | 4 ++ scripts/build.ps1 | 4 ++ scripts/pack.ps1 | 6 +- scripts/test-build-helpers.ps1 | 125 +++++++++++++++++++++++++++++++++ scripts/utils.ps1 | 55 ++++++++++----- 6 files changed, 181 insertions(+), 21 deletions(-) create mode 100644 scripts/test-build-helpers.ps1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3b0b58dd8..b7190a5ec 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,6 +46,14 @@ jobs: shell: pwsh run: .\scripts\test-update.ps1 + - name: Test build helper argument and path safety + shell: pwsh + run: .\scripts\test-build-helpers.ps1 + + - name: Test build helpers on Windows PowerShell 5.1 + shell: powershell + run: .\scripts\test-build-helpers.ps1 + - name: Test historical shell defaults shell: pwsh run: .\scripts\test-shell-detection.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 355945d52..cd3472a9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ helper command. Run legacy launcher, shell-default, and package-content checks independently of current development. - Read pull-request branch names through the environment in workflow summaries. +- Pass archive paths and exclusions as arguments instead of executable strings, + preserve inputs after extraction failures, and restore the working directory + after compression failures. Validate custom vendor names before touching any + vendor directory and consistently produce SHA256 hashes. ### Components diff --git a/scripts/build.ps1 b/scripts/build.ps1 index cfce5fa8d..65bf2e17f 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -95,6 +95,10 @@ if (-not $noVendor) { # Get the vendor sources $sources = Get-Content $sourcesPath | Out-String | ConvertFrom-Json + # Validate the entire custom manifest before any vendor backup or deletion. + foreach ($source in $sources) { + Assert-CmderVendorName $source.name + } Push-Location -Path $saveTo New-Item -Type Directory -Path (Join-Path $saveTo "/tmp/") -ErrorAction SilentlyContinue >$null diff --git a/scripts/pack.ps1 b/scripts/pack.ps1 index bbe2df435..62932b7a9 100644 --- a/scripts/pack.ps1 +++ b/scripts/pack.ps1 @@ -42,9 +42,9 @@ $ErrorActionPreference = "Stop" Ensure-Executable "7z" $targets = @{ - "cmder.7z" = "-t7z -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on -myx=7 -mqs=on -xr!`"vendor\windows-terminal`""; - "cmder.zip" = "-mm=Deflate -mfb=128 -mpass=3 -xr!`"vendor\windows-terminal`""; - "cmder_mini.zip" = "-xr!`"vendor\git-for-windows`" -xr!`"vendor\windows-terminal`""; + "cmder.7z" = @('-t7z', '-m0=lzma2', '-mx=9', '-mfb=64', '-md=32m', '-ms=on', '-myx=7', '-mqs=on', '-xr!vendor\windows-terminal'); + "cmder.zip" = @('-mm=Deflate', '-mfb=128', '-mpass=3', '-xr!vendor\windows-terminal'); + "cmder_mini.zip" = @('-xr!vendor\git-for-windows', '-xr!vendor\windows-terminal'); } Push-Location -Path $cmderRoot diff --git a/scripts/test-build-helpers.ps1 b/scripts/test-build-helpers.ps1 new file mode 100644 index 000000000..3bf1b63d2 --- /dev/null +++ b/scripts/test-build-helpers.ps1 @@ -0,0 +1,125 @@ +[CmdletBinding()] +param() + +$ErrorActionPreference = 'Stop' +. (Join-Path $PSScriptRoot 'utils.ps1') +Ensure-Executable '7z' + +$testParent = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath()) +$testRoot = Join-Path $testParent ('cmder-build-helpers-' + [guid]::NewGuid().ToString('N')) +$originalLocation = $PWD.Path +$cases = 0 + +try { + $null = New-Item -ItemType Directory -Path $testRoot + $source = Join-Path $testRoot 'source [literal] $(throw INJECTION); & text' + $null = New-Item -ItemType Directory -Path $source + $null = New-Item -ItemType Directory -Path (Join-Path $source 'vendor\drop') + Set-Content -LiteralPath (Join-Path $source 'kept.txt') -Value 'expected payload' -Encoding ascii + Set-Content -LiteralPath (Join-Path $source 'vendor\drop\excluded.txt') -Value 'excluded payload' -Encoding ascii + Set-Content -LiteralPath (Join-Path $source 'packignore') -Value 'packignore' -Encoding ascii + $archive = Join-Path $testRoot 'archive [literal] $(throw INJECTION).zip' + Create-Archive $source $archive @('-tzip', '-xr!vendor\drop') + if ($PWD.Path -ne $originalLocation -or -not (Test-Path -LiteralPath $archive)) { + throw 'Archive creation failed to preserve literal paths or restore the working directory.' + } + & 7z t $archive > $null + if ($LASTEXITCODE -ne 0) { throw 'The created archive failed integrity verification.' } + $listing = (& 7z l -slt -ba $archive) -join "`n" + if ($LASTEXITCODE -ne 0 -or $listing -notmatch 'Path = kept\.txt' -or $listing -match 'excluded\.txt') { + throw 'Archive content or array-based vendor exclusion is incorrect.' + } + $expectedHash = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash + if ((Digest-Hash $archive) -ne $expectedHash -or $expectedHash.Length -ne 64) { + throw 'Digest-Hash did not return SHA-256 for a literal path.' + } + $cases++ + + $extraction = Join-Path $testRoot 'extracted [literal] $(throw INJECTION)' + Extract-Archive $archive $extraction + if ((Get-Content -LiteralPath (Join-Path $extraction 'kept.txt') -Raw).Trim() -ne 'expected payload') { + throw 'Literal-path archive extraction lost the payload.' + } + if (Test-Path -LiteralPath $archive) { throw 'Successful extraction did not remove its input archive.' } + $cases++ + + $corrupt = Join-Path $testRoot 'corrupt [literal].zip' + Set-Content -LiteralPath $corrupt -Value 'not an archive' -Encoding ascii + $failed = $false + try { Extract-Archive $corrupt (Join-Path $testRoot 'bad-extraction') 2>$null } catch { $failed = $true } + if (-not $failed -or -not (Test-Path -LiteralPath $corrupt)) { + throw 'Failed extraction must report failure and preserve the input archive.' + } + $cases++ + + $failed = $false + try { Create-Archive $source (Join-Path $testRoot 'bad.zip') @('-tinvalid-format') 2>$null } catch { $failed = $true } + if (-not $failed -or $PWD.Path -ne $originalLocation) { + throw 'Failed compression must report failure and restore the working directory.' + } + $cases++ + + foreach ($name in @('clink', 'git-for-windows', 'vendor_1.2-rc', 'x')) { + Assert-CmderVendorName $name + $cases++ + } + foreach ($name in @('', '.', '..', '..\outside', '../outside', 'C:\outside', '\\server\share', + 'vendor*', 'vendor?', 'name.', 'space name', '$(throw INJECTION)', 'CON', 'aux.txt', 'LPT1', 'com9.zip')) { + $failed = $false + try { Assert-CmderVendorName $name } catch { $failed = $true } + if (-not $failed) { throw "Unsafe vendor name was accepted: $name" } + $cases++ + } + + $vendorRoot = Join-Path $testRoot 'vendors' + $null = New-Item -ItemType Directory -Path $vendorRoot + $sentinel = Join-Path $vendorRoot 'preserve.txt' + Set-Content -LiteralPath $sentinel -Value 'preserve' -Encoding ascii + $manifest = Join-Path $testRoot 'invalid-sources.json' + '[{"name":"..\\outside","version":"1","url":"https://example.invalid/not-downloaded"}]' | + Set-Content -LiteralPath $manifest -Encoding ascii + $failed = $false + try { + & (Join-Path $PSScriptRoot 'build.ps1') -SourcesPath $manifest -SaveTo $vendorRoot + } catch { + if ($_.Exception.Message -notlike 'Invalid vendor name*') { throw } + $failed = $true + } + if (-not $failed -or (Test-Path -LiteralPath (Join-Path $vendorRoot 'tmp')) -or + (Get-Content -LiteralPath $sentinel -Raw).Trim() -ne 'preserve') { + throw 'Invalid manifest must fail before any vendor-directory mutation.' + } + $cases++ + + Push-Location -LiteralPath $testRoot + try { + $version = Get-VersionStr + if ($version -notmatch '^\d+\.\d+' -or $ErrorActionPreference -ne 'Stop') { + throw 'Version fallback outside a Git repository failed or changed error handling.' + } + $null = & git.exe init --quiet + if ($LASTEXITCODE -ne 0) { throw 'Unable to prepare the untagged Git fixture.' } + $version = Get-VersionStr + if ($version -notmatch '^\d+\.\d+' -or $ErrorActionPreference -ne 'Stop') { + throw 'Version fallback in an untagged Git repository failed or changed error handling.' + } + } finally { + Pop-Location + } + $cases += 2 +} finally { + if (Test-Path -LiteralPath $testRoot) { + $resolved = (Resolve-Path -LiteralPath $testRoot).Path + $item = Get-Item -LiteralPath $resolved + if (-not $resolved.StartsWith($testParent, [System.StringComparison]::OrdinalIgnoreCase) -or + $item.Name -notmatch '^cmder-build-helpers-[0-9a-f]{32}$' -or + ($item.Attributes -band [System.IO.FileAttributes]::ReparsePoint)) { + throw "Refusing to remove an unexpected test directory: $resolved" + } + Remove-Item -LiteralPath $resolved -Recurse -Force + } +} + +Write-Output "Build helper regression tests passed ($cases cases)." +# Expected native failures above must not become the Actions shell's exit code. +exit 0 diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index e0c107b92..cdb9217d2 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -70,21 +70,23 @@ function Delete-Existing($path) { function Extract-Archive($source, $target) { Write-Verbose $("Extracting Archive '$cmder_root\vendor\" + $source.replace('/','\') + " to '$cmder_root\vendor\$target'") - Invoke-Expression "7z x -y -o`"$($target)`" `"$source`" > `$null" + & 7z x -y "-o$target" $source > $null if ($LastExitCode -ne 0) { - Write-Error "Extracting of $source failed" + throw "Extracting of $source failed (7-Zip exit code $LastExitCode)" } - Remove-Item $source + Remove-Item -LiteralPath $source } -function Create-Archive($source, $target, $params) { - $command = "7z a -x@`"$source\packignore`" $params `"$target`" `"*`" > `$null" +function Create-Archive($source, $target, [string[]]$params) { Write-Verbose "Creating Archive from '$source' in '$target' with parameters '$params'" - Push-Location $source - Invoke-Expression $command - Pop-Location - if ($LastExitCode -ne 0) { - Write-Error "Compressing $source failed" + Push-Location -LiteralPath $source + try { + & 7z a "-x@$source\packignore" @params $target '*' > $null + if ($LastExitCode -ne 0) { + throw "Compressing $source failed (7-Zip exit code $LastExitCode)" + } + } finally { + Pop-Location } } @@ -101,11 +103,18 @@ function Flatten-Directory($name) { } function Digest-Hash($path) { - if (Get-Command Get-FileHash -ErrorAction SilentlyContinue) { - return (Get-FileHash -Algorithm SHA256 -Path $path).Hash - } + return (Get-FileHash -Algorithm SHA256 -LiteralPath $path).Hash +} - return Invoke-Expression "md5sum $path" +function Assert-CmderVendorName([string]$Name) { + # A vendor is one ordinary Windows directory name, never a path or pattern. + if ( + $Name -notmatch '^[A-Za-z0-9][A-Za-z0-9._-]*$' -or + $Name.EndsWith('.') -or + $Name -match '^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)' + ) { + throw "Invalid vendor name '$Name': expected one safe directory name." + } } function Set-GHVariable { @@ -146,10 +155,20 @@ function Get-VersionStr { # Determine if git is available if (Get-Command "git.exe" -ErrorAction SilentlyContinue) { # Determine if the current directory is a git repository - $GitPresent = Invoke-Expression "git rev-parse --is-inside-work-tree" -ErrorAction SilentlyContinue - - if ( $GitPresent -eq 'true' ) { - $string = Invoke-Expression "git describe --abbrev=0 --tags" + # Native stderr is an ErrorRecord on Windows PowerShell 5.1. A missing + # repository/tag is an expected fallback, even when the caller uses Stop. + $previousErrorActionPreference = $ErrorActionPreference + try { + $ErrorActionPreference = 'Continue' + $GitPresent = & git.exe rev-parse --is-inside-work-tree 2>$null + if ($LASTEXITCODE -eq 0 -and $GitPresent -eq 'true') { + $candidate = & git.exe describe --abbrev=0 --tags 2>$null + if ($LASTEXITCODE -eq 0) { + $string = $candidate + } + } + } finally { + $ErrorActionPreference = $previousErrorActionPreference } } From 8f542395b089676f610296b23dfade9dfc9ebcde Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:09:40 +0330 Subject: [PATCH 10/17] fix(legacy): reject trailing newlines in vendor names --- scripts/test-build-helpers.ps1 | 2 +- scripts/utils.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test-build-helpers.ps1 b/scripts/test-build-helpers.ps1 index 3bf1b63d2..b89651a2e 100644 --- a/scripts/test-build-helpers.ps1 +++ b/scripts/test-build-helpers.ps1 @@ -64,7 +64,7 @@ try { $cases++ } foreach ($name in @('', '.', '..', '..\outside', '../outside', 'C:\outside', '\\server\share', - 'vendor*', 'vendor?', 'name.', 'space name', '$(throw INJECTION)', 'CON', 'aux.txt', 'LPT1', 'com9.zip')) { + ('clink' + [char]10), 'vendor*', 'vendor?', 'name.', 'space name', '$(throw INJECTION)', 'CON', 'aux.txt', 'LPT1', 'com9.zip')) { $failed = $false try { Assert-CmderVendorName $name } catch { $failed = $true } if (-not $failed) { throw "Unsafe vendor name was accepted: $name" } diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index cdb9217d2..039d24401 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -109,7 +109,7 @@ function Digest-Hash($path) { function Assert-CmderVendorName([string]$Name) { # A vendor is one ordinary Windows directory name, never a path or pattern. if ( - $Name -notmatch '^[A-Za-z0-9][A-Za-z0-9._-]*$' -or + $Name -notmatch '^[A-Za-z0-9][A-Za-z0-9._-]*\z' -or $Name.EndsWith('.') -or $Name -match '^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)' ) { From 1d67a96c429d79b93d19299ba3a6a66a587de918 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:10:22 +0330 Subject: [PATCH 11/17] fix(legacy): select Git for Windows 2.56.0 security update Use the official PortableGit 2.56.0.windows.4 x64 package, digest b1f3e52216e2ed6882d1bebfd4d3fdf319bec40d2edbbf9fd26ec4fd3fce7ed1. Apply UCRT64 compatibility before publishing the maintenance release. Related vendor update: #3093. --- vendor/sources.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/sources.json b/vendor/sources.json index b34f88f95..949b02117 100644 --- a/vendor/sources.json +++ b/vendor/sources.json @@ -1,8 +1,8 @@ [ { "name": "git-for-windows", - "version": "2.52.0.windows.1", - "url": "https://github.com/git-for-windows/git/releases/download/v2.52.0.windows.1/PortableGit-2.52.0-64-bit.7z.exe" + "version": "2.56.0.windows.4", + "url": "https://github.com/git-for-windows/git/releases/download/v2.56.0.windows.4/PortableGit-2.56.0.4-64-bit.7z.exe" }, { "name": "clink", From 2658da5158afc4fd7a1973cea67f9847a9dc5b7c Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:12:41 +0330 Subject: [PATCH 12/17] docs(legacy): document selective maintenance and release checks --- CHANGELOG.md | 4 +-- CONTRIBUTING.md | 16 ++++++---- docs/MAINTENANCE-1.x.md | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 docs/MAINTENANCE-1.x.md diff --git a/CHANGELOG.md b/CHANGELOG.md index cd3472a9b..00e71d627 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,8 +34,8 @@ ### Components -- Git for Windows 2.52.0.windows.1, Clink 1.9.5, ConEmu 23.07.24, and - clink-completions 0.6.7 are the inherited maintenance pins. +- Git for Windows 2.56.0.windows.4 supplies the selected upstream security fixes. + Clink 1.9.5, ConEmu 23.07.24, and clink-completions 0.6.7 retain their inherited pins. - The Full archives include Git. The Mini archive uses an external Git install. Embedded components have their own Windows requirements; a 1.x archive does not imply Windows 7 support. See the diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9bfae7a12..0bbce5e3e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,11 @@ # How to contribute +This is the `legacy/1.x` maintenance line. Read the +[maintenance guide](docs/MAINTENANCE-1.x.md) before preparing a backport. +New features and normal current work follow the +[current contribution guide](https://github.com/cmderdev/cmder/blob/main/CONTRIBUTING.md) +and target `main`. `development` is historical. + Unfortunately we all can't work on Cmder every day of the year, so I have decided to write some guidelines for contributing. If you follow them your contribution will likely be pulled in quicker. @@ -7,14 +13,14 @@ If you follow them your contribution will likely be pulled in quicker. ## Getting Started * Fork the repository on GitHub (It's that easy) -* Create a feature branch based on the `master` branch. +* Create a separate branch from `legacy/1.x` for a compatible 1.x fix. Link its current-line fix or original report. ## Making Changes * Make changes in your separate branch. * Check for unnecessary whitespace with `git diff --check` before committing. * Make sure your commit messages are easy to understand -* Squash your 'Correcting mistakes' commits if you have a lot of them. (See the 'Squashing Commits' link below) +* Keep commits focused and preserve contributor credit. Do not rewrite shared history or discard existing work. * Make sure your changes won't affect new users or user without a customised system, try out your changes on a fresh Windows VM to see if it would affect a new user's experience. * Sometimes a change that helps you with your cmder experience and tools doesn't always mean other people may need/want it. @@ -22,13 +28,13 @@ If you follow them your contribution will likely be pulled in quicker. ### Documentation -* If the documentation is about a currently available feature in cmder or correcting already created documentation, you can safely make your changes on the master branch and pull request them onto master. +* Send documentation about this maintenance line to `legacy/1.x`. Send documentation about current features to `main`. ## Submitting Changes * Push your changes to the branch in your fork of the repository. -* Submit a pull request to the develop branch of the cmder repository (unless it's a change in documentation [see above]). -* Make sure you explicitly say to not complete the pull request if you are still making changes. +* Submit a pull request to `legacy/1.x` for a reviewed maintenance fix, or to `main` for current work. +* Open a draft pull request while the change is still in progress. # Additional Resources diff --git a/docs/MAINTENANCE-1.x.md b/docs/MAINTENANCE-1.x.md new file mode 100644 index 000000000..68edd108f --- /dev/null +++ b/docs/MAINTENANCE-1.x.md @@ -0,0 +1,66 @@ +# Maintaining Cmder 1.x + +`legacy/1.x` keeps the ConEmu-based Cmder behavior available for selective fixes. +It has its own launcher, `vendor/init.bat`, build scripts and three archive names: +`cmder.zip`, `cmder.7z`, and `cmder_mini.zip`. New features target `main`. +`development` is historical and must not collect new work. + +The exact pre-integration master remains at +[`legacy/1.x-baseline-2026-11-10`](https://github.com/cmderdev/cmder/tree/legacy/1.x-baseline-2026-11-10), +commit `2b25c570a2b58c3c46b7f672a0a25677970aa9c7`. Maintenance changes advance +`legacy/1.x` normally; do not force-push the baseline or merge the entire current +line into it. + +## Prepare a backport + +1. Read the original issue, current-line fix, and review comments. +2. Preserve local edits, branches, and stashes. Use a separate source checkout + rather than building inside a daily Cmder installation. +3. Create a short branch from `origin/legacy/1.x`. Cherry-pick a compatible fix + with provenance, or make the smallest equivalent change for the old source. +4. Keep 1.x command paths, package names, user configuration and contributor credit. + Do not introduce the 2.0 generated-cache or Windows Terminal model as a backport. +5. Add a regression check for changed behavior and update `CHANGELOG.md`. +6. Send a PR to `legacy/1.x`, linking the original work and the checks performed. + +## Checks + +Use Visual Studio 2022/v143 and Windows SDK 10 for launcher changes. The CI builds +and runs the production-source launcher tests on Win32 and x64. Build helpers +and historical shell defaults are checked on Windows PowerShell 5.1 and 7. + +```powershell +.\scripts\check-trailing-whitespace.ps1 +.\scripts\test-update.ps1 +.\scripts\test-shell-detection.ps1 +.\scripts\test-build-helpers.ps1 +.\scripts\test-legacy-packaging.ps1 +.\scripts\build.ps1 -Compile -NoVendor -Verbose +git diff --check +``` + +For a release, run the full build and pack in that separate checkout. Independently +download and verify the tagged assets, SHA-256 manifest, archive contents and +versioned launcher. Check that every archive excludes Windows Terminal, Full +includes Git, Mini excludes Git, and private user configuration is absent. + +## Component and OS limits + +The selected Full package uses Git for Windows `2.56.0.windows.4` on x64 and +therefore requires Windows 10 or later. See the +[upstream requirements](https://gitforwindows.org/requirements.html). +The legacy startup paths retain support for older `mingw64`/`mingw32` layouts +alongside `ucrt64`. + +Mini leaves Git selection to the user. An external component's own OS and security +requirements still apply. A 1.x branch or a successful Win32 build does not prove +that the package works on Windows 7 or on a physical 32-bit/ARM machine. + +The TCC/TCCLE change restores the four previous shell-helper defaults removed by +`e3d9f81`, retaining user overrides and existing initialization behavior. It does +not require a new TCC installation or introduce a new shell policy. + +Current follow-ups remain in [David's backlog](https://github.com/cmderdev/cmder/issues/3133). +Use the [direct legacy/main comparison with whitespace hidden](https://github.com/cmderdev/cmder/compare/legacy%2F1.x..main?w=1) +to review porting differences. The [default-branch admin handoff](https://github.com/cmderdev/cmder/issues/3130) +is independent of maintenance releases. From 2ffe5b634bff0bfeea61d169ee17574326fc64f5 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:21:23 +0330 Subject: [PATCH 13/17] fix(legacy): support current Git UCRT64 layout Select native Git tools without changing the existing Bash or startup architecture. Adapt the reviewed current-line fixes from 4ffe73e9236531c08b71216961460eb583639d50 and 23a98193a509c3c2aa0d8deef237032c33d1662c; preserve native 32-bit and WoW64 selection and older MinGW support. --- CHANGELOG.md | 2 ++ vendor/init.bat | 21 +++++++++++---- vendor/profile.ps1 | 8 ++---- vendor/psmodules/Cmder.ps1 | 55 +++++++++++++++++++++++++++++--------- 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00e71d627..43d6b7014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ reject invalid arguments before attempting context-menu registration. - Restore the previous TCC and TCCLE shell-helper defaults for Clink and aliases, preserving explicit user settings and the existing `init.bat` behavior. +- Recognize the current Git UCRT64 layout in CMD and PowerShell while retaining + older MinGW layouts, native 32-bit and WoW64 selection, and external-Git preference. - Support Git repositories that use reftables in the Clink prompt. - Make Mercurial prompt updates asynchronous and fix its branch handling. - Quote Git locale paths, avoid temporary-file name collisions, and respect diff --git a/vendor/init.bat b/vendor/init.bat index bd5242f7b..e37e78531 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -323,16 +323,27 @@ if %nix_tools% equ 1 ( set "path_position=" ) +set "git_mingw_bin=" +set "git_native_64bit=1" +if /i "%PROCESSOR_ARCHITECTURE%" == "x86" if not defined PROCESSOR_ARCHITEW6432 set "git_native_64bit=0" +if "%git_native_64bit%" == "0" ( + if exist "%GIT_INSTALL_ROOT%\mingw32\bin" set "git_mingw_bin=%GIT_INSTALL_ROOT%\mingw32\bin" +) else if exist "%GIT_INSTALL_ROOT%\ucrt64\bin" ( + set "git_mingw_bin=%GIT_INSTALL_ROOT%\ucrt64\bin" +) else if exist "%GIT_INSTALL_ROOT%\mingw64\bin" ( + set "git_mingw_bin=%GIT_INSTALL_ROOT%\mingw64\bin" +) else if exist "%GIT_INSTALL_ROOT%\mingw32\bin" ( + set "git_mingw_bin=%GIT_INSTALL_ROOT%\mingw32\bin" +) +set "git_native_64bit=" + if %nix_tools% geq 1 ( - if exist "%GIT_INSTALL_ROOT%\mingw32" ( - %lib_path% enhance_path "%GIT_INSTALL_ROOT%\mingw32\bin" %path_position% - ) else if exist "%GIT_INSTALL_ROOT%\mingw64" ( - %lib_path% enhance_path "%GIT_INSTALL_ROOT%\mingw64\bin" %path_position% - ) + if defined git_mingw_bin %lib_path% enhance_path "%git_mingw_bin%" %path_position% if exist "%GIT_INSTALL_ROOT%\usr\bin" ( %lib_path% enhance_path "%GIT_INSTALL_ROOT%\usr\bin" %path_position% ) ) +set "git_mingw_bin=" :SET_ENV diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 72d5e503d..20001add0 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -71,13 +71,9 @@ foreach ($git in (Get-Command -ErrorAction SilentlyContinue 'git')) { # Use user installed Git if ($null -eq $gitPathUser) { - Write-Debug "Detected Git from mingw bin directory" + Write-Debug "Detected Git from PATH" Write-Debug "Git Dir: ${gitDir}" - 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) - } + $gitPathUser = Get-GitRoot -GitPath $gitDir Write-Debug "Git Path User: ${gitDir}" } diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 6de808e4b..f2eb23d8c 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -116,6 +116,40 @@ function Compare-GitVersion { return $VendorVersion } +function Get-GitRoot { + param( + [Parameter(Mandatory = $true)] + [string]$GitPath + ) + + $parent = Split-Path -Path $GitPath -Parent + $leaf = Split-Path -Path $GitPath -Leaf + if ($leaf -eq 'bin' -and (Split-Path -Path $parent -Leaf) -in @('ucrt64', 'mingw64', 'mingw32')) { + return Split-Path -Path $parent -Parent + } + if ($leaf -in @('cmd', 'bin')) { + return $parent + } + return $GitPath +} + +function Get-GitNativeBin { + param( + [Parameter(Mandatory = $true)] + [string]$GitRoot, + [bool]$Is64BitOperatingSystem = [Environment]::Is64BitOperatingSystem + ) + + $directories = if ($Is64BitOperatingSystem) { @('ucrt64', 'mingw64', 'mingw32') } else { @('mingw32') } + foreach ($directory in $directories) { + $nativeBin = Join-Path $GitRoot "$directory\bin" + if (Test-Path -LiteralPath $nativeBin -PathType Container) { + return $nativeBin + } + } + return $null +} + function Set-GitPath { param( [Parameter(Mandatory = $true)] @@ -138,11 +172,16 @@ function Set-GitPath { } $newPath = $env:Path + $nativeBin = Get-GitNativeBin -GitRoot $GitRoot # 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 + if ($nativeBin) { + $nativePattern = [regex]::Escape($GitRoot) + '\\(?:ucrt64|mingw64|mingw32)\\bin(?=;|$)' + $newPath = [regex]::Replace($newPath, $nativePattern, { param($match) $nativeBin }, [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) + } } else { # Add Git cmd directory to the path $gitCmd = Join-Path $GitRoot "cmd" @@ -151,18 +190,10 @@ function Set-GitPath { $newPath = "$gitCmd;$newPath" } - # Add mingw[32|64]\bin directories to the path, if they exist and not already present - # 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" - $newPath = "$newPath;$mingwBin" - break - } + # Prefer the current UCRT64 directory, with older MinGW layouts as fallbacks. + if ($nativeBin -and -not ($newPath -match [regex]::Escape($nativeBin))) { + Write-Debug "Adding $nativeBin to the path" + $newPath = "$newPath;$nativeBin" } # Add usr\bin directory to the path From 6cd94a5e00729566c1c8a10a855376c37686e733 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:22:37 +0330 Subject: [PATCH 14/17] test(legacy): verify Git native layouts without changing Bash policy Exercise production PowerShell helpers and the actual init.bat native-bin selection across UCRT64, MinGW64, MinGW32, mixed and absent layouts, including native32 and WoW64. Preserve legacy Bash portable-bin behavior and syntax. All94 assertions pass under Windows PowerShell5.1 and7; run both in CI. --- .github/workflows/tests.yml | 8 ++ CHANGELOG.md | 2 + scripts/test-git-layout.ps1 | 152 ++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 scripts/test-git-layout.ps1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b7190a5ec..d518861cb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,6 +58,14 @@ jobs: shell: pwsh run: .\scripts\test-shell-detection.ps1 + - name: Test legacy Git layouts + shell: pwsh + run: .\scripts\test-git-layout.ps1 + + - name: Test legacy Git layouts on Windows PowerShell 5.1 + shell: powershell + run: .\scripts\test-git-layout.ps1 + - name: Test legacy package contents shell: pwsh run: .\scripts\test-legacy-packaging.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d6b7014..15cc22a55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ preserving explicit user settings and the existing `init.bat` behavior. - Recognize the current Git UCRT64 layout in CMD and PowerShell while retaining older MinGW layouts, native 32-bit and WoW64 selection, and external-Git preference. + Check the production helpers and `init.bat` selection with layout fixtures on + PowerShell 5.1 and 7, keeping the existing Bash initialization policy. - Support Git repositories that use reftables in the Clink prompt. - Make Mercurial prompt updates asynchronous and fix its branch handling. - Quote Git locale paths, avoid temporary-file name collisions, and respect diff --git a/scripts/test-git-layout.ps1 b/scripts/test-git-layout.ps1 new file mode 100644 index 000000000..47a3b1761 --- /dev/null +++ b/scripts/test-git-layout.ps1 @@ -0,0 +1,152 @@ +[CmdletBinding()] +param( + [string]$BashExecutable = "$env:ProgramFiles\Git\usr\bin\bash.exe", + [string]$RepositoryRoot = '' +) + +$ErrorActionPreference = 'Stop' +if (!$RepositoryRoot) { $RepositoryRoot = Split-Path $PSScriptRoot -Parent } +$repoRoot = [IO.Path]::GetFullPath($RepositoryRoot) +$tokens = $null +$parseErrors = $null +$modulePath = Join-Path $repoRoot 'vendor\psmodules\Cmder.ps1' +$ast = [System.Management.Automation.Language.Parser]::ParseFile($modulePath, [ref]$tokens, [ref]$parseErrors) +if ($parseErrors.Count) { throw $parseErrors[0].Message } +foreach ($name in @('Get-GitRoot', 'Get-GitNativeBin', 'Set-GitPath')) { + $definition = $ast.Find({ + $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $args[0].Name -eq $name + }, $true) + if (!$definition) { throw "Missing production function: $name" } + . ([scriptblock]::Create($definition.Extent.Text)) +} + +$script:assertionCount = 0 +function Assert-Equal($Actual, $Expected, [string]$Label) { + if ([string]$Actual -cne [string]$Expected) { + throw "${Label}: expected '$Expected', got '$Actual'." + } + $script:assertionCount++ +} + +if (!(Test-Path -LiteralPath $BashExecutable -PathType Leaf)) { + throw "Git Bash is required; provide -BashExecutable. Not found: $BashExecutable" +} +$cygpath = Join-Path (Split-Path $BashExecutable -Parent) 'cygpath.exe' +if (!(Test-Path -LiteralPath $cygpath -PathType Leaf)) { throw "Not found: $cygpath" } +$bashSource = [IO.File]::ReadAllText((Join-Path $repoRoot 'vendor\cmder.sh')) +# The 1.x Bash profile keeps its existing portable bin policy. It has no native +# MinGW/UCRT selection block; do not import the 2.x initialization model here. +$bashMatch = [regex]::Match($bashSource, '(?ms)^if \[\[ ! "\$PATH" =~ "\$\{GIT_INSTALL_ROOT\}/bin:" \]\] ; then\r?\n.*?^fi\r?$') +if (!$bashMatch.Success) { throw 'Cannot locate the legacy Git bin PATH block in cmder.sh.' } +if ($bashSource -match '(?i)(?:mingw32|mingw64|ucrt64)[\\/]bin') { + throw 'The legacy Bash profile must not hardcode a Git native directory.' +} +$cmdSource = 'vendor\init.bat' +$sourceText = [IO.File]::ReadAllText((Join-Path $repoRoot $cmdSource)) +$selection = [regex]::Match($sourceText, '(?ms)^\s*set "git_mingw_bin="\r?\n.*?^\s*set "git_native_64bit="\r?$') +if (!$selection.Success) { throw 'Cannot locate Git native-bin selection in vendor/init.bat.' } + +$tempParent = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()) +$fixtureRoot = Join-Path $tempParent ('cmder-git-layout-' + [guid]::NewGuid().ToString('N')) +$savedPath = $env:Path +$savedGitRoot = $env:GIT_INSTALL_ROOT +$savedArchitecture = $env:PROCESSOR_ARCHITECTURE +$savedWow64Architecture = $env:PROCESSOR_ARCHITEW6432 +try { + $null = New-Item -ItemType Directory -Path $fixtureRoot + $cases = @( + @{ Name = 'UCRT64 only'; Dirs = @('ucrt64'); Native = 'ucrt64' }, + @{ Name = 'MinGW64 only'; Dirs = @('mingw64'); Native = 'mingw64' }, + @{ Name = 'MinGW32 only'; Dirs = @('mingw32'); Native = 'mingw32' }, + @{ Name = 'Mixed layouts'; Dirs = @('ucrt64', 'mingw64', 'mingw32'); Native = 'ucrt64' }, + @{ Name = 'Older mixed layouts'; Dirs = @('mingw64', 'mingw32'); Native = 'mingw64' }, + @{ Name = 'No native directory'; Dirs = @(); Native = '' } + ) + $basePath = 'C:\Windows\System32' + foreach ($case in $cases) { + $gitRoot = Join-Path $fixtureRoot $case.Name + foreach ($directory in @('cmd', 'bin', 'usr\bin') + @($case.Dirs | ForEach-Object { "$_\bin" })) { + $null = New-Item -ItemType Directory -Path (Join-Path $gitRoot $directory) -Force + } + # A directory without bin is not a usable native-tool layout. + $null = New-Item -ItemType Directory -Path (Join-Path $gitRoot 'unused\bin') -Force + if (!$case.Native) { $null = New-Item -ItemType Directory -Path (Join-Path $gitRoot 'mingw64') } + $native = if ($case.Native) { Join-Path $gitRoot ($case.Native + '\bin') } else { '' } + $native32 = if ($case.Dirs -contains 'mingw32') { Join-Path $gitRoot 'mingw32\bin' } else { '' } + Assert-Equal (Get-GitNativeBin -GitRoot $gitRoot -Is64BitOperatingSystem $true) $native "$($case.Name) PowerShell native bin on 64-bit OS" + Assert-Equal (Get-GitNativeBin -GitRoot $gitRoot -Is64BitOperatingSystem $false) $native32 "$($case.Name) PowerShell native bin on 32-bit OS" + $hostNative = if ([Environment]::Is64BitOperatingSystem) { $native } else { $native32 } + Assert-Equal (Get-GitNativeBin -GitRoot $gitRoot) $hostNative "$($case.Name) PowerShell native bin on current OS" + foreach ($directory in @('cmd', 'bin') + @($case.Dirs | ForEach-Object { "$_\bin" })) { + Assert-Equal (Get-GitRoot -GitPath (Join-Path $gitRoot $directory)) $gitRoot "$($case.Name) root from $directory" + } + Assert-Equal (Get-GitRoot -GitPath $gitRoot) $gitRoot "$($case.Name) root remains unchanged" + $env:Path = $basePath + $expected = (Join-Path $gitRoot 'cmd') + ';' + $basePath + if ($hostNative) { $expected += ';' + $hostNative } + $expected += ';' + (Join-Path $gitRoot 'usr\bin') + Assert-Equal (Set-GitPath -GitRoot $gitRoot -GitType 'VENDOR') $expected "$($case.Name) vendored PATH" + $env:Path = $expected + Assert-Equal (Set-GitPath -GitRoot $gitRoot -GitType 'VENDOR') $expected "$($case.Name) no duplicate PATH" + $env:Path = $basePath + Assert-Equal (Set-GitPath -GitRoot $gitRoot -GitType 'USER') $basePath "$($case.Name) preserves user-selected PATH" + $env:Path = $savedPath + + $env:GIT_INSTALL_ROOT = $gitRoot + foreach ($source in @($cmdSource)) { + $cmdFile = Join-Path $fixtureRoot 'select-native.cmd' + $architectures = @( + @{ Name = 'native64'; Process = 'AMD64'; Wow64 = ''; Native = $native }, + @{ Name = 'native32'; Process = 'x86'; Wow64 = ''; Native = $native32 }, + @{ Name = 'WoW64'; Process = 'x86'; Wow64 = 'AMD64'; Native = $native } + ) + foreach ($architecture in $architectures) { + $env:PROCESSOR_ARCHITECTURE = $architecture.Process + $env:PROCESSOR_ARCHITEW6432 = $architecture.Wow64 + # cmd.exe restores its real architecture on launch; set the fixture inside the child. + $cmdText = "@echo off`r`nset `"PROCESSOR_ARCHITECTURE=$($architecture.Process)`"`r`nset `"PROCESSOR_ARCHITEW6432=$($architecture.Wow64)`"`r`n" + $selection.Value + "`r`necho LAYOUT[%git_mingw_bin%]`r`n" + [IO.File]::WriteAllText($cmdFile, $cmdText, [Text.Encoding]::ASCII) + $actual = & $env:ComSpec /d /c "`"$cmdFile`"" + if ($LASTEXITCODE) { throw "CMD selection failed: $source" } + Assert-Equal $actual "LAYOUT[$($architecture.Native)]" "$($case.Name) $source ($($architecture.Name))" + } + } + $bashFile = Join-Path $fixtureRoot 'select-legacy-bin.sh' + $bashText = 'GIT_INSTALL_ROOT="$1"' + "`n" + 'PATH="$2"' + "`n" + $bashMatch.Value + "`n" + 'printf ''%s\n'' "$PATH"' + "`n" + [IO.File]::WriteAllText($bashFile, ($bashText -replace "`r`n", "`n"), (New-Object Text.UTF8Encoding($false))) + $posixGitRoot = & $cygpath -u $gitRoot + $posixScript = & $cygpath -u $bashFile + $expectedBash = "$posixGitRoot/bin" + ':/layout-test-base' + $actual = & $BashExecutable --noprofile --norc $posixScript $posixGitRoot '/layout-test-base' + if ($LASTEXITCODE) { throw 'Legacy Bash bin selection failed.' } + Assert-Equal $actual $expectedBash "$($case.Name) legacy Bash portable bin PATH" + $actual = & $BashExecutable --noprofile --norc $posixScript $posixGitRoot $expectedBash + if ($LASTEXITCODE) { throw 'Legacy Bash existing PATH check failed.' } + Assert-Equal $actual $expectedBash "$($case.Name) legacy Bash no duplicate bin PATH" + } + + $newRoot = Join-Path $fixtureRoot 'UCRT64 only' + $oldRoot = Join-Path $fixtureRoot 'Old Git' + $env:Path = "$basePath;$oldRoot\cmd;$oldRoot\mingw64\bin;$oldRoot\usr\bin" + if ([Environment]::Is64BitOperatingSystem) { + $expected = "$basePath;$newRoot\cmd;$newRoot\ucrt64\bin;$newRoot\usr\bin" + Assert-Equal (Set-GitPath -GitRoot $newRoot -GitType 'VENDOR' -GitPathUser $oldRoot) $expected 'Migrates an older MinGW PATH to UCRT64 in the same position' + } + + $env:Path = $savedPath + $posixSource = & $cygpath -u (Join-Path $repoRoot 'vendor\cmder.sh') + & $BashExecutable -n $posixSource + Assert-Equal $LASTEXITCODE 0 'Full cmder.sh Bash syntax' +} finally { + $env:Path = $savedPath + $env:GIT_INSTALL_ROOT = $savedGitRoot + $env:PROCESSOR_ARCHITECTURE = $savedArchitecture + $env:PROCESSOR_ARCHITEW6432 = $savedWow64Architecture + $resolved = [IO.Path]::GetFullPath($fixtureRoot) + if (!$resolved.StartsWith($tempParent, [StringComparison]::OrdinalIgnoreCase) -or + !(Split-Path $resolved -Leaf).StartsWith('cmder-git-layout-')) { + throw "Refusing to remove unexpected fixture directory: $resolved" + } + if (Test-Path -LiteralPath $resolved) { Remove-Item -LiteralPath $resolved -Recurse -Force } +} +Write-Output "Legacy Git directory-layout tests passed ($script:assertionCount assertions)." From 7cb64c49fdbdbe42663406cc8bb42d7681af349e Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:24:57 +0330 Subject: [PATCH 15/17] fix(legacy): derive product versions only from release tags Keep archival baseline tags intact while restricting git describe to v-prefixed numeric release tags. Add an isolated two-commit fixture proving a closer preservation tag cannot replace the earlier release version. All29 build-helper cases pass on Windows PowerShell5.1 and7 without changing user identity, signing, or hook configuration. --- scripts/test-build-helpers.ps1 | 20 ++++++++++++++++++++ scripts/utils.ps1 | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/test-build-helpers.ps1 b/scripts/test-build-helpers.ps1 index b89651a2e..caa24ca0b 100644 --- a/scripts/test-build-helpers.ps1 +++ b/scripts/test-build-helpers.ps1 @@ -103,6 +103,26 @@ try { if ($version -notmatch '^\d+\.\d+' -or $ErrorActionPreference -ne 'Stop') { throw 'Version fallback in an untagged Git repository failed or changed error handling.' } + + # An archival tag on a newer commit must not replace the release version. + # Keep identity and hooks local to these commands; never change user config. + $emptyHooks = Join-Path $testRoot 'empty-hooks' + $null = New-Item -ItemType Directory -Path $emptyHooks + $fixtureConfig = @('-c', 'user.name=Cmder Test Fixture', '-c', 'user.email=fixture@example.invalid', + '-c', "core.hooksPath=$emptyHooks", '-c', 'tag.gpgSign=false') + $null = & git.exe @fixtureConfig commit --allow-empty --no-gpg-sign --quiet -m 'Release fixture' + if ($LASTEXITCODE -ne 0) { throw 'Unable to create the release-version fixture.' } + $null = & git.exe @fixtureConfig tag v9.8.7 + if ($LASTEXITCODE -ne 0) { throw 'Unable to tag the release-version fixture.' } + $null = & git.exe @fixtureConfig commit --allow-empty --no-gpg-sign --quiet -m 'Archival fixture' + if ($LASTEXITCODE -ne 0) { throw 'Unable to create the archival-version fixture.' } + $null = & git.exe @fixtureConfig tag archive-fixture + if ($LASTEXITCODE -ne 0) { throw 'Unable to tag the archival-version fixture.' } + $version = Get-VersionStr + if ($version -notmatch '^9\.8\.7(?:\.|\z)' -or $ErrorActionPreference -ne 'Stop') { + throw "A closer archival tag replaced the earlier release version: $version" + } + $cases++ } finally { Pop-Location } diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index 039d24401..24c223855 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -162,7 +162,8 @@ function Get-VersionStr { $ErrorActionPreference = 'Continue' $GitPresent = & git.exe rev-parse --is-inside-work-tree 2>$null if ($LASTEXITCODE -eq 0 -and $GitPresent -eq 'true') { - $candidate = & git.exe describe --abbrev=0 --tags 2>$null + # Preservation tags describe history, not the product version. + $candidate = & git.exe describe --abbrev=0 --tags --match 'v[0-9]*' 2>$null if ($LASTEXITCODE -eq 0) { $string = $candidate } From 2eb8b2fc31cc8accd8e0f065f867e74a3372e538 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:27:16 +0330 Subject: [PATCH 16/17] docs(legacy): prepare the 1.3.26 maintenance release --- CHANGELOG.md | 6 +++--- README.md | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15cc22a55..a2a7108ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [1.3.26](https://github.com/cmderdev/cmder/compare/v1.3.25...legacy/1.x) (UNRELEASED) +## [1.3.26](https://github.com/cmderdev/cmder/releases/tag/v1.3.26) (2026-11-10) ### Maintenance scope @@ -44,8 +44,8 @@ Embedded components have their own Windows requirements; a 1.x archive does not imply Windows 7 support. See the [Git for Windows requirements](https://gitforwindows.org/requirements.html). -- This section records unreleased work. A final release must document the actual - selected component versions and archive verification. +- The release notes record the selected components and the independent checks + of the tagged archives, versioned launcher, and shell startup. ## [1.3.25](https://github.com/cmderdev/cmder/tree/v1.3.25) (2024-05-31) diff --git a/README.md b/README.md index 33dae372e..db34f15b1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ This is the `legacy/1.x` maintenance line. Current Cmder development and the 2.x releases are on [`main`](https://github.com/cmderdev/cmder/tree/main). This branch keeps the ConEmu launcher, `vendor\init.bat`, and the existing Full (`cmder.zip`, `cmder.7z`) and Mini (`cmder_mini.zip`) archive names. -See the [unreleased 1.3.26 notes](CHANGELOG.md) for the maintenance changes. +See the [1.3.26 maintenance notes](CHANGELOG.md) and +[backport guide](docs/MAINTENANCE-1.x.md) for this line's changes and checks. [![Join the chat at https://gitter.im/cmderdev/cmder](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cmderdev/cmder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://github.com/cmderdev/cmder/actions/workflows/build.yml/badge.svg?branch=legacy%2F1.x)](https://github.com/cmderdev/cmder/actions/workflows/build.yml?query=event%3Apush+branch%3Alegacy%2F1.x) From bf3eed93e81d34085e89e71a0b27fc35ce3db72d Mon Sep 17 00:00:00 2001 From: David Refoua Date: Tue, 10 Nov 2026 05:29:56 +0330 Subject: [PATCH 17/17] docs(legacy): include Git layout verification in maintenance checks --- docs/MAINTENANCE-1.x.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/MAINTENANCE-1.x.md b/docs/MAINTENANCE-1.x.md index 68edd108f..104753612 100644 --- a/docs/MAINTENANCE-1.x.md +++ b/docs/MAINTENANCE-1.x.md @@ -33,6 +33,7 @@ and historical shell defaults are checked on Windows PowerShell 5.1 and 7. .\scripts\check-trailing-whitespace.ps1 .\scripts\test-update.ps1 .\scripts\test-shell-detection.ps1 +.\scripts\test-git-layout.ps1 .\scripts\test-build-helpers.ps1 .\scripts\test-legacy-packaging.ps1 .\scripts\build.ps1 -Compile -NoVendor -Verbose