Skip to content

Commit 6e99ab0

Browse files
A-Ovchinnikov-mxAlexander Ovchinnikov
A-Ovchinnikov-mx
authored and
Alexander Ovchinnikov
committed
Enable proxy support
* Add ProxyOptions type and a corresponding parameter to networking methods
1 parent d4e22f8 commit 6e99ab0

16 files changed

+212
-97
lines changed

LibGit2Sharp.Tests/CloneFixture.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void CanCloneWithCheckoutBranchName(string branchName, string headTipId)
4343
{
4444
var scd = BuildSelfCleaningDirectory();
4545

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

4848
using (var repo = new Repository(clonedRepoPath))
4949
{
@@ -107,7 +107,7 @@ public void CanCloneBarely(string url)
107107
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
108108
{
109109
IsBare = true
110-
});
110+
}, new ProxyOptions());
111111

112112
using (var repo = new Repository(clonedRepoPath))
113113
{
@@ -130,7 +130,7 @@ public void WontCheckoutIfAskedNotTo(string url)
130130
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
131131
{
132132
Checkout = false
133-
});
133+
}, new ProxyOptions());
134134

135135
using (var repo = new Repository(clonedRepoPath))
136136
{
@@ -155,7 +155,7 @@ public void CallsProgressCallbacks(string url)
155155
OnProgress = progress => { progressWasCalled = true; return true; },
156156
OnUpdateTips = (name, oldId, newId) => { updateTipsWasCalled = true; return true; },
157157
OnCheckoutProgress = (a, b, c) => checkoutWasCalled = true
158-
});
158+
}, new ProxyOptions());
159159

160160
Assert.True(transferWasCalled);
161161
Assert.True(progressWasCalled);
@@ -175,7 +175,7 @@ public void CanCloneWithCredentials()
175175
new CloneOptions()
176176
{
177177
CredentialsProvider = Constants.PrivateRepoCredentials
178-
});
178+
}, new ProxyOptions());
179179

180180

181181
using (var repo = new Repository(clonedRepoPath))
@@ -289,7 +289,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
289289
};
290290

291291
Assert.Throws<UserCancelledException>(() =>
292-
Repository.Clone(url, scd.DirectoryPath, options)
292+
Repository.Clone(url, scd.DirectoryPath, options, new ProxyOptions())
293293
);
294294

295295
Assert.True(wasCalled);
@@ -437,7 +437,7 @@ public void CanRecursivelyCloneSubmodules()
437437
RepositoryOperationCompleted = repositoryOperationCompleted,
438438
};
439439

440-
string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
440+
string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions());
441441
string workDirPath;
442442

443443
using (Repository repo = new Repository(clonedRepoPath))
@@ -521,7 +521,7 @@ public void CanCancelRecursiveClone()
521521
};
522522

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

526526
// Cancel after super repository is cloned, but before submodule is cloned.
527527
cancelDepth = 1;
@@ -530,7 +530,7 @@ public void CanCancelRecursiveClone()
530530

531531
try
532532
{
533-
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
533+
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions());
534534
}
535535
catch (RecurseSubmodulesException ex)
536536
{
@@ -562,7 +562,7 @@ public void CannotCloneWithForbiddenCustomHeaders()
562562
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
563563
};
564564

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

568568
[Fact]
@@ -578,7 +578,7 @@ public void CannotCloneWithMalformedCustomHeaders()
578578
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
579579
};
580580

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

584584
[Fact]
@@ -594,7 +594,7 @@ public void CanCloneWithCustomHeaders()
594594
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
595595
};
596596

597-
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions);
597+
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions, new ProxyOptions());
598598
Assert.True(Directory.Exists(clonedRepoPath));
599599
}
600600
}

LibGit2Sharp.Tests/FetchFixture.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void CanFetchIntoAnEmptyRepository(string url)
4242
}
4343

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

4747
// Verify the expected
4848
expectedFetchState.CheckUpdatedReferences(repo);
@@ -65,7 +65,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
6565
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
6666
{
6767
CredentialsProvider = Constants.PrivateRepoCredentials
68-
}, null);
68+
}, null, new ProxyOptions());
6969
}
7070
}
7171

@@ -102,7 +102,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
102102
{
103103
TagFetchMode = TagFetchMode.All,
104104
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
105-
}, null);
105+
}, null, new ProxyOptions());
106106

107107
// Verify the expected
108108
expectedFetchState.CheckUpdatedReferences(repo);
@@ -148,7 +148,7 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local
148148
{
149149
TagFetchMode = TagFetchMode.None,
150150
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
151-
}, null);
151+
}, null, new ProxyOptions());
152152

153153
// Verify the expected
154154
expectedFetchState.CheckUpdatedReferences(repo);
@@ -179,7 +179,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
179179
r => r.TagFetchMode = tagFetchMode);
180180

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

184184
// Verify the number of fetched tags.
185185
Assert.Equal(expectedTagCount, repo.Tags.Count());
@@ -197,7 +197,7 @@ public void CanFetchAllTagsAfterAnInitialClone()
197197

198198
using (var repo = new Repository(clonedRepoPath))
199199
{
200-
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
200+
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null, new ProxyOptions());
201201
}
202202
}
203203

@@ -223,17 +223,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
223223

224224
// No pruning when the configuration entry isn't defined
225225
Assert.Null(clonedRepo.Config.Get<bool>("fetch.prune"));
226-
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
226+
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
227227
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
228228

229229
// No pruning when the configuration entry is set to false
230230
clonedRepo.Config.Set<bool>("fetch.prune", false);
231-
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
231+
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
232232
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
233233

234234
// Auto pruning when the configuration entry is set to true
235235
clonedRepo.Config.Set<bool>("fetch.prune", true);
236-
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
236+
Commands.Fetch(clonedRepo, "origin", new string[0], null, null, null);
237237
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
238238
}
239239
}
@@ -251,7 +251,7 @@ public void CannotFetchWithForbiddenCustomHeaders()
251251
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
252252
using (var repo = new Repository(clonedRepoPath))
253253
{
254-
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
254+
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions()));
255255
}
256256
}
257257

@@ -268,7 +268,7 @@ public void CanFetchWithCustomHeaders()
268268
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
269269
using (var repo = new Repository(clonedRepoPath))
270270
{
271-
Commands.Fetch(repo, "origin", new string[0], options, null);
271+
Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions());
272272
}
273273
}
274274

@@ -285,7 +285,7 @@ public void CannotFetchWithMalformedCustomHeaders()
285285
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
286286
using (var repo = new Repository(clonedRepoPath))
287287
{
288-
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
288+
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null, new ProxyOptions()));
289289
}
290290
}
291291

LibGit2Sharp.Tests/NetworkFixture.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void CanListRemoteReferencesWithCredentials()
127127
{
128128
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);
129129

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

132132
foreach (var reference in references)
133133
{
@@ -161,7 +161,7 @@ public void CanPull(FastForwardStrategy fastForwardStrategy)
161161
}
162162
};
163163

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

166166
if (fastForwardStrategy == FastForwardStrategy.Default || fastForwardStrategy == FastForwardStrategy.FastForwardOnly)
167167
{
@@ -194,7 +194,7 @@ public void CanPullIntoEmptyRepo()
194194
b => b.UpstreamBranch = "refs/heads/master");
195195

196196
// Pull!
197-
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions());
197+
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions(), new ProxyOptions());
198198

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

222222
try
223223
{
224-
Commands.Pull(repo, Constants.Signature, new PullOptions());
224+
Commands.Pull(repo, Constants.Signature, new PullOptions(), new ProxyOptions());
225225
}
226226
catch (MergeFetchHeadNotFoundException ex)
227227
{
@@ -249,7 +249,7 @@ public void CanMergeFetchedRefs()
249249
Assert.False(repo.RetrieveStatus().Any());
250250
Assert.Equal(repo.Lookup<Commit>("refs/remotes/origin/master~1"), repo.Head.Tip);
251251

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

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

282282
// Remove the branch from the source repository
@@ -286,11 +286,11 @@ public void CanPruneRefs()
286286
}
287287

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

292292
// but we do when asked by the user
293-
Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true }, null);
293+
Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true }, null, new ProxyOptions());
294294
Assert.Null(repo.Refs["refs/remotes/pruner/master"]);
295295
}
296296
}

LibGit2Sharp.Tests/PushFixture.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void CanPushABranchTrackingAnUpstreamBranch()
7575
OnPackBuilderProgress = packBuilderCb,
7676
};
7777

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

@@ -102,7 +102,7 @@ public void CanInvokePrePushCallbackAndSucceed()
102102
OnNegotiationCompletedBeforePush = prePushHook,
103103
};
104104

105-
AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options));
105+
AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options, new ProxyOptions()));
106106
Assert.True(packBuilderCalled);
107107
Assert.True(prePushHandlerCalled);
108108
}
@@ -130,7 +130,7 @@ public void CanInvokePrePushCallbackAndFail()
130130
OnNegotiationCompletedBeforePush = prePushHook
131131
};
132132

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

135135
Assert.False(packBuilderCalled);
136136
Assert.True(prePushHandlerCalled);

LibGit2Sharp.Tests/RepositoryFixture.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ public void CanFetchFromRemoteByName()
212212
}
213213

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

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

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

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

699699
IEnumerable<Reference> references = Repository.ListRemoteReferences(Constants.PrivateRepoUrl,
700-
Constants.PrivateRepoCredentials);
700+
Constants.PrivateRepoCredentials, new ProxyOptions());
701701

702702
foreach (var reference in references)
703703
{

LibGit2Sharp.Tests/SubmoduleFixture.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void UpdatingUninitializedSubmoduleThrows()
215215
Assert.NotNull(submodule);
216216
Assert.True(submodule.RetrieveStatus().HasFlag(SubmoduleStatus.WorkDirUninitialized));
217217

218-
Assert.Throws<LibGit2SharpException>(() => repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions()));
218+
Assert.Throws<LibGit2SharpException>(() => repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions(), new ProxyOptions()));
219219
}
220220
}
221221

@@ -244,7 +244,7 @@ public void CanUpdateSubmodule()
244244
};
245245

246246
repo.Submodules.Init(submodule.Name, false);
247-
repo.Submodules.Update(submodule.Name, options);
247+
repo.Submodules.Update(submodule.Name, options, new ProxyOptions());
248248

249249
Assert.True(submodule.RetrieveStatus().HasFlag(SubmoduleStatus.InWorkDir));
250250
Assert.True(checkoutProgressCalled);
@@ -269,7 +269,7 @@ public void CanInitializeAndUpdateSubmodule()
269269
Assert.NotNull(submodule);
270270
Assert.True(submodule.RetrieveStatus().HasFlag(SubmoduleStatus.WorkDirUninitialized));
271271

272-
repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions() { Init = true });
272+
repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions() { Init = true }, new ProxyOptions());
273273

274274
Assert.True(submodule.RetrieveStatus().HasFlag(SubmoduleStatus.InWorkDir));
275275
Assert.Equal((ObjectId)"480095882d281ed676fe5b863569520e54a7d5c0", submodule.HeadCommitId);
@@ -292,7 +292,7 @@ public void CanUpdateSubmoduleAfterCheckout()
292292
Assert.True(submodule.RetrieveStatus().HasFlag(SubmoduleStatus.WorkDirUninitialized));
293293

294294
repo.Submodules.Init(submodule.Name, false);
295-
repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions());
295+
repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions(), new ProxyOptions());
296296

297297
Assert.True(submodule.RetrieveStatus().HasFlag(SubmoduleStatus.InWorkDir));
298298

@@ -305,7 +305,7 @@ public void CanUpdateSubmoduleAfterCheckout()
305305
Assert.Equal((ObjectId)"5e4963595a9774b90524d35a807169049de8ccad", submodule.IndexCommitId);
306306
Assert.Equal((ObjectId)"480095882d281ed676fe5b863569520e54a7d5c0", submodule.WorkDirCommitId);
307307

308-
repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions());
308+
repo.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions(), new ProxyOptions());
309309
submodule = repo.Submodules[submoduleName];
310310

311311
Assert.Equal((ObjectId)"5e4963595a9774b90524d35a807169049de8ccad", submodule.HeadCommitId);

0 commit comments

Comments
 (0)