@@ -209,77 +209,85 @@ public void Select(IList commits)
209209 }
210210 }
211211
212- public void DoubleTapped ( Models . Commit commit , Models . Decorator decorator = null )
212+ public bool CheckoutBranchByDecorator ( Models . Decorator decorator )
213213 {
214- if ( decorator != null )
214+ if ( decorator == null )
215+ return false ;
216+
217+ if ( decorator . Type == Models . DecoratorType . CurrentBranchHead ||
218+ decorator . Type == Models . DecoratorType . CurrentCommitHead )
219+ return true ;
220+
221+ if ( decorator . Type == Models . DecoratorType . LocalBranchHead )
222+ {
223+ var b = _repo . Branches . Find ( x => x . Name == decorator . Name ) ;
224+ if ( b == null )
225+ return false ;
226+
227+ _repo . CheckoutBranch ( b ) ;
228+ return true ;
229+ }
230+
231+ if ( decorator . Type == Models . DecoratorType . RemoteBranchHead )
215232 {
216- if ( decorator . Type == Models . DecoratorType . LocalBranchHead )
233+ var rb = _repo . Branches . Find ( x => x . FriendlyName == decorator . Name ) ;
234+ if ( rb == null )
235+ return false ;
236+
237+ var lb = _repo . Branches . Find ( x => x . IsLocal && x . Upstream == rb . FullName ) ;
238+ if ( lb == null || lb . TrackStatus . Ahead . Count > 0 )
217239 {
218- var b = _repo . Branches . Find ( x => x . FriendlyName == decorator . Name ) ;
219- if ( b != null )
220- {
221- _repo . CheckoutBranch ( b ) ;
222- return ;
223- }
240+ if ( _repo . CanCreatePopup ( ) )
241+ _repo . ShowPopup ( new CreateBranch ( _repo , rb ) ) ;
224242 }
225- else if ( decorator . Type == Models . DecoratorType . RemoteBranchHead )
243+ else if ( lb . TrackStatus . Behind . Count > 0 )
226244 {
227- var remoteBranch = _repo . Branches . Find ( x => x . FriendlyName == decorator . Name ) ;
228- if ( remoteBranch != null )
229- {
230- var localBranch = _repo . Branches . Find ( x => x . IsLocal && x . Upstream == remoteBranch . FullName ) ;
231- if ( localBranch != null )
232- {
233- if ( localBranch . IsCurrent )
234- return ;
235- if ( localBranch . TrackStatus . Ahead . Count > 0 )
236- {
237- if ( _repo . CanCreatePopup ( ) )
238- _repo . ShowPopup ( new CreateBranch ( _repo , remoteBranch ) ) ;
239- }
240- else if ( localBranch . TrackStatus . Behind . Count > 0 )
241- {
242- if ( _repo . CanCreatePopup ( ) )
243- _repo . ShowPopup ( new CheckoutAndFastForward ( _repo , localBranch , remoteBranch ) ) ;
244- }
245- else
246- _repo . CheckoutBranch ( localBranch ) ;
247- return ;
248- }
249- }
245+ if ( _repo . CanCreatePopup ( ) )
246+ _repo . ShowPopup ( new CheckoutAndFastForward ( _repo , lb , rb ) ) ;
247+ }
248+ else if ( ! lb . IsCurrent )
249+ {
250+ _repo . CheckoutBranch ( lb ) ;
250251 }
252+
253+ return true ;
251254 }
252255
253- if ( commit == null || commit . IsCurrentHead )
256+ return false ;
257+ }
258+
259+ public void CheckoutBranchByCommit ( Models . Commit commit )
260+ {
261+ if ( commit . IsCurrentHead )
254262 return ;
255263
256264 var firstRemoteBranch = null as Models . Branch ;
257265 foreach ( var d in commit . Decorators )
258266 {
259267 if ( d . Type == Models . DecoratorType . LocalBranchHead )
260268 {
261- var b = _repo . Branches . Find ( x => x . FriendlyName == d . Name ) ;
262- if ( b ! = null )
263- {
264- _repo . CheckoutBranch ( b ) ;
265- return ;
266- }
269+ var b = _repo . Branches . Find ( x => x . Name == d . Name ) ;
270+ if ( b = = null )
271+ continue ;
272+
273+ _repo . CheckoutBranch ( b ) ;
274+ return ;
267275 }
268276 else if ( d . Type == Models . DecoratorType . RemoteBranchHead )
269277 {
270- var remoteBranch = _repo . Branches . Find ( x => x . FriendlyName == d . Name ) ;
271- if ( remoteBranch != null )
278+ var rb = _repo . Branches . Find ( x => x . FriendlyName == d . Name ) ;
279+ if ( rb == null )
280+ continue ;
281+
282+ var lb = _repo . Branches . Find ( x => x . IsLocal && x . Upstream == rb . FullName ) ;
283+ if ( lb is { TrackStatus . Ahead . Count : 0 } )
272284 {
273- var localBranch = _repo . Branches . Find ( x => x . IsLocal && x . Upstream == remoteBranch . FullName ) ;
274- if ( localBranch is { TrackStatus . Ahead . Count : 0 } )
275- {
276- if ( _repo . CanCreatePopup ( ) )
277- _repo . ShowPopup ( new CheckoutAndFastForward ( _repo , localBranch , remoteBranch ) ) ;
278- return ;
279- }
285+ if ( _repo . CanCreatePopup ( ) )
286+ _repo . ShowPopup ( new CheckoutAndFastForward ( _repo , lb , rb ) ) ;
287+ return ;
280288 }
281289
282- firstRemoteBranch ??= remoteBranch ;
290+ firstRemoteBranch ??= rb ;
283291 }
284292 }
285293
0 commit comments