Repository navigation
msal: restore visible console parenting on Windows - #2464
Merged
Merged
Conversation
Ensure that we only consider a console window (or hosting terminal in case of ConPTY) a valid parent for MSAL windows if it is visible. This will prevent MSAL windows from being hidden too. Note that we do **not** apply the visibility check to the optional explicitly provided parent window (via `GCM_MODEL_PARENTHWND)` - the caller should be the one to decide if their handle is good to use or not. Finally, note that we do **not** check for a minimised parent window (via `IsIconic(HWND)`) because we should probably also remain minimised if our parent was. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Extract the console parent lookup logic to a static method in preparation for allowing tests to mock it. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Allow testing of the parent window adapter by allowing mocks of the core platform-specific APIs: * creation of stub window * window visibilty checking * get console window Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
In previous versions of GCM (2.x) we preferred to parent MSAL windows to the console window, if possible, over creating our own stub 'progress' window. In GCM 3.0.0 we accidentally reversed that preference, which means in practice we always used the stub window and never the console window. Let's reverse that back to the desired order: 1. Explicit parent (via `GCM_MODAL_PARENTHWND`) 2. Console window parent (if present and visible) 3. Stub progress window (if required by the caller) 4. None Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Add comprehensive tests of the MSAL parent window adapter, and the precedence logic for selecting (and creating) an appropriate parent window. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
dscho
approved these changes
Oct 5, 2026
mjcheetham
added a commit
that referenced
this pull request
Oct 5, 2026
This follows up on #2464. Visible-console parenting currently lives inside the MSAL adapter, so _other_ in-process authentication dialogs remain unparented unless `GCM_MODAL_PARENTHWND` is supplied. Those prompts can appear disconnected from the terminal that initiated the Git operation. This PR moves console-parent discovery into a shared platform helper and uses it in the authentication and UI-helper parent handle lookups. This extends the fallback beyond MSAL while keeping the two lookup paths consistent. MSAL retains responsibility for creating a progress window when broker authentication requires a parent and no usable handle was resolved. Explicit HWNDs still take precedence and are not visibility-filtered. Automatically discovered owners must be visible, with visibility checked after resolving the console's root owner to accommodate ConPTY compatibility windows. Update the environment variable documentation to describe the fallback to the console-parent window. Tested behaviour on Windows Terminal, conhost.exe (classic terminal host), and Git Bash/MSYS2's terminal.
Merged
mjcheetham
added a commit
that referenced
this pull request
Oct 6, 2026
**Bug Fixes:** - Prompt for default OS account on Microsoft DevBox (#2459) - Restore Entra broker parent window handling (#2464) **Features:** - Support `authtype` Git capability (#2457) - Add console parent window parenting for non-Entra UI (#2465) **Other changes:** - Drop Windows x86 release binaries (#2456) - Documentation updates (#2460) - Fix release workflow _VERSION_ file parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Windows authentication dialogs need an appropriate parent window, but Git is not always launched from a visible terminal. GUI applications and background processes can retain a hidden console with a valid HWND. Automatically selecting that invisible owner can leave authentication UI out of view, making the operation appear stalled while it waits for credentials.
GCM 3.0 also accidentally reversed the parent-selection preference used in 2.x: interactive Windows broker authentication creates a progress window before considering an existing console owner. This introduces unnecessary temporary UI and disconnects authentication dialogs from the terminal that initiated the operation.
This PR restores console-first parenting while rejecting invisible automatically discovered owners. The selection order becomes:
GCM_MODAL_PARENTHWND.IsWindowVisiblereturns true.The visibility check applies after walking the window parent/owner chain. This matters for ConPTY, where the console HWND may be a hidden compatibility window while its root owner is the visible terminal.
Explicit HWNDs remain the caller’s responsibility and are not visibility-filtered. Minimised owners also remain eligible: this change deliberately does not add an
IsIconiccheck or replace a minimised owner with an independent progress window.The series adds regression coverage for parent precedence, hidden or missing owners, and progress-window cleanup, and documents
GCM_MODAL_PARENTHWNDfor applications integrating Git into their own GUI.