@@ -114,25 +114,35 @@ func runRebase(cfg *config.Config, opts *rebaseOptions) error {
114114 // Enable git rerere so conflict resolutions are remembered.
115115 _ = git .EnableRerere ()
116116
117- if err := git .Fetch ("origin" ); err != nil {
118- cfg .Warningf ("Failed to fetch origin: %v" , err )
117+ // Resolve remote for fetch and trunk comparison
118+ remote , err := pickRemote (cfg , currentBranch )
119+ if err != nil {
120+ cfg .Errorf ("%s" , err )
121+ return nil
122+ }
123+
124+ if err := git .Fetch (remote ); err != nil {
125+ cfg .Warningf ("Failed to fetch %s: %v" , remote , err )
119126 } else {
120- cfg .Successf ("Fetched origin" )
127+ cfg .Successf ("Fetched %s" , remote )
121128 }
122129
123130 // Fast-forward trunk so the cascade rebase targets the latest upstream.
124131 trunk := s .Trunk .Branch
125- localSHA , localErr := git .HeadSHA (trunk )
126- remoteSHA , remoteErr := git .HeadSHA ("origin/" + trunk )
132+ localSHA , remoteSHA := "" , ""
133+ trunkRefs , trunkErr := git .RevParseMulti ([]string {trunk , remote + "/" + trunk })
134+ if trunkErr == nil {
135+ localSHA , remoteSHA = trunkRefs [0 ], trunkRefs [1 ]
136+ }
127137
128- if localErr == nil && remoteErr == nil && localSHA != remoteSHA {
138+ if trunkErr == nil && localSHA != remoteSHA {
129139 isAncestor , err := git .IsAncestor (localSHA , remoteSHA )
130140 if err != nil {
131141 cfg .Warningf ("Could not determine fast-forward status for %s: %v" , trunk , err )
132142 } else if ! isAncestor {
133- cfg .Warningf ("Trunk %s has diverged from origin — skipping trunk update" , trunk )
143+ cfg .Warningf ("Trunk %s has diverged from %s — skipping trunk update" , trunk , remote )
134144 } else if currentBranch == trunk {
135- if err := ffMerge ( trunk ); err != nil {
145+ if err := git . MergeFF ( remote + "/" + trunk ); err != nil {
136146 cfg .Warningf ("Failed to fast-forward %s: %v" , trunk , err )
137147 } else {
138148 cfg .Successf ("Trunk %s fast-forwarded to %s" , trunk , short (remoteSHA ))
@@ -184,14 +194,14 @@ func runRebase(cfg *config.Config, opts *rebaseOptions) error {
184194 // Sync PR state before rebase so we can detect merged PRs.
185195 syncStackPRs (cfg , s )
186196
187- originalRefs := make (map [ string ]string )
188- for _ , b := range s .Branches {
189- sha , err := git . HeadSHA ( b .Branch )
190- if err != nil {
191- cfg . Errorf ( "failed to resolve HEAD SHA for %s: %s" , b . Branch , err )
192- return nil
193- }
194- originalRefs [ b . Branch ] = sha
197+ branchNames := make ([ ]string , len ( s . Branches ) )
198+ for i , b := range s .Branches {
199+ branchNames [ i ] = b .Branch
200+ }
201+ originalRefs , err := git . RevParseMap ( branchNames )
202+ if err != nil {
203+ cfg . Errorf ( "failed to resolve branch SHAs: %s" , err )
204+ return nil
195205 }
196206
197207 // Track --onto rebase state for squash-merged branches.
@@ -312,25 +322,7 @@ func runRebase(cfg *config.Config, opts *rebaseOptions) error {
312322
313323 _ = git .CheckoutBranch (currentBranch )
314324
315- for i := range s .Branches {
316- // Skip merged branches when updating base SHAs.
317- if s .Branches [i ].IsMerged () {
318- continue
319- }
320- // Find the first non-merged ancestor, or trunk.
321- parent := s .Trunk .Branch
322- for j := i - 1 ; j >= 0 ; j -- {
323- if ! s .Branches [j ].IsMerged () {
324- parent = s .Branches [j ].Branch
325- break
326- }
327- }
328- base , _ := git .HeadSHA (parent )
329- s .Branches [i ].Base = base
330- if head , err := git .HeadSHA (s .Branches [i ].Branch ); err == nil {
331- s .Branches [i ].Head = head
332- }
333- }
325+ updateBaseSHAs (s )
334326
335327 syncStackPRs (cfg , s )
336328
@@ -521,25 +513,7 @@ func continueRebase(cfg *config.Config, gitDir string) error {
521513 clearRebaseState (gitDir )
522514 _ = git .CheckoutBranch (state .OriginalBranch )
523515
524- for i := range s .Branches {
525- // Skip merged branches when updating base SHAs.
526- if s .Branches [i ].IsMerged () {
527- continue
528- }
529- // Find the first non-merged ancestor, or trunk.
530- parent := s .Trunk .Branch
531- for j := i - 1 ; j >= 0 ; j -- {
532- if ! s .Branches [j ].IsMerged () {
533- parent = s .Branches [j ].Branch
534- break
535- }
536- }
537- base , _ := git .HeadSHA (parent )
538- s .Branches [i ].Base = base
539- if head , err := git .HeadSHA (s .Branches [i ].Branch ); err == nil {
540- s .Branches [i ].Head = head
541- }
542- }
516+ updateBaseSHAs (s )
543517
544518 syncStackPRs (cfg , s )
545519
0 commit comments