@@ -189,13 +189,14 @@ impl State {
189189 current_upstream : Option < String > ,
190190 branch_name : String ,
191191 ) -> Result < ( ) > {
192- let trunk = git_trunk ( git_repo) ?;
193192 // Ensure the main branch is in the git-stack tree for this repo if we haven't
194- // added it yet.
195- self . repos
196- . entry ( repo. to_string ( ) )
197- . or_insert_with ( || RepoState :: new ( Branch :: new ( trunk. main_branch . clone ( ) , None ) ) ) ;
198- self . save_state ( ) ?;
193+ // added it yet (only if we have a remote configured).
194+ if let Some ( trunk) = git_trunk ( git_repo) {
195+ self . repos
196+ . entry ( repo. to_string ( ) )
197+ . or_insert_with ( || RepoState :: new ( Branch :: new ( trunk. main_branch . clone ( ) , None ) ) ) ;
198+ self . save_state ( ) ?;
199+ }
199200
200201 let branch_exists_in_tree = self . branch_exists_in_tree ( repo, & branch_name) ;
201202 let branch_exists_locally = git_branch_exists ( git_repo, & branch_name) ;
@@ -574,15 +575,15 @@ impl State {
574575 Ok ( ( ) )
575576 }
576577
577- pub ( crate ) fn ensure_trunk ( & mut self , git_repo : & GitRepo , repo : & str ) -> Result < GitTrunk > {
578+ pub ( crate ) fn ensure_trunk ( & mut self , git_repo : & GitRepo , repo : & str ) -> Option < GitTrunk > {
578579 let trunk = git_trunk ( git_repo) ?;
579580 // The branch might not exist in git, let's create it, and add it to the tree.
580581 // Ensure the main branch is in the git-stack tree for this repo if we haven't
581582 // added it yet.
582583 self . repos
583584 . entry ( repo. to_string ( ) )
584585 . or_insert_with ( || RepoState :: new ( Branch :: new ( trunk. main_branch . clone ( ) , None ) ) ) ;
585- Ok ( trunk)
586+ Some ( trunk)
586587 }
587588
588589 pub ( crate ) fn mount (
@@ -592,16 +593,20 @@ impl State {
592593 branch_name : & str ,
593594 parent_branch : Option < String > ,
594595 ) -> Result < ( ) > {
595- let trunk = self . ensure_trunk ( git_repo, repo) ? ;
596+ let trunk = self . ensure_trunk ( git_repo, repo) ;
596597
597- if trunk. main_branch == branch_name {
598- bail ! (
599- "Branch {branch_name} cannot be stacked on anything else." ,
600- branch_name = branch_name. red( )
601- ) ;
598+ if let Some ( ref trunk) = trunk {
599+ if trunk. main_branch == branch_name {
600+ bail ! (
601+ "Branch {branch_name} cannot be stacked on anything else." ,
602+ branch_name = branch_name. red( )
603+ ) ;
604+ }
602605 }
603606
604- let parent_branch = parent_branch. unwrap_or ( trunk. main_branch ) ;
607+ let parent_branch = parent_branch
608+ . or_else ( || trunk. map ( |t| t. main_branch ) )
609+ . ok_or_else ( || anyhow ! ( "No parent branch specified and no remote configured" ) ) ?;
605610
606611 if branch_name == parent_branch {
607612 bail ! (
@@ -678,7 +683,9 @@ impl State {
678683 // For each sub-branch in the tree, check if the parent
679684
680685 tracing:: debug!( "Refreshing lkgs for all branches..." ) ;
681- let trunk = git_trunk ( git_repo) ?;
686+ let Some ( trunk) = git_trunk ( git_repo) else {
687+ return Ok ( ( ) ) ;
688+ } ;
682689
683690 let mut parent_lkgs: HashMap < String , Option < String > > = HashMap :: default ( ) ;
684691
@@ -800,8 +807,8 @@ impl State {
800807 repo : & str ,
801808 branch_name : & str ,
802809 ) -> Result < bool > {
803- // Ensure the tree exists for this repo
804- self . ensure_trunk ( git_repo, repo) ? ;
810+ // Ensure the tree exists for this repo (no-op if no remote)
811+ self . ensure_trunk ( git_repo, repo) ;
805812
806813 // Check if the branch is already in the tree
807814 if self . branch_exists_in_tree ( repo, branch_name) {
@@ -813,8 +820,10 @@ impl State {
813820 bail ! ( "Branch {branch_name} does not exist in git" ) ;
814821 }
815822
816- // Get the tree for this repo (guaranteed to exist after ensure_trunk)
817- let tree = self . get_tree ( repo) . expect ( "tree exists after ensure_trunk" ) ;
823+ // Get the tree for this repo (may not exist if no remote configured)
824+ let Some ( tree) = self . get_tree ( repo) else {
825+ return Ok ( false ) ;
826+ } ;
818827
819828 // Collect all mounted branches
820829 let mut all_branches = Vec :: new ( ) ;
@@ -831,7 +840,10 @@ impl State {
831840 // Determine the parent branch
832841 let parent_branch = if ancestor_branches. is_empty ( ) {
833842 // No ancestors found, default to the trunk/main branch
834- let trunk = git_trunk ( git_repo) ?;
843+ let Some ( trunk) = git_trunk ( git_repo) else {
844+ // No remote configured and no ancestor branches - can't auto-mount
845+ return Ok ( false ) ;
846+ } ;
835847 tracing:: info!(
836848 "No mounted ancestor branches found for {}. Defaulting to trunk branch {}." ,
837849 branch_name,
0 commit comments