Skip to content

Commit 8fd7448

Browse files
author
A-Ovchinnikov-mx
authored
Enable configurable proxy support (#14)
* Update libgit2 to v1.1.1 * Add ProxyOptions type and a corresponding parameter to networking methods
1 parent 2504c52 commit 8fd7448

18 files changed

+212
-101
lines changed

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void CanCloneWithCheckoutBranchName(string branchName, string headTipId)
4646
{
4747
var scd = BuildSelfCleaningDirectory();
4848

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

5151
using (var repo = new Repository(clonedRepoPath))
5252
{
@@ -112,7 +112,7 @@ public void CanCloneBarely(string url)
112112
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
113113
{
114114
IsBare = true
115-
});
115+
}, new ProxyOptions());
116116

117117
using (var repo = new Repository(clonedRepoPath))
118118
{
@@ -135,7 +135,7 @@ public void WontCheckoutIfAskedNotTo(string url)
135135
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
136136
{
137137
Checkout = false
138-
});
138+
}, new ProxyOptions());
139139

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

165165
Assert.True(transferWasCalled);
166166
Assert.True(progressWasCalled);
@@ -180,7 +180,7 @@ public void CanCloneWithCredentials()
180180
new CloneOptions()
181181
{
182182
CredentialsProvider = Constants.PrivateRepoCredentials
183-
});
183+
}, new ProxyOptions());
184184

185185

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

228228
using (var repo = new Repository(clonedRepoPath))
229229
{
@@ -290,7 +290,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
290290
};
291291

292292
Assert.Throws<UserCancelledException>(() =>
293-
Repository.Clone(url, scd.DirectoryPath, options)
293+
Repository.Clone(url, scd.DirectoryPath, options, new ProxyOptions())
294294
);
295295

296296
Assert.True(wasCalled);
@@ -438,7 +438,7 @@ public void CanRecursivelyCloneSubmodules()
438438
RepositoryOperationCompleted = repositoryOperationCompleted,
439439
};
440440

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

444444
using(Repository repo = new Repository(clonedRepoPath))
@@ -522,7 +522,7 @@ public void CanCancelRecursiveClone()
522522
};
523523

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

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

532532
try
533533
{
534-
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
534+
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options, new ProxyOptions());
535535
}
536536
catch(RecurseSubmodulesException ex)
537537
{
@@ -563,7 +563,7 @@ public void CannotCloneWithForbiddenCustomHeaders()
563563
FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
564564
};
565565

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

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

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

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

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

LibGit2Sharp.Tests/FetchFixture.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void CanFetchIntoAnEmptyRepository(string url)
4444
}
4545

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

4949
// Verify the expected
5050
expectedFetchState.CheckUpdatedReferences(repo);
@@ -67,7 +67,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
6767
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
6868
{
6969
CredentialsProvider = Constants.PrivateRepoCredentials
70-
}, null);
70+
}, null, new ProxyOptions());
7171
}
7272
}
7373

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

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

155155
// Verify the expected
156156
expectedFetchState.CheckUpdatedReferences(repo);
@@ -181,7 +181,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
181181
r => r.TagFetchMode = tagFetchMode);
182182

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

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

200200
using (var repo = new Repository(clonedRepoPath))
201201
{
202-
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
202+
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null, new ProxyOptions());
203203
}
204204
}
205205

@@ -225,17 +225,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
225225

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

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

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

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

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

LibGit2Sharp.Tests/NetworkFixture.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void CanListRemoteReferencesWithCredentials()
130130
{
131131
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);
132132

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

135135
foreach (var reference in references)
136136
{
@@ -164,7 +164,7 @@ public void CanPull(FastForwardStrategy fastForwardStrategy)
164164
}
165165
};
166166

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

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

199199
// Pull!
200-
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions());
200+
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions(), new ProxyOptions());
201201

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

225225
try
226226
{
227-
Commands.Pull(repo, Constants.Signature, new PullOptions());
227+
Commands.Pull(repo, Constants.Signature, new PullOptions(), new ProxyOptions());
228228
}
229229
catch(MergeFetchHeadNotFoundException ex)
230230
{
@@ -252,7 +252,7 @@ public void CanMergeFetchedRefs()
252252
Assert.False(repo.RetrieveStatus().Any());
253253
Assert.Equal(repo.Lookup<Commit>("refs/remotes/origin/master~1"), repo.Head.Tip);
254254

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

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

285285
// Remove the branch from the source repository
@@ -289,11 +289,11 @@ public void CanPruneRefs()
289289
}
290290

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

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

LibGit2Sharp.Tests/PushFixture.cs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ public void CanFetchFromRemoteByName()
213213
}
214214

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

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

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

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

700700
IEnumerable<Reference> references = Repository.ListRemoteReferences(Constants.PrivateRepoUrl,
701-
Constants.PrivateRepoCredentials);
701+
Constants.PrivateRepoCredentials, new ProxyOptions());
702702

703703
foreach (var reference in references)
704704
{

0 commit comments

Comments
 (0)