@@ -275,22 +275,16 @@ public void OpenRepositoryInTab(RepositoryNode node, LauncherPage page)
275
275
276
276
if ( ! Path . Exists ( node . Id ) )
277
277
{
278
- var ctx = page == null ? ActivePage . Node . Id : page . Node . Id ;
279
- App . RaiseException ( ctx , "Repository does NOT exists any more. Please remove it." ) ;
278
+ App . RaiseException ( node . Id , "Repository does NOT exists any more. Please remove it." ) ;
280
279
return ;
281
280
}
282
281
283
282
var isBare = new Commands . IsBareRepository ( node . Id ) . Result ( ) ;
284
- var gitDir = node . Id ;
285
- if ( ! isBare )
283
+ var gitDir = isBare ? node . Id : GetRepositoryGitDir ( node . Id ) ;
284
+ if ( string . IsNullOrEmpty ( gitDir ) )
286
285
{
287
- gitDir = new Commands . QueryGitDir ( node . Id ) . Result ( ) ;
288
- if ( string . IsNullOrEmpty ( gitDir ) )
289
- {
290
- var ctx = page == null ? ActivePage . Node . Id : page . Node . Id ;
291
- App . RaiseException ( ctx , "Given path is not a valid git repository!" ) ;
292
- return ;
293
- }
286
+ App . RaiseException ( node . Id , "Given path is not a valid git repository!" ) ;
287
+ return ;
294
288
}
295
289
296
290
var repo = new Repository ( isBare , node . Id , gitDir ) ;
@@ -469,6 +463,37 @@ public ContextMenu CreateContextForPageTab(LauncherPage page)
469
463
return menu ;
470
464
}
471
465
466
+ private string GetRepositoryGitDir ( string repo )
467
+ {
468
+ var fullpath = Path . Combine ( repo , ".git" ) ;
469
+ if ( Directory . Exists ( fullpath ) )
470
+ {
471
+ if ( Directory . Exists ( Path . Combine ( fullpath , "refs" ) ) &&
472
+ Directory . Exists ( Path . Combine ( fullpath , "objects" ) ) &&
473
+ File . Exists ( Path . Combine ( fullpath , "HEAD" ) ) )
474
+ return fullpath ;
475
+
476
+ return null ;
477
+ }
478
+
479
+ if ( File . Exists ( fullpath ) )
480
+ {
481
+ var redirect = File . ReadAllText ( fullpath ) . Trim ( ) ;
482
+ if ( redirect . StartsWith ( "gitdir: " , StringComparison . Ordinal ) )
483
+ redirect = redirect . Substring ( 8 ) ;
484
+
485
+ if ( ! Path . IsPathRooted ( redirect ) )
486
+ redirect = Path . GetFullPath ( Path . Combine ( repo , redirect ) ) ;
487
+
488
+ if ( Directory . Exists ( redirect ) )
489
+ return redirect ;
490
+
491
+ return null ;
492
+ }
493
+
494
+ return new Commands . QueryGitDir ( repo ) . Result ( ) ;
495
+ }
496
+
472
497
private void SwitchWorkspace ( Workspace to )
473
498
{
474
499
foreach ( var one in Pages )
0 commit comments