зеркало из https://github.com/github/libgit2sharp.git
Obsolete repo.Clone() overload which returns a Repository
This commit is contained in:
Родитель
09a26cfe1f
Коммит
1b418ae77a
|
@ -804,7 +804,10 @@ namespace LibGit2Sharp.Tests
|
|||
}
|
||||
|
||||
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");
|
||||
|
|
|
@ -17,7 +17,10 @@ namespace LibGit2Sharp.Tests
|
|||
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 @@ namespace LibGit2Sharp.Tests
|
|||
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 @@ namespace LibGit2Sharp.Tests
|
|||
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 @@ namespace LibGit2Sharp.Tests
|
|||
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 @@ namespace LibGit2Sharp.Tests
|
|||
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 @@ namespace LibGit2Sharp.Tests
|
|||
"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));
|
||||
|
|
|
@ -34,7 +34,10 @@ namespace LibGit2Sharp.Tests
|
|||
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");
|
||||
|
||||
|
|
|
@ -39,16 +39,19 @@ namespace LibGit2Sharp.Tests
|
|||
[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<DirectReference> references = repo.Network.ListReferences(remote);
|
||||
|
||||
List<Tuple<string, string>> actualRefs = new List<Tuple<string,string>>();
|
||||
var actualRefs = new List<Tuple<string,string>>();
|
||||
|
||||
foreach(DirectReference reference in references)
|
||||
{
|
||||
|
|
|
@ -17,8 +17,12 @@ namespace LibGit2Sharp.Tests
|
|||
private void AssertPush(Action<Repository> 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"];
|
||||
|
||||
|
|
|
@ -174,40 +174,5 @@ namespace LibGit2Sharp.Tests
|
|||
|
||||
AssertValueInConfigFile(systemLocation, "xpaulbettsx");
|
||||
}
|
||||
|
||||
[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<string>("woot.this-rocks").Value);
|
||||
Assert.Equal(42, repo.Config.Get<int>("wow.man-I-am-totally-global").Value);
|
||||
|
||||
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Xdg));
|
||||
Assert.Equal("xdg", repo.Config.Get<string>("woot.this-rocks", ConfigurationLevel.Xdg).Value);
|
||||
|
||||
Assert.True(repo.Config.HasConfig(ConfigurationLevel.System));
|
||||
Assert.Equal("system", repo.Config.Get<string>("woot.this-rocks", ConfigurationLevel.System).Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -569,31 +569,57 @@ namespace LibGit2Sharp
|
|||
/// <param name="onCheckoutProgress">Handler for checkout progress information</param>
|
||||
/// <param name="options">Overrides to the way a repository is opened.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <returns></returns>
|
||||
/// <returns> a new instance of the <see cref = "Repository" /> class. The client code is responsible for calling <see cref = "Dispose()" /> on this instance.</returns>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clone with specified options.
|
||||
/// </summary>
|
||||
/// <param name="sourceUrl">URI for the remote repository</param>
|
||||
/// <param name="workdirPath">Local path to clone into</param>
|
||||
/// <param name="bare">True will result in a bare clone, false a full clone.</param>
|
||||
/// <param name="checkout">If true, the origin's HEAD will be checked out. This only applies
|
||||
/// to non-bare repositories.</param>
|
||||
/// <param name="onTransferProgress">Handler for network transfer and indexing progress information</param>
|
||||
/// <param name="onCheckoutProgress">Handler for checkout progress information</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <returns>The path to the created repository.</returns>
|
||||
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)
|
||||
{
|
||||
|
@ -602,13 +628,17 @@ namespace LibGit2Sharp
|
|||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Загрузка…
Ссылка в новой задаче