Skip to content

Commit b5f6042

Browse files
Alexander OvchinnikovAlexander Ovchinnikov
authored andcommitted
Add Repository.Init method accepting InitOptions
1 parent ce74279 commit b5f6042

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

LibGit2Sharp/Repository.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,8 @@ public static string Init(string path, bool isBare)
496496
Ensure.ArgumentNotNullOrEmptyString(path, "path");
497497

498498
var initOptions = new InitOptions { IsBare = isBare };
499-
500-
using (var opts = GitRepositoryInitOptions.BuildFrom(initOptions))
501-
using (RepositoryHandle repo = Proxy.git_repository_init_ext(path, opts))
502-
{
503-
FilePath repoPath = Proxy.git_repository_path(repo);
504-
return repoPath.Native;
505-
}
499+
500+
return Init(path, initOptions);
506501
}
507502

508503
/// <summary>
@@ -525,8 +520,24 @@ public static string Init(string workingDirectoryPath, string gitDirectoryPath)
525520

526521
// TODO: Shouldn't we ensure that the working folder isn't under the gitDir?
527522

528-
using (var opts = GitRepositoryInitOptions.BuildFrom(initOptions))
529-
using (RepositoryHandle repo = Proxy.git_repository_init_ext(gitDirectoryPath, opts))
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))
530541
{
531542
FilePath repoPath = Proxy.git_repository_path(repo);
532543
return repoPath.Native;

0 commit comments

Comments
 (0)