@@ -495,11 +495,9 @@ public static string Init(string path, bool isBare)
495
495
{
496
496
Ensure . ArgumentNotNullOrEmptyString ( path , "path" ) ;
497
497
498
- using ( RepositoryHandle repo = Proxy . git_repository_init_ext ( null , path , isBare ) )
499
- {
500
- FilePath repoPath = Proxy . git_repository_path ( repo ) ;
501
- return repoPath . Native ;
502
- }
498
+ var initOptions = new InitOptions { IsBare = isBare } ;
499
+
500
+ return Init ( path , initOptions ) ;
503
501
}
504
502
505
503
/// <summary>
@@ -518,9 +516,28 @@ public static string Init(string workingDirectoryPath, string gitDirectoryPath)
518
516
// to pass a path relatively to his current directory.
519
517
string wd = Path . GetFullPath ( workingDirectoryPath ) ;
520
518
519
+ var initOptions = new InitOptions { WorkdirPath = wd } ;
520
+
521
521
// TODO: Shouldn't we ensure that the working folder isn't under the gitDir?
522
522
523
- using ( RepositoryHandle repo = Proxy . git_repository_init_ext ( wd , gitDirectoryPath , false ) )
523
+ return Init ( gitDirectoryPath , initOptions ) ;
524
+ }
525
+
526
+ /// <summary>
527
+ /// Initialize a repository at the specified <paramref name="path"/>,
528
+ /// providing optional behavioral overrides through the <paramref name="options"/> parameter.
529
+ /// </summary>
530
+ /// <param name="path">The path to the working folder when initializing a standard ".git" repository. Otherwise, when initializing a bare repository, the path to the expected location of this later.</param>
531
+ /// <param name="options">Options controlling init behavior.</param>
532
+ /// <returns>The path to the created repository.</returns>
533
+ public static string Init ( string path , InitOptions options )
534
+ {
535
+ Ensure . ArgumentNotNullOrEmptyString ( path , "path" ) ;
536
+
537
+ options = options ?? new InitOptions ( ) ;
538
+
539
+ using ( var opts = GitRepositoryInitOptions . BuildFrom ( options ) )
540
+ using ( RepositoryHandle repo = Proxy . git_repository_init_ext ( path , opts ) )
524
541
{
525
542
FilePath repoPath = Proxy . git_repository_path ( repo ) ;
526
543
return repoPath . Native ;
@@ -656,7 +673,24 @@ internal Commit LookupCommit(string committish)
656
673
/// <returns>The references in the remote repository.</returns>
657
674
public static IEnumerable < Reference > ListRemoteReferences ( string url )
658
675
{
659
- return ListRemoteReferences ( url , null ) ;
676
+ string _defaultBranch ;
677
+ return ListRemoteReferences ( url , null , out _defaultBranch ) ;
678
+ }
679
+
680
+ /// <summary>
681
+ /// Lists the Remote Repository References.
682
+ /// </summary>
683
+ /// <para>
684
+ /// Does not require a local Repository. The retrieved
685
+ /// <see cref="IBelongToARepository.Repository"/>
686
+ /// throws <see cref="InvalidOperationException"/> in this case.
687
+ /// </para>
688
+ /// <param name="url">The url to list from.</param>
689
+ /// <param name="defaultBranch">The name of the Repository's default branch.</param>
690
+ /// <returns>The references in the remote repository.</returns>
691
+ public static IEnumerable < Reference > ListRemoteReferences ( string url , out string defaultBranch )
692
+ {
693
+ return ListRemoteReferences ( url , null , out defaultBranch ) ;
660
694
}
661
695
662
696
/// <summary>
@@ -671,6 +705,24 @@ public static IEnumerable<Reference> ListRemoteReferences(string url)
671
705
/// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
672
706
/// <returns>The references in the remote repository.</returns>
673
707
public static IEnumerable < Reference > ListRemoteReferences ( string url , CredentialsHandler credentialsProvider )
708
+ {
709
+ string _defaultBranch ;
710
+ return ListRemoteReferences ( url , credentialsProvider , out _defaultBranch ) ;
711
+ }
712
+
713
+ /// <summary>
714
+ /// Lists the Remote Repository References.
715
+ /// </summary>
716
+ /// <para>
717
+ /// Does not require a local Repository. The retrieved
718
+ /// <see cref="IBelongToARepository.Repository"/>
719
+ /// throws <see cref="InvalidOperationException"/> in this case.
720
+ /// </para>
721
+ /// <param name="url">The url to list from.</param>
722
+ /// <param name="credentialsProvider">The <see cref="Func{Credentials}"/> used to connect to remote repository.</param>
723
+ /// <param name="defaultBranch">The name of the Repository's default branch.</param>
724
+ /// <returns>The references in the remote repository.</returns>
725
+ public static IEnumerable < Reference > ListRemoteReferences ( string url , CredentialsHandler credentialsProvider , out string defaultBranch )
674
726
{
675
727
Ensure . ArgumentNotNull ( url , "url" ) ;
676
728
@@ -687,7 +739,11 @@ public static IEnumerable<Reference> ListRemoteReferences(string url, Credential
687
739
}
688
740
689
741
Proxy . git_remote_connect ( remoteHandle , GitDirection . Fetch , ref gitCallbacks , ref proxyOptions ) ;
690
- return Proxy . git_remote_ls ( null , remoteHandle ) ;
742
+
743
+ var remoteReferences = Proxy . git_remote_ls ( null , remoteHandle ) ;
744
+ defaultBranch = Proxy . git_remote_default_branch ( remoteHandle ) ;
745
+
746
+ return remoteReferences ;
691
747
}
692
748
}
693
749
0 commit comments