Skip to content

Commit 31af9ab

Browse files
committed
trace2: pass to Git
Pass instance of Trace2 to Git in preparation for capturing exceptions, which will be added in a future commit.
1 parent 9a2f912 commit 31af9ab

File tree

4 files changed

+72
-62
lines changed

4 files changed

+72
-62
lines changed

src/shared/Core.Tests/GitConfigurationTests.cs

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public void GitProcess_GetConfiguration_ReturnsConfiguration()
4747
{
4848
string gitPath = GetGitPath();
4949
var trace = new NullTrace();
50-
var env = new TestEnvironment();
50+
var trace2 = new NullTrace2();
5151
var processManager = new TestProcessManager();
52-
var git = new GitProcess(trace, processManager, gitPath);
52+
var git = new GitProcess(trace, trace2, processManager, gitPath);
5353
var config = git.GetConfiguration();
5454
Assert.NotNull(config);
5555
}
@@ -71,9 +71,9 @@ public void GitConfiguration_Enumerate_CallbackReturnsTrue_InvokesCallbackForEac
7171

7272
string gitPath = GetGitPath();
7373
var trace = new NullTrace();
74-
var env = new TestEnvironment();
74+
var trace2 = new NullTrace2();
7575
var processManager = new TestProcessManager();
76-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
76+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
7777
IGitConfiguration config = git.GetConfiguration();
7878

7979
var actualVisitedEntries = new List<(string name, string value)>();
@@ -110,9 +110,9 @@ public void GitConfiguration_Enumerate_CallbackReturnsFalse_InvokesCallbackForEa
110110

111111
string gitPath = GetGitPath();
112112
var trace = new NullTrace();
113-
var env = new TestEnvironment();
113+
var trace2 = new NullTrace2();
114114
var processManager = new TestProcessManager();
115-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
115+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
116116
IGitConfiguration config = git.GetConfiguration();
117117

118118
var actualVisitedEntries = new List<(string name, string value)>();
@@ -138,13 +138,12 @@ public void GitConfiguration_TryGet_Name_Exists_ReturnsTrueOutString()
138138
{
139139
string repoPath = CreateRepository(out string workDirPath);
140140
ExecGit(repoPath, workDirPath, "config --local user.name john.doe").AssertSuccess();
141-
142141
string gitPath = GetGitPath();
143142
var trace = new NullTrace();
144-
var env = new TestEnvironment();
143+
var trace2 = new NullTrace2();
145144
var processManager = new TestProcessManager();
146145

147-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
146+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
148147
IGitConfiguration config = git.GetConfiguration();
149148

150149
bool result = config.TryGet("user.name", false, out string value);
@@ -160,9 +159,10 @@ public void GitConfiguration_TryGet_Name_DoesNotExists_ReturnsFalse()
160159

161160
string gitPath = GetGitPath();
162161
var trace = new NullTrace();
163-
var env = new TestEnvironment();
162+
163+
var trace2 = new NullTrace2();
164164
var processManager = new TestProcessManager();
165-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
165+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
166166
IGitConfiguration config = git.GetConfiguration();
167167

168168
string randomName = $"{Guid.NewGuid():N}.{Guid.NewGuid():N}";
@@ -180,9 +180,9 @@ public void GitConfiguration_TryGet_IsPath_True_ReturnsCanonicalPath()
180180
string homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
181181
string gitPath = GetGitPath();
182182
var trace = new NullTrace();
183-
var env = new TestEnvironment();
183+
var trace2 = new NullTrace2();
184184
var processManager = new TestProcessManager();
185-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
185+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
186186
IGitConfiguration config = git.GetConfiguration();
187187

188188
bool result = config.TryGet("example.path", true, out string value);
@@ -199,9 +199,9 @@ public void GitConfiguration_TryGet_IsPath_False_ReturnsRawConfig()
199199

200200
string gitPath = GetGitPath();
201201
var trace = new NullTrace();
202-
var env = new TestEnvironment();
202+
var trace2 = new NullTrace2();
203203
var processManager = new TestProcessManager();
204-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
204+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
205205
IGitConfiguration config = git.GetConfiguration();
206206

207207
bool result = config.TryGet("example.path", false, out string value);
@@ -218,9 +218,9 @@ public void GitConfiguration_TryGet_BoolType_ReturnsCanonicalBool()
218218

219219
string gitPath = GetGitPath();
220220
var trace = new NullTrace();
221-
var env = new TestEnvironment();
221+
var trace2 = new NullTrace2();
222222
var processManager = new TestProcessManager();
223-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
223+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
224224
IGitConfiguration config = git.GetConfiguration();
225225

226226
bool result = config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Bool,
@@ -238,9 +238,9 @@ public void GitConfiguration_TryGet_BoolWithoutType_ReturnsRawConfig()
238238

239239
string gitPath = GetGitPath();
240240
var trace = new NullTrace();
241-
var env = new TestEnvironment();
241+
var trace2 = new NullTrace2();
242242
var processManager = new TestProcessManager();
243-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
243+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
244244
IGitConfiguration config = git.GetConfiguration();
245245

246246
bool result = config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Raw,
@@ -258,9 +258,10 @@ public void GitConfiguration_Get_Name_Exists_ReturnsString()
258258

259259
string gitPath = GetGitPath();
260260
var trace = new NullTrace();
261-
var env = new TestEnvironment();
261+
var trace2 = new NullTrace2();
262262
var processManager = new TestProcessManager();
263-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
263+
264+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
264265
IGitConfiguration config = git.GetConfiguration();
265266

266267
string value = config.Get("user.name");
@@ -275,9 +276,9 @@ public void GitConfiguration_Get_Name_DoesNotExists_ThrowsException()
275276

276277
string gitPath = GetGitPath();
277278
var trace = new NullTrace();
278-
var env = new TestEnvironment();
279+
var trace2 = new NullTrace2();
279280
var processManager = new TestProcessManager();
280-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
281+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
281282
IGitConfiguration config = git.GetConfiguration();
282283

283284
string randomName = $"{Guid.NewGuid():N}.{Guid.NewGuid():N}";
@@ -291,16 +292,16 @@ public void GitConfiguration_Set_Local_SetsLocalConfig()
291292

292293
string gitPath = GetGitPath();
293294
var trace = new NullTrace();
294-
var env = new TestEnvironment();
295+
var trace2 = new NullTrace2();
295296
var processManager = new TestProcessManager();
296-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
297+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);;
297298
IGitConfiguration config = git.GetConfiguration();
298299

299300
config.Set(GitConfigurationLevel.Local, "core.foobar", "foo123");
300301

301302
GitResult localResult = ExecGit(repoPath, workDirPath, "config --local core.foobar");
302303

303-
Assert.Equal("foo123", localResult.StandardOutput.Trim());
304+
Assert.Equal("foo123", localResult.StandardOutput.Trim());
304305
}
305306

306307
[Fact]
@@ -310,12 +311,13 @@ public void GitConfiguration_Set_All_ThrowsException()
310311

311312
string gitPath = GetGitPath();
312313
var trace = new NullTrace();
313-
var env = new TestEnvironment();
314+
var trace2 = new NullTrace2();
314315
var processManager = new TestProcessManager();
315-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
316+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
316317
IGitConfiguration config = git.GetConfiguration();
317318

318-
Assert.Throws<InvalidOperationException>(() => config.Set(GitConfigurationLevel.All, "core.foobar", "test123"));
319+
Assert.Throws<InvalidOperationException>(() =>
320+
config.Set(GitConfigurationLevel.All, "core.foobar", "test123"));
319321
}
320322

321323
[Fact]
@@ -324,15 +326,14 @@ public void GitConfiguration_Unset_Global_UnsetsGlobalConfig()
324326
string repoPath = CreateRepository(out string workDirPath);
325327
try
326328
{
327-
328329
ExecGit(repoPath, workDirPath, "config --global core.foobar alice").AssertSuccess();
329330
ExecGit(repoPath, workDirPath, "config --local core.foobar bob").AssertSuccess();
330331

331332
string gitPath = GetGitPath();
332333
var trace = new NullTrace();
333-
var env = new TestEnvironment();
334+
var trace2 = new NullTrace2();
334335
var processManager = new TestProcessManager();
335-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
336+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
336337
IGitConfiguration config = git.GetConfiguration();
337338

338339
config.Unset(GitConfigurationLevel.Global, "core.foobar");
@@ -362,9 +363,9 @@ public void GitConfiguration_Unset_Local_UnsetsLocalConfig()
362363

363364
string gitPath = GetGitPath();
364365
var trace = new NullTrace();
365-
var env = new TestEnvironment();
366+
var trace2 = new NullTrace2();
366367
var processManager = new TestProcessManager();
367-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
368+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
368369
IGitConfiguration config = git.GetConfiguration();
369370

370371
config.Unset(GitConfigurationLevel.Local, "core.foobar");
@@ -389,9 +390,9 @@ public void GitConfiguration_Unset_All_ThrowsException()
389390

390391
string gitPath = GetGitPath();
391392
var trace = new NullTrace();
392-
var env = new TestEnvironment();
393+
var trace2 = new NullTrace2();
393394
var processManager = new TestProcessManager();
394-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
395+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
395396
IGitConfiguration config = git.GetConfiguration();
396397

397398
Assert.Throws<InvalidOperationException>(() => config.Unset(GitConfigurationLevel.All, "core.foobar"));
@@ -407,9 +408,9 @@ public void GitConfiguration_UnsetAll_UnsetsAllConfig()
407408

408409
string gitPath = GetGitPath();
409410
var trace = new NullTrace();
410-
var env = new TestEnvironment();
411+
var trace2 = new NullTrace2();
411412
var processManager = new TestProcessManager();
412-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
413+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
413414
IGitConfiguration config = git.GetConfiguration();
414415

415416
config.UnsetAll(GitConfigurationLevel.Local, "core.foobar", "foo*");
@@ -426,12 +427,14 @@ public void GitConfiguration_UnsetAll_All_ThrowsException()
426427

427428
string gitPath = GetGitPath();
428429
var trace = new NullTrace();
429-
var env = new TestEnvironment();
430+
431+
var trace2 = new NullTrace2();
430432
var processManager = new TestProcessManager();
431-
var git = new GitProcess(trace, processManager, gitPath, repoPath);
433+
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
432434
IGitConfiguration config = git.GetConfiguration();
433435

434-
Assert.Throws<InvalidOperationException>(() => config.UnsetAll(GitConfigurationLevel.All, "core.foobar", Constants.RegexPatterns.Any));
436+
Assert.Throws<InvalidOperationException>(() =>
437+
config.UnsetAll(GitConfigurationLevel.All, "core.foobar", Constants.RegexPatterns.Any));
435438
}
436439
}
437440
}

src/shared/Core.Tests/GitTests.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public void Git_GetCurrentRepository_NoLocalRepo_ReturnsNull()
1313
{
1414
string gitPath = GetGitPath();
1515
var trace = new NullTrace();
16-
var env = new TestEnvironment();
16+
var trace2 = new NullTrace2();
1717
var processManager = new TestProcessManager();
18-
var git = new GitProcess(trace, processManager, gitPath, Path.GetTempPath());
18+
var git = new GitProcess(trace, trace2, processManager, gitPath, Path.GetTempPath());
1919

2020
string actual = git.GetCurrentRepository();
2121

@@ -29,9 +29,9 @@ public void Git_GetCurrentRepository_LocalRepo_ReturnsNotNull()
2929

3030
string gitPath = GetGitPath();
3131
var trace = new NullTrace();
32-
var env = new TestEnvironment();
32+
var trace2 = new NullTrace2();
3333
var processManager = new TestProcessManager();
34-
var git = new GitProcess(trace, processManager, gitPath, workDirPath);
34+
var git = new GitProcess(trace, trace2, processManager, gitPath, workDirPath);
3535

3636
string actual = git.GetCurrentRepository();
3737

@@ -43,9 +43,9 @@ public void Git_GetRemotes_NoLocalRepo_ReturnsEmpty()
4343
{
4444
string gitPath = GetGitPath();
4545
var trace = new NullTrace();
46-
var env = new TestEnvironment();
46+
var trace2 = new NullTrace2();
4747
var processManager = new TestProcessManager();
48-
var git = new GitProcess(trace, processManager, gitPath, Path.GetTempPath());
48+
var git = new GitProcess(trace, trace2, processManager, gitPath, Path.GetTempPath());
4949

5050
GitRemote[] remotes = git.GetRemotes().ToArray();
5151

@@ -59,9 +59,9 @@ public void Git_GetRemotes_NoRemotes_ReturnsEmpty()
5959

6060
string gitPath = GetGitPath();
6161
var trace = new NullTrace();
62-
var env = new TestEnvironment();
62+
var trace2 = new NullTrace2();
6363
var processManager = new TestProcessManager();
64-
var git = new GitProcess(trace, processManager, gitPath, workDirPath);
64+
var git = new GitProcess(trace, trace2, processManager, gitPath, workDirPath);
6565

6666
GitRemote[] remotes = git.GetRemotes().ToArray();
6767

@@ -78,10 +78,10 @@ public void Git_GetRemotes_OneRemote_ReturnsRemote()
7878

7979
string gitPath = GetGitPath();
8080
var trace = new NullTrace();
81-
var env = new TestEnvironment();
81+
var trace2 = new NullTrace2();
8282
var processManager = new TestProcessManager();
8383

84-
var git = new GitProcess(trace, processManager, gitPath, workDirPath);
84+
var git = new GitProcess(trace, trace2, processManager, gitPath, workDirPath);
8585
GitRemote[] remotes = git.GetRemotes().ToArray();
8686

8787
Assert.Single(remotes);
@@ -100,10 +100,10 @@ public void Git_GetRemotes_OneRemoteFetchAndPull_ReturnsRemote()
100100

101101
string gitPath = GetGitPath();
102102
var trace = new NullTrace();
103-
var env = new TestEnvironment();
103+
var trace2 = new NullTrace2();
104104
var processManager = new TestProcessManager();
105105

106-
var git = new GitProcess(trace, processManager, gitPath, workDirPath);
106+
var git = new GitProcess(trace, trace2, processManager, gitPath, workDirPath);
107107
GitRemote[] remotes = git.GetRemotes().ToArray();
108108

109109
Assert.Single(remotes);
@@ -124,10 +124,10 @@ public void Git_GetRemotes_NonHttpRemote_ReturnsRemote(string url)
124124

125125
string gitPath = GetGitPath();
126126
var trace = new NullTrace();
127-
var env = new TestEnvironment();
127+
var trace2 = new NullTrace2();
128128
var processManager = new TestProcessManager();
129129

130-
var git = new GitProcess(trace, processManager, gitPath, workDirPath);
130+
var git = new GitProcess(trace, trace2, processManager, gitPath, workDirPath);
131131
GitRemote[] remotes = git.GetRemotes().ToArray();
132132

133133
Assert.Single(remotes);
@@ -150,10 +150,10 @@ public void Git_GetRemotes_MultipleRemotes_ReturnsAllRemotes()
150150

151151
string gitPath = GetGitPath();
152152
var trace = new NullTrace();
153-
var env = new TestEnvironment();
153+
var trace2 = new NullTrace2();
154154
var processManager = new TestProcessManager();
155155

156-
var git = new GitProcess(trace, processManager, gitPath, workDirPath);
156+
var git = new GitProcess(trace, trace2, processManager, gitPath, workDirPath);
157157
GitRemote[] remotes = git.GetRemotes().ToArray();
158158

159159
Assert.Equal(3, remotes.Length);
@@ -175,10 +175,10 @@ public void Git_GetRemotes_RemoteNoFetchOnlyPull_ReturnsRemote()
175175

176176
string gitPath = GetGitPath();
177177
var trace = new NullTrace();
178-
var env = new TestEnvironment();
178+
var trace2 = new NullTrace2();
179179
var processManager = new TestProcessManager();
180180

181-
var git = new GitProcess(trace, processManager, gitPath, workDirPath);
181+
var git = new GitProcess(trace, trace2, processManager, gitPath, workDirPath);
182182
GitRemote[] remotes = git.GetRemotes().ToArray();
183183

184184
Assert.Single(remotes);
@@ -191,13 +191,14 @@ public void Git_Version_ReturnsVersion()
191191
{
192192
string gitPath = GetGitPath();
193193
var trace = new NullTrace();
194-
var env = new TestEnvironment();
194+
var trace2 = new NullTrace2();
195195
var processManager = new TestProcessManager();
196196

197-
var git = new GitProcess(trace, processManager, gitPath, Path.GetTempPath());
197+
var git = new GitProcess(trace, trace2, processManager, gitPath, Path.GetTempPath());
198198
GitVersion version = git.Version;
199199

200200
Assert.NotEqual(new GitVersion(), version);
201+
201202
}
202203

203204
#region Test Helpers

0 commit comments

Comments
 (0)