diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index 2aa28f4c9..74bd2a33b 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -804,7 +804,10 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone() } SelfCleaningDirectory scd2 = BuildSelfCleaningDirectory(); - using (Repository repo = Repository.Clone(uri.AbsoluteUri, scd2.RootedDirectoryPath)) + + string clonedRepoPath = Repository.Clone(uri.AbsoluteUri, scd2.DirectoryPath); + + using (var repo = new Repository(clonedRepoPath)) { Assert.Empty(Directory.GetFiles(scd2.RootedDirectoryPath)); Assert.Equal(repo.Head.Name, "master"); diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs index 004dda996..e48321eac 100644 --- a/LibGit2Sharp.Tests/CheckoutFixture.cs +++ b/LibGit2Sharp.Tests/CheckoutFixture.cs @@ -312,9 +312,9 @@ public void CheckingOutWithMergeConflictsThrows() [Fact] public void CanCancelCheckoutThroughNotifyCallback() { - SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); + string repoPath = InitNewRepository(); - using (var repo = Repository.Init(scd.DirectoryPath)) + using (var repo = new Repository(repoPath)) { string relativePath = "a.txt"; Touch(repo.Info.WorkingDirectory, relativePath, "Hello\n"); @@ -432,8 +432,9 @@ public void CheckingOutCallsCheckoutNotify(CheckoutNotifyFlags notifyFlags, stri expectedNotificationPath = expectedNotificationPath + Path.DirectorySeparatorChar; } - SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); - using (var repo = Repository.Init(scd.DirectoryPath)) + string repoPath = InitNewRepository(); + + using (var repo = new Repository(repoPath)) { PopulateBasicRepository(repo); diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs index f5f005d19..a1ae44ded 100644 --- a/LibGit2Sharp.Tests/CloneFixture.cs +++ b/LibGit2Sharp.Tests/CloneFixture.cs @@ -17,7 +17,10 @@ public class CloneFixture : BaseFixture public void CanClone(string url) { var scd = BuildSelfCleaningDirectory(); - using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath)) + + string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath); + + using (var repo = new Repository(clonedRepoPath)) { string dir = repo.Info.Path; Assert.True(Path.IsPathRooted(dir)); @@ -36,7 +39,10 @@ public void CanClone(string url) private void AssertLocalClone(string path) { var scd = BuildSelfCleaningDirectory(); - using (Repository clonedRepo = Repository.Clone(path, scd.RootedDirectoryPath)) + + string clonedRepoPath = Repository.Clone(path, scd.DirectoryPath); + + using (var clonedRepo = new Repository(clonedRepoPath)) using (var originalRepo = new Repository(BareTestRepoPath)) { Assert.NotEqual(originalRepo.Info.Path, clonedRepo.Info.Path); @@ -71,7 +77,10 @@ public void CanCloneALocalRepositoryFromAStandardPath() public void CanCloneBarely(string url) { var scd = BuildSelfCleaningDirectory(); - using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath, bare: true)) + + string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, bare: true); + + using (var repo = new Repository(clonedRepoPath)) { string dir = repo.Info.Path; Assert.True(Path.IsPathRooted(dir)); @@ -88,9 +97,12 @@ public void CanCloneBarely(string url) public void WontCheckoutIfAskedNotTo(string url) { var scd = BuildSelfCleaningDirectory(); - using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath, checkout: false)) + + string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, checkout: false); + + using (var repo = new Repository(clonedRepoPath)) { - Assert.False(File.Exists(Path.Combine(scd.RootedDirectoryPath, "master.txt"))); + Assert.False(File.Exists(Path.Combine(repo.Info.WorkingDirectory, "master.txt"))); } } @@ -102,13 +114,13 @@ public void CallsProgressCallbacks(string url) bool checkoutWasCalled = false; var scd = BuildSelfCleaningDirectory(); - using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath, - onTransferProgress: (_) => { transferWasCalled = true; return 0; }, - onCheckoutProgress: (a, b, c) => checkoutWasCalled = true)) - { - Assert.True(transferWasCalled); - Assert.True(checkoutWasCalled); - } + + Repository.Clone(url, scd.DirectoryPath, + onTransferProgress: _ => { transferWasCalled = true; return 0; }, + onCheckoutProgress: (a, b, c) => checkoutWasCalled = true); + + Assert.True(transferWasCalled); + Assert.True(checkoutWasCalled); } [SkippableFact] @@ -118,13 +130,16 @@ public void CanCloneWithCredentials() "Populate Constants.PrivateRepo* to run this test"); var scd = BuildSelfCleaningDirectory(); - using (Repository repo = Repository.Clone( - Constants.PrivateRepoUrl, scd.RootedDirectoryPath, + + string clonedRepoPath = Repository.Clone(Constants.PrivateRepoUrl, scd.DirectoryPath, credentials: new Credentials { Username = Constants.PrivateRepoUsername, Password = Constants.PrivateRepoPassword - })) + }); + + + using (var repo = new Repository(clonedRepoPath)) { string dir = repo.Info.Path; Assert.True(Path.IsPathRooted(dir)); diff --git a/LibGit2Sharp.Tests/FetchHeadFixture.cs b/LibGit2Sharp.Tests/FetchHeadFixture.cs index 51f5721bd..ccd6f863f 100644 --- a/LibGit2Sharp.Tests/FetchHeadFixture.cs +++ b/LibGit2Sharp.Tests/FetchHeadFixture.cs @@ -34,7 +34,10 @@ private class FetchHeadExpected public void CanIterateFetchHead(string url) { var scd = BuildSelfCleaningDirectory(); - using (var repo = Repository.Clone(url, scd.RootedDirectoryPath)) + + string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath); + + using (var repo = new Repository(clonedRepoPath)) { repo.Reset(ResetOptions.Hard, "HEAD~2"); diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs index 759e36ed3..870633aa8 100644 --- a/LibGit2Sharp.Tests/NetworkFixture.cs +++ b/LibGit2Sharp.Tests/NetworkFixture.cs @@ -39,16 +39,19 @@ public void CanListRemoteReferences(string url) [Fact] public void CanListRemoteReferenceObjects() { - string url = "http://github.com/libgit2/TestGitRepository"; - string remoteName = "origin"; + const string url = "http://github.com/libgit2/TestGitRepository"; + const string remoteName = "origin"; var scd = BuildSelfCleaningDirectory(); - using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath)) + + string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath); + + using (var repo = new Repository(clonedRepoPath)) { Remote remote = repo.Network.Remotes[remoteName]; IEnumerable references = repo.Network.ListReferences(remote); - List> actualRefs = new List>(); + var actualRefs = new List>(); foreach(DirectReference reference in references) { diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs index 3e81e3530..db8e9fded 100644 --- a/LibGit2Sharp.Tests/PushFixture.cs +++ b/LibGit2Sharp.Tests/PushFixture.cs @@ -17,8 +17,12 @@ private void OnPushStatusError(PushStatusError pushStatusErrors) private void AssertPush(Action push) { var scd = BuildSelfCleaningDirectory(); - using (var originalRepo = new Repository(CloneBareTestRepo())) - using (Repository clonedRepo = Repository.Clone(originalRepo.Info.Path, scd.RootedDirectoryPath)) + + string originalRepoPath = CloneBareTestRepo(); + string clonedRepoPath = Repository.Clone(originalRepoPath, scd.DirectoryPath); + + using (var originalRepo = new Repository(originalRepoPath)) + using (var clonedRepo = new Repository(clonedRepoPath)) { Remote remote = clonedRepo.Network.Remotes["origin"]; diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs index b3f8625da..81a896d74 100644 --- a/LibGit2Sharp.Tests/RepositoryFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryFixture.cs @@ -81,6 +81,54 @@ public void CanCreateStandardRepo() } } + [Fact] + public void CanCreateStandardRepoAndSpecifyAFolderWhichWillContainTheNewlyCreatedGitDirectory() + { + var scd1 = BuildSelfCleaningDirectory(); + var scd2 = BuildSelfCleaningDirectory(); + + string repoPath = Repository.Init(scd1.DirectoryPath, scd2.DirectoryPath); + + Assert.True(Repository.IsValid(repoPath)); + + using (var repo = new Repository(repoPath)) + { + Assert.True(Repository.IsValid(repo.Info.WorkingDirectory)); + Assert.True(Repository.IsValid(repo.Info.Path)); + + Assert.Equal(false, repo.Info.IsBare); + + char sep = Path.DirectorySeparatorChar; + Assert.Equal(scd1.RootedDirectoryPath + sep, repo.Info.WorkingDirectory); + Assert.Equal(scd2.RootedDirectoryPath + sep + ".git" + sep, repo.Info.Path); + } + } + + [Fact] + public void CanCreateStandardRepoAndDirectlySpecifyAGitDirectory() + { + var scd1 = BuildSelfCleaningDirectory(); + var scd2 = BuildSelfCleaningDirectory(); + + var gitDir = Path.Combine(scd2.DirectoryPath, ".git/"); + + string repoPath = Repository.Init(scd1.DirectoryPath, gitDir); + + Assert.True(Repository.IsValid(repoPath)); + + using (var repo = new Repository(repoPath)) + { + Assert.True(Repository.IsValid(repo.Info.WorkingDirectory)); + Assert.True(Repository.IsValid(repo.Info.Path)); + + Assert.Equal(false, repo.Info.IsBare); + + char sep = Path.DirectorySeparatorChar; + Assert.Equal(scd1.RootedDirectoryPath + sep, repo.Info.WorkingDirectory); + Assert.Equal(Path.GetFullPath(gitDir), repo.Info.Path); + } + } + private static void CheckGitConfigFile(string dir) { string configFilePath = Path.Combine(dir, "config"); @@ -155,9 +203,13 @@ public void CanReinitARepository() string repoPath = InitNewRepository(); using (var repository = new Repository(repoPath)) - using (var repository2 = new Repository(repoPath)) { - Assert.Equal(repository2.Info.Path, repository.Info.Path); + string repoPath2 = Repository.Init(repoPath, false); + + using (var repository2 = new Repository(repoPath2)) + { + Assert.Equal(repository2.Info.Path, repository.Info.Path); + } } } diff --git a/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs b/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs index 1f9e19dfd..298d0f9ea 100644 --- a/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs @@ -174,72 +174,5 @@ public void CanProvideDifferentConfigurationFilesToARepository() AssertValueInConfigFile(systemLocation, "xpaulbettsx"); } - - [Fact] - public void CanProvideDifferentWorkingDirOnInit() - { - SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); - var options = new RepositoryOptions {WorkingDirectoryPath = newWorkdir}; - - using (var repo = Repository.Init(scd.DirectoryPath, false, options)) - { - Assert.Equal(Path.GetFullPath(newWorkdir) + Path.DirectorySeparatorChar, repo.Info.WorkingDirectory); - } - } - - [Fact] - public void CanProvideDifferentConfigurationFilesOnInit() - { - SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); - var options = BuildFakeConfigs(scd); - - using (var repo = Repository.Init(scd.DirectoryPath, false, options)) - { - Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global)); - Assert.Equal("global", repo.Config.Get("woot.this-rocks").Value); - Assert.Equal(42, repo.Config.Get("wow.man-I-am-totally-global").Value); - - Assert.True(repo.Config.HasConfig(ConfigurationLevel.Xdg)); - Assert.Equal("xdg", repo.Config.Get("woot.this-rocks", ConfigurationLevel.Xdg).Value); - - Assert.True(repo.Config.HasConfig(ConfigurationLevel.System)); - Assert.Equal("system", repo.Config.Get("woot.this-rocks", ConfigurationLevel.System).Value); - } - } - - [Fact] - public void CanProvideDifferentWorkingDirOnClone() - { - string url = "https://github.com/libgit2/TestGitRepository"; - var scd = BuildSelfCleaningDirectory(); - var options = new RepositoryOptions { WorkingDirectoryPath = newWorkdir }; - - using (var repo = Repository.Clone(url, scd.DirectoryPath, false, true, null, null, options)) - { - Assert.Equal(Path.GetFullPath(newWorkdir) + Path.DirectorySeparatorChar, repo.Info.WorkingDirectory); - } - } - - [Fact] - public void CanProvideDifferentConfigurationFilesOnClone() - { - string url = "https://github.com/libgit2/TestGitRepository"; - var scd = BuildSelfCleaningDirectory(); - var configScd = BuildSelfCleaningDirectory(); - var options = BuildFakeConfigs(configScd); - - using (var repo = Repository.Clone(url, scd.DirectoryPath, false, true, null, null, options)) - { - Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global)); - Assert.Equal("global", repo.Config.Get("woot.this-rocks").Value); - Assert.Equal(42, repo.Config.Get("wow.man-I-am-totally-global").Value); - - Assert.True(repo.Config.HasConfig(ConfigurationLevel.Xdg)); - Assert.Equal("xdg", repo.Config.Get("woot.this-rocks", ConfigurationLevel.Xdg).Value); - - Assert.True(repo.Config.HasConfig(ConfigurationLevel.System)); - Assert.Equal("system", repo.Config.Get("woot.this-rocks", ConfigurationLevel.System).Value); - } - } } } diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index 5dcc93c4a..b91c2316a 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -142,10 +142,7 @@ protected string InitNewRepository(bool isBare = false) { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); - using (var repo = Repository.Init(scd.DirectoryPath, isBare, null)) - { - return repo.Info.Path; - } + return Repository.Init(scd.DirectoryPath, isBare); } public void Register(string directoryPath) diff --git a/LibGit2Sharp/Core/GitRepositoryInitOptions.cs b/LibGit2Sharp/Core/GitRepositoryInitOptions.cs new file mode 100644 index 000000000..da202b94e --- /dev/null +++ b/LibGit2Sharp/Core/GitRepositoryInitOptions.cs @@ -0,0 +1,64 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace LibGit2Sharp.Core +{ + [StructLayout(LayoutKind.Sequential)] + internal class GitRepositoryInitOptions : IDisposable + { + public uint Version = 1; + public GitRepositoryInitFlags Flags; + public int Mode; + public IntPtr WorkDirPath; + public IntPtr Description; + public IntPtr TemplatePath; + public IntPtr InitialHead; + public IntPtr OriginUrl; + + public static GitRepositoryInitOptions BuildFrom(FilePath workdirPath, bool isBare) + { + var opts = new GitRepositoryInitOptions + { + Flags = GitRepositoryInitFlags.GIT_REPOSITORY_INIT_MKPATH, + Mode = 0 /* GIT_REPOSITORY_INIT_SHARED_UMASK */ + }; + + if (workdirPath != null) + { + Debug.Assert(!isBare); + + opts.WorkDirPath = FilePathMarshaler.FromManaged(workdirPath); + } + + if (isBare) + { + opts.Flags |= GitRepositoryInitFlags.GIT_REPOSITORY_INIT_BARE; + } + + return opts; + } + + public void Dispose() + { + if (WorkDirPath == IntPtr.Zero) + { + return; + } + + Marshal.FreeHGlobal(WorkDirPath); + WorkDirPath = IntPtr.Zero; + } + } + + [Flags] + internal enum GitRepositoryInitFlags + { + GIT_REPOSITORY_INIT_BARE = (1 << 0), + GIT_REPOSITORY_INIT_NO_REINIT = (1 << 1), + GIT_REPOSITORY_INIT_NO_DOTGIT_DIR = (1 << 2), + GIT_REPOSITORY_INIT_MKDIR = (1 << 3), + GIT_REPOSITORY_INIT_MKPATH = (1 << 4), + GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE = (1 << 5), + } +} diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 62a6e1ab8..ca65c16bf 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -876,10 +876,10 @@ internal static extern int git_repository_fetchhead_foreach( internal static extern int git_repository_index(out IndexSafeHandle index, RepositorySafeHandle repo); [DllImport(libgit2)] - internal static extern int git_repository_init( + internal static extern int git_repository_init_ext( out RepositorySafeHandle repository, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path, - [MarshalAs(UnmanagedType.Bool)] bool isBare); + GitRepositoryInitOptions options); [DllImport(libgit2)] internal static extern int git_repository_is_bare(RepositorySafeHandle handle); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index ac2c3ba98..093f5c35c 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -1574,12 +1574,16 @@ public static IndexSafeHandle git_repository_index(RepositorySafeHandle repo) } } - public static RepositorySafeHandle git_repository_init(FilePath path, bool isBare) + public static RepositorySafeHandle git_repository_init_ext( + FilePath workdirPath, + FilePath gitdirPath, + bool isBare) { using (ThreadAffinity()) + using (var opts = GitRepositoryInitOptions.BuildFrom(workdirPath, isBare)) { RepositorySafeHandle repo; - int res = NativeMethods.git_repository_init(out repo, path, isBare); + int res = NativeMethods.git_repository_init_ext(out repo, gitdirPath, opts); Ensure.ZeroResult(res); return repo; diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 4d74e4f11..0ddf68ad4 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -69,6 +69,7 @@ + diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 6f2c3757a..2c8687a73 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -362,14 +362,53 @@ protected virtual void Dispose(bool disposing) /// true to initialize a bare repository. False otherwise, to initialize a standard ".git" repository. /// Overrides to the way a repository is opened. /// a new instance of the class. The client code is responsible for calling on this instance. - public static Repository Init(string path, bool isBare = false, RepositoryOptions options = null) + [Obsolete("This method will be removed in the next release. Please use Init(string, bool) instead.")] + public static Repository Init(string path, bool isBare, RepositoryOptions options) + { + string gitDirPath = Init(path, isBare); + + return new Repository(gitDirPath, options); + } + + /// + /// Initialize a repository at the specified . + /// + /// 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. + /// true to initialize a bare repository. False otherwise, to initialize a standard ".git" repository. + /// The path to the created repository. + public static string Init(string path, bool isBare = false) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); - using (RepositorySafeHandle repo = Proxy.git_repository_init(path, isBare)) + using (RepositorySafeHandle repo = Proxy.git_repository_init_ext(null, path, isBare)) { FilePath repoPath = Proxy.git_repository_path(repo); - return new Repository(repoPath.Native, options); + return repoPath.Native; + } + } + + /// + /// Initialize a repository by explictly setting the path to both the working directory and the git directory. + /// + /// The path to the working directory. + /// The path to the git repository to be created. + /// The path to the created repository. + public static string Init(string workingDirectoryPath, string gitDirectoryPath) + { + Ensure.ArgumentNotNullOrEmptyString(workingDirectoryPath, "workingDirectoryPath"); + Ensure.ArgumentNotNullOrEmptyString(gitDirectoryPath, "gitDirectoryPath"); + + // When being passed a relative workdir path, libgit2 will evaluate it from the + // path to the repository. We pass a fully rooted path in order for the LibGit2Sharp caller + // to pass a path relatively to his current directory. + string wd = Path.GetFullPath(workingDirectoryPath); + + // TODO: Shouldn't we ensure that the working folder isn't under the gitDir? + + using (RepositorySafeHandle repo = Proxy.git_repository_init_ext(wd, gitDirectoryPath, false)) + { + FilePath repoPath = Proxy.git_repository_path(repo); + return repoPath.Native; } } @@ -530,31 +569,57 @@ public static string Discover(string startingPath) /// Handler for checkout progress information /// Overrides to the way a repository is opened. /// Credentials to use for user/pass authentication - /// + /// a new instance of the class. The client code is responsible for calling on this instance. + [Obsolete("This method will be removed in the next release. Please use Clone(string, string, bool, bool, TransferProgressHandler, CheckoutProgressHandler, Credentials) instead.")] public static Repository Clone(string sourceUrl, string workdirPath, + bool bare, + bool checkout, + TransferProgressHandler onTransferProgress, + CheckoutProgressHandler onCheckoutProgress, + RepositoryOptions options, + Credentials credentials) + { + string gitDirPath = Clone(sourceUrl, workdirPath, bare, + checkout, onTransferProgress, onCheckoutProgress, credentials); + + return new Repository(gitDirPath, options); + } + + /// + /// Clone with specified options. + /// + /// URI for the remote repository + /// Local path to clone into + /// True will result in a bare clone, false a full clone. + /// If true, the origin's HEAD will be checked out. This only applies + /// to non-bare repositories. + /// Handler for network transfer and indexing progress information + /// Handler for checkout progress information + /// Credentials to use for user/pass authentication + /// The path to the created repository. + public static string Clone(string sourceUrl, string workdirPath, bool bare = false, bool checkout = true, TransferProgressHandler onTransferProgress = null, CheckoutProgressHandler onCheckoutProgress = null, - RepositoryOptions options = null, Credentials credentials = null) { CheckoutCallbacks checkoutCallbacks = CheckoutCallbacks.GenerateCheckoutCallbacks(onCheckoutProgress, null); var cloneOpts = new GitCloneOptions + { + Bare = bare ? 1 : 0, + TransferProgressCallback = TransferCallbacks.GenerateCallback(onTransferProgress), + CheckoutOpts = { - Bare = bare ? 1 : 0, - TransferProgressCallback = TransferCallbacks.GenerateCallback(onTransferProgress), - CheckoutOpts = - { - version = 1, - progress_cb = + version = 1, + progress_cb = checkoutCallbacks.CheckoutProgressCallback, - checkout_strategy = checkout - ? CheckoutStrategy.GIT_CHECKOUT_SAFE_CREATE - : CheckoutStrategy.GIT_CHECKOUT_NONE - }, - }; + checkout_strategy = checkout + ? CheckoutStrategy.GIT_CHECKOUT_SAFE_CREATE + : CheckoutStrategy.GIT_CHECKOUT_NONE + }, + }; if (credentials != null) { @@ -563,13 +628,17 @@ public static Repository Clone(string sourceUrl, string workdirPath, NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password); } - using(Proxy.git_clone(sourceUrl, workdirPath, cloneOpts)) {} + FilePath repoPath; + using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, cloneOpts)) + { + repoPath = Proxy.git_repository_path(repo); + } // To be safe, make sure the credential callback is kept until // alive until at least this point. GC.KeepAlive(cloneOpts.CredAcquireCallback); - return new Repository(workdirPath, options); + return repoPath.Native; } ///