Skip to content

Enable configurable proxy support #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
6 commits merged into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions LibGit2Sharp.Tests/CloneFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void CanCloneWithCheckoutBranchName(string branchName, string headTipId)
{
var scd = BuildSelfCleaningDirectory();

string clonedRepoPath = Repository.Clone(BareTestRepoPath, scd.DirectoryPath, new CloneOptions { BranchName = branchName });
string clonedRepoPath = Repository.Clone(BareTestRepoPath, scd.DirectoryPath, new CloneOptions { BranchName = branchName }, new ProxyOptions());

using (var repo = new Repository(clonedRepoPath))
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public void CanCloneBarely(string url)
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
{
IsBare = true
});
}, new ProxyOptions());

using (var repo = new Repository(clonedRepoPath))
{
Expand All @@ -135,7 +135,7 @@ public void WontCheckoutIfAskedNotTo(string url)
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
{
Checkout = false
});
}, new ProxyOptions());

using (var repo = new Repository(clonedRepoPath))
{
Expand All @@ -160,7 +160,7 @@ public void CallsProgressCallbacks(string url)
OnProgress = progress => { progressWasCalled = true; return true; },
OnUpdateTips = (name, oldId, newId) => { updateTipsWasCalled = true; return true; },
OnCheckoutProgress = (a, b, c) => checkoutWasCalled = true
});
}, new ProxyOptions());

Assert.True(transferWasCalled);
Assert.True(progressWasCalled);
Expand All @@ -180,7 +180,7 @@ public void CanCloneWithCredentials()
new CloneOptions()
{
CredentialsProvider = Constants.PrivateRepoCredentials
});
}, new ProxyOptions());


using (var repo = new Repository(clonedRepoPath))
Expand Down Expand Up @@ -223,7 +223,7 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
{
CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials (user, pass, secure)
});
}, new ProxyOptions());

using (var repo = new Repository(clonedRepoPath))
{
Expand Down Expand Up @@ -290,7 +290,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
};

Assert.Throws<UserCancelledException>(() =>
Repository.Clone(url, scd.DirectoryPath, options)
Repository.Clone(url, scd.DirectoryPath, options, new ProxyOptions())
);

Assert.True(wasCalled);
Expand Down Expand Up @@ -438,7 +438,7 @@ public void CanRecursivelyCloneSubmodules()
RepositoryOperationCompleted = repositoryOperationCompleted,
};

string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions());
string workDirPath;

using(Repository repo = new Repository(clonedRepoPath))
Expand Down Expand Up @@ -522,7 +522,7 @@ public void CanCancelRecursiveClone()
};

Assert.Throws<UserCancelledException>(() =>
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options));
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions()));

// Cancel after super repository is cloned, but before submodule is cloned.
cancelDepth = 1;
Expand All @@ -531,7 +531,7 @@ public void CanCancelRecursiveClone()

try
{
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions());
}
catch(RecurseSubmodulesException ex)
{
Expand Down Expand Up @@ -563,7 +563,7 @@ public void CannotCloneWithForbiddenCustomHeaders()
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
};

Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions));
Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions, new ProxyOptions()));
}

[Fact]
Expand All @@ -579,7 +579,7 @@ public void CannotCloneWithMalformedCustomHeaders()
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
};

Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions));
Assert.Throws<LibGit2SharpException>(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions, new ProxyOptions()));
}

[Fact]
Expand All @@ -595,7 +595,7 @@ public void CanCloneWithCustomHeaders()
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
};

var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions);
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions, new ProxyOptions());
Assert.True(Directory.Exists(clonedRepoPath));
}
}
Expand Down
24 changes: 12 additions & 12 deletions LibGit2Sharp.Tests/FetchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void CanFetchIntoAnEmptyRepository(string url)
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null, new ProxyOptions());

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand All @@ -67,7 +67,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
{
CredentialsProvider = Constants.PrivateRepoCredentials
}, null);
}, null, new ProxyOptions());
}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
TagFetchMode = TagFetchMode.All,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
}, null);
}, null, new ProxyOptions());

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand Down Expand Up @@ -150,7 +150,7 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local
Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions {
TagFetchMode = TagFetchMode.None,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
}, null);
}, null, new ProxyOptions());

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand Down Expand Up @@ -181,7 +181,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
r => r.TagFetchMode = tagFetchMode);

// Perform the actual fetch.
Commands.Fetch(repo, remoteName, new string[0], null, null);
Commands.Fetch(repo, remoteName, new string[0], null, null, null);

// Verify the number of fetched tags.
Assert.Equal(expectedTagCount, repo.Tags.Count());
Expand All @@ -199,7 +199,7 @@ public void CanFetchAllTagsAfterAnInitialClone()

using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null, new ProxyOptions());
}
}

Expand All @@ -225,17 +225,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()

// No pruning when the configuration entry isn't defined
Assert.Null(clonedRepo.Config.Get<bool>("fetch.prune"));
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));

// No pruning when the configuration entry is set to false
clonedRepo.Config.Set<bool>("fetch.prune", false);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));

// Auto pruning when the configuration entry is set to true
clonedRepo.Config.Set<bool>("fetch.prune", true);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote));
}
}
Expand All @@ -253,7 +253,7 @@ public void CannotFetchWithForbiddenCustomHeaders()
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions()));
}
}

Expand All @@ -270,7 +270,7 @@ public void CanFetchWithCustomHeaders()
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], options, null);
Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions());
}
}

Expand All @@ -287,7 +287,7 @@ public void CannotFetchWithMalformedCustomHeaders()
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions()));
}
}

Expand Down
16 changes: 8 additions & 8 deletions LibGit2Sharp.Tests/NetworkFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void CanListRemoteReferencesWithCredentials()
{
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);

var references = repo.Network.ListReferences(remote, Constants.PrivateRepoCredentials);
var references = repo.Network.ListReferences(remote, Constants.PrivateRepoCredentials, new ProxyOptions());

foreach (var reference in references)
{
Expand Down Expand Up @@ -164,7 +164,7 @@ public void CanPull(FastForwardStrategy fastForwardStrategy)
}
};

MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, pullOptions);
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, pullOptions, new ProxyOptions());

if(fastForwardStrategy == FastForwardStrategy.Default || fastForwardStrategy == FastForwardStrategy.FastForwardOnly)
{
Expand Down Expand Up @@ -197,7 +197,7 @@ public void CanPullIntoEmptyRepo()
b => b.UpstreamBranch = "refs/heads/master");

// Pull!
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions());
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions(), new ProxyOptions());

Assert.Equal(MergeStatus.FastForward, mergeResult.Status);
Assert.Equal(mergeResult.Commit, repo.Branches["refs/remotes/origin/master"].Tip);
Expand All @@ -224,7 +224,7 @@ public void PullWithoutMergeBranchThrows()

try
{
Commands.Pull(repo, Constants.Signature, new PullOptions());
Commands.Pull(repo, Constants.Signature, new PullOptions(), new ProxyOptions());
}
catch(MergeFetchHeadNotFoundException ex)
{
Expand Down Expand Up @@ -252,7 +252,7 @@ public void CanMergeFetchedRefs()
Assert.False(repo.RetrieveStatus().Any());
Assert.Equal(repo.Lookup<Commit>("refs/remotes/origin/master~1"), repo.Head.Tip);

Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null);
Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null, null);

MergeOptions mergeOptions = new MergeOptions()
{
Expand All @@ -279,7 +279,7 @@ public void CanPruneRefs()
using (var repo = new Repository(clonedRepoPath))
{
repo.Network.Remotes.Add("pruner", clonedRepoPath2);
Commands.Fetch(repo, "pruner", new string[0], null, null);
Commands.Fetch(repo, "pruner", new string[0], null, null, null);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);

// Remove the branch from the source repository
Expand All @@ -289,11 +289,11 @@ public void CanPruneRefs()
}

// and by default we don't prune it
Commands.Fetch(repo, "pruner", new string[0], null, null);
Commands.Fetch(repo, "pruner", new string[0], null, null, null);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);

// but we do when asked by the user
Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true}, null);
Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true}, null, new ProxyOptions());
Assert.Null(repo.Refs["refs/remotes/pruner/master"]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp.Tests/PushFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void CanPushABranchTrackingAnUpstreamBranch()
OnPackBuilderProgress = packBuilderCb,
};

AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options));
AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options, new ProxyOptions()));
Assert.True(packBuilderCalled);
}

Expand All @@ -102,7 +102,7 @@ public void CanInvokePrePushCallbackAndSucceed()
OnNegotiationCompletedBeforePush = prePushHook,
};

AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options));
AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options, new ProxyOptions()));
Assert.True(packBuilderCalled);
Assert.True(prePushHandlerCalled);
}
Expand Down Expand Up @@ -130,7 +130,7 @@ public void CanInvokePrePushCallbackAndFail()
OnNegotiationCompletedBeforePush = prePushHook
};

Assert.Throws<UserCancelledException>(() => { AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options)); });
Assert.Throws<UserCancelledException>(() => { AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options, new ProxyOptions())); });

Assert.False(packBuilderCalled);
Assert.True(prePushHandlerCalled);
Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ public void CanFetchFromRemoteByName()
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null, new ProxyOptions());

// Verify the expected state
expectedFetchState.CheckUpdatedReferences(repo);

// Now fetch the rest of the tags
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null, new ProxyOptions());

// Verify that the "nearly-dangling" tag is now in the repo.
Tag nearlyDanglingTag = repo.Tags["nearly-dangling"];
Expand Down Expand Up @@ -698,7 +698,7 @@ public void CanListRemoteReferencesWithCredentials()
"Populate Constants.PrivateRepo* to run this test");

IEnumerable<Reference> references = Repository.ListRemoteReferences(Constants.PrivateRepoUrl,
Constants.PrivateRepoCredentials);
Constants.PrivateRepoCredentials, new ProxyOptions());

foreach (var reference in references)
{
Expand Down
Loading