8000 Add optional RepositoryOptions to Repository.Clone call · rlazev/libgit2sharp@25a7855 · GitHub
[go: up one dir, main page]

Skip to content

Commit 25a7855

Browse files
Saamannulltoken
authored andcommitted
Add optional RepositoryOptions to Repository.Clone call
Fix libgit2#263
1 parent d1a5c57 commit 25a7855

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

LibGit2Sharp.Tests/RepositoryOptionsFixture.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,40 @@ public void CanProvideDifferentConfigurationFilesOnInit()
211211
Assert.Equal("system", repo.Config.Get<string>("woot.this-rocks", ConfigurationLevel.System).Value);
212212
}
213213
}
214+
215+
[Fact]
216+
public void CanProvideDifferentWorkingDirOnClone()
217+
{
218+
string url = "https://github.com/libgit2/TestGitRepository";
219+
var scd = BuildSelfCleaningDirectory();
220+
var options = new RepositoryOptions { WorkingDirectoryPath = newWorkdir };
221+
222+
using (var repo = Repository.Clone(url, scd.DirectoryPath, false, true, null, null, options))
223+
{
224+
Assert.Equal(Path.GetFullPath(newWorkdir) + Path.DirectorySeparatorChar, repo.Info.WorkingDirectory);
225+
}
226+
}
227+
228+
[Fact]
229+
public void CanProvideDifferentConfigurationFilesOnClone()
230+
{
231+
string url = "https://github.com/libgit2/TestGitRepository";
232+
var scd = BuildSelfCleaningDirectory();
233+
var configScd = BuildSelfCleaningDirectory();
234+
var options = BuildFakeConfigs(configScd);
235+
236+
using (var repo = Repository.Clone(url, scd.DirectoryPath, false, true, null, null, options))
237+
{
238+
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global));
239+
Assert.Equal("global", repo.Config.Get<string>("woot.this-rocks").Value);
240+
Assert.Equal(42, repo.Config.Get<int>("wow.man-I-am-totally-global").Value);
241+
242+
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Xdg));
243+
Assert.Equal("xdg", repo.Config.Get<string>("woot.this-rocks", ConfigurationLevel.Xdg).Value);
244+
245+
Assert.True(repo.Config.HasConfig(ConfigurationLevel.System));
246+
Assert.Equal("system", repo.Config.Get<string>("woot.this-rocks", ConfigurationLevel.System).Value);
247+
}
248+
}
214249
}
215250
}

LibGit2Sharp/Repository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,14 @@ public static string Discover(string startingPath)
413413
/// to non-bare repositories.</param>
414414
/// <param name="onTransferProgress">Handler for network transfer and indexing progress information</param>
415415
/// <param name="onCheckoutProgress">Handler for checkout progress information</param>
416+
/// <param name="options">Overrides to the way a repository is opened.</param>
416417
/// <returns></returns>
417418
public static Repository Clone(string sourceUrl, string workdirPath,
418419
bool bare = false,
419420
bool checkout = true,
420421
TransferProgressHandler onTransferProgress = null,
421-
CheckoutProgressHandler onCheckoutProgress = null)
422+
CheckoutProgressHandler onCheckoutProgress = null,
423+
RepositoryOptions options = null)
422424
{
423425
GitCheckoutOpts nativeOpts = null;
424426
if (checkout)
@@ -438,7 +440,7 @@ public static Repository Clone(string sourceUrl, string workdirPath,
438440
: Proxy.git_clone(sourceUrl, workdirPath, cb, nativeOpts);
439441
repo.SafeDispose();
440442

441-
return new Repository(workdirPath);
443+
return new Repository(workdirPath, options);
442444
}
443445

444446
/// <summary>

0 commit comments

Comments
 (0)
0