fix(cli): prevent panic when askpass broker is not initialized #12327
+34
−15
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.
Summary
but pull(and other CLI operations requiring SSH auth) panics withaskpass broker not initializedwhen running outside the GUIget_broker()now returnsOptioninstead of panicking, and all call sites gracefully handle the uninitialized caseProblem
The askpass broker handles SSH credential prompts (passphrase, auth tokens) by forwarding them to the GUI as Tauri events. It's stored in a global static and initialized in
crates/gitbutler-tauri/src/main.rsduring the Taurisetuphook.When the same binary runs as a CLI (
but pull,but push, etc.), the early-return at the CLI entry point skips the Tauri setup, leaving the broker uninitialized. Any git operation that triggers an SSH prompt then callsget_broker()which panics:Fix
get_broker()now returnsOption<&'static AskpassBroker>instead of unwrapping:All 4 call sites updated to handle
None:handle_git_prompt_push— returnsNone(auth fails gracefully)handle_git_prompt_fetch— returnsNone(auth fails gracefully)handle_git_prompt_clone— returnsNone(auth fails gracefully)submit_prompt_response— logs warning and no-opsThis means CLI operations that don't need credentials continue to work normally, and operations that need credentials fail with a proper authentication error instead of crashing the process.
Test plan
but pullwith a public repo works without panicbut pullwith a password-protected SSH key returns an authentication error instead of panickingcargo clippy -p but-api— passes cleanFixes #12279