diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 91e2f8513..9c7916b5e 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -556,16 +556,21 @@ public static string Clone(string sourceUrl, string workdirPath, Bare = options.IsBare ? 1 : 0, CheckoutOpts = gitCheckoutOptions, RemoteCallbacks = gitRemoteCallbacks, - CheckoutBranch = StrictUtf8Marshaler.FromManaged(options.BranchName) }; - FilePath repoPath; - using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, ref cloneOpts)) + try { - repoPath = Proxy.git_repository_path(repo); - } + cloneOpts.CheckoutBranch = StrictUtf8Marshaler.FromManaged(options.BranchName); - return repoPath.Native; + using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, ref cloneOpts)) + { + return Proxy.git_repository_path(repo).Native; + } + } + finally + { + EncodingMarshaler.Cleanup(cloneOpts.CheckoutBranch); + } } }