forked from git-ecosystem/git-credential-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitConfigurationTests.cs
More file actions
660 lines (543 loc) · 27.2 KB
/
GitConfigurationTests.cs
File metadata and controls
660 lines (543 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
using System;
using System.Collections.Generic;
using System.IO;
using GitCredentialManager.Tests.Objects;
using Xunit;
using static GitCredentialManager.Tests.GitTestUtilities;
namespace GitCredentialManager.Tests
{
public class GitConfigurationTests
{
[Theory]
[InlineData(null, "\"\"")]
[InlineData("", "\"\"")]
[InlineData("hello", "hello")]
[InlineData("hello world", "\"hello world\"")]
[InlineData("C:\\app.exe", "C:\\app.exe")]
[InlineData("C:\\path with space\\app.exe", "\"C:\\path with space\\app.exe\"")]
[InlineData("''", "\"''\"")]
[InlineData("'hello'", "\"'hello'\"")]
[InlineData("'hello world'", "\"'hello world'\"")]
[InlineData("'C:\\app.exe'", "\"'C:\\app.exe'\"")]
[InlineData("'C:\\path with space\\app.exe'", "\"'C:\\path with space\\app.exe'\"")]
[InlineData("\"\"", "\"\\\"\\\"\"")]
[InlineData("\"hello\"", "\"\\\"hello\\\"\"")]
[InlineData("\"hello world\"", "\"\\\"hello world\\\"\"")]
[InlineData("\"C:\\app.exe\"", "\"\\\"C:\\app.exe\\\"\"")]
[InlineData("\"C:\\path with space\\app.exe\"", "\"\\\"C:\\path with space\\app.exe\\\"\"")]
[InlineData("\\", "\\")]
[InlineData("\\\\", "\\\\")]
[InlineData("\\\\\\", "\\\\\\")]
[InlineData("\"", "\"\\\"\"")]
[InlineData("\\\"", "\"\\\\\\\"\"")]
[InlineData("\\\\\"", "\"\\\\\\\\\\\"\"")]
[InlineData("\"\\", "\"\\\"\\\\\"")]
[InlineData("\"\\\\", "\"\\\"\\\\\\\\\"")]
[InlineData("ab\\", "ab\\")]
[InlineData("a b\\", "\"a b\\\\\"")]
public void GitConfiguration_QuoteCmdArg(string input, string expected)
{
string actual = GitProcessConfiguration.QuoteCmdArg(input);
Assert.Equal(expected, actual);
}
[Fact]
public void GitProcess_GetConfiguration_ReturnsConfiguration()
{
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath);
var config = git.GetConfiguration();
Assert.NotNull(config);
}
[Fact]
public void GitConfiguration_Enumerate_CallbackReturnsTrue_InvokesCallbackForEachEntry()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local foo.name lancelot").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local foo.quest seek-holy-grail").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local foo.favcolor blue").AssertSuccess();
var expectedVisitedEntries = new List<(string name, string value)>
{
("foo.name", "lancelot"),
("foo.quest", "seek-holy-grail"),
("foo.favcolor", "blue")
};
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
var actualVisitedEntries = new List<(string name, string value)>();
bool cb(GitConfigurationEntry entry)
{
if (entry.Key.StartsWith("foo."))
{
actualVisitedEntries.Add((entry.Key, entry.Value));
}
// Continue enumeration
return true;
}
config.Enumerate(cb);
Assert.Equal(expectedVisitedEntries, actualVisitedEntries);
}
[Fact]
public void GitConfiguration_Enumerate_CallbackReturnsFalse_InvokesCallbackForEachEntryUntilReturnsFalse()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local foo.name lancelot").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local foo.quest seek-holy-grail").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local foo.favcolor blue").AssertSuccess();
var expectedVisitedEntries = new List<(string name, string value)>
{
("foo.name", "lancelot"),
("foo.quest", "seek-holy-grail")
};
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
var actualVisitedEntries = new List<(string name, string value)>();
bool cb(GitConfigurationEntry entry)
{
if (entry.Key.StartsWith("foo."))
{
actualVisitedEntries.Add((entry.Key, entry.Value));
}
// Stop enumeration after 2 'foo' entries
return actualVisitedEntries.Count < 2;
}
config.Enumerate(cb);
Assert.Equal(expectedVisitedEntries, actualVisitedEntries);
}
[Fact]
public void GitConfiguration_TryGet_Name_Exists_ReturnsTrueOutString()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local user.name john.doe").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
bool result = config.TryGet("user.name", false, out string value);
Assert.True(result);
Assert.NotNull(value);
Assert.Equal("john.doe", value);
}
[Fact]
public void GitConfiguration_TryGet_Name_DoesNotExists_ReturnsFalse()
{
string repoPath = CreateRepository();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
string randomName = $"{Guid.NewGuid():N}.{Guid.NewGuid():N}";
bool result = config.TryGet(randomName, false, out string value);
Assert.False(result);
Assert.Null(value);
}
[Fact]
public void GitConfiguration_TryGet_IsPath_True_ReturnsCanonicalPath()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local example.path ~/test").AssertSuccess();
string homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
bool result = config.TryGet("example.path", true, out string value);
Assert.True(result);
Assert.NotNull(value);
Assert.Equal(Path.GetFullPath($"{homeDirectory}/test").Replace("\\", "/"), value);
}
[Fact]
public void GitConfiguration_TryGet_IsPath_False_ReturnsRawConfig()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local example.path ~/test").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
bool result = config.TryGet("example.path", false, out string value);
Assert.True(result);
Assert.NotNull(value);
Assert.Equal($"~/test", value);
}
[Fact]
public void GitConfiguration_TryGet_BoolType_ReturnsCanonicalBool()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local example.bool fAlSe").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
bool result = config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Bool,
"example.bool", out string value);
Assert.True(result);
Assert.NotNull(value);
Assert.Equal("false", value);
}
[Fact]
public void GitConfiguration_TryGet_BoolWithoutType_ReturnsRawConfig()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local example.bool fAlSe").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
bool result = config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Raw,
"example.bool", out string value);
Assert.True(result);
Assert.NotNull(value);
Assert.Equal("fAlSe", value);
}
[Fact]
public void GitConfiguration_Get_Name_Exists_ReturnsString()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local user.name john.doe").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
string value = config.Get("user.name");
Assert.NotNull(value);
Assert.Equal("john.doe", value);
}
[Fact]
public void GitConfiguration_Get_Name_DoesNotExists_ThrowsException()
{
string repoPath = CreateRepository();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
string randomName = $"{Guid.NewGuid():N}.{Guid.NewGuid():N}";
Assert.Throws<KeyNotFoundException>(() => config.Get(randomName));
}
[Fact]
public void GitConfiguration_Set_Local_SetsLocalConfig()
{
string repoPath = CreateRepository(out string workDirPath);
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);;
IGitConfiguration config = git.GetConfiguration();
config.Set(GitConfigurationLevel.Local, "core.foobar", "foo123");
GitResult localResult = ExecGit(repoPath, workDirPath, "config --local core.foobar");
Assert.Equal("foo123", localResult.StandardOutput.Trim());
}
[Fact]
public void GitConfiguration_Set_All_ThrowsException()
{
string repoPath = CreateRepository(out _);
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
Assert.Throws<InvalidOperationException>(() =>
config.Set(GitConfigurationLevel.All, "core.foobar", "test123"));
}
[Fact]
public void GitConfiguration_Unset_Global_UnsetsGlobalConfig()
{
string repoPath = CreateRepository(out string workDirPath);
try
{
ExecGit(repoPath, workDirPath, "config --global core.foobar alice").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local core.foobar bob").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
config.Unset(GitConfigurationLevel.Global, "core.foobar");
GitResult globalResult = ExecGit(repoPath, workDirPath, "config --global core.foobar");
GitResult localResult = ExecGit(repoPath, workDirPath, "config --local core.foobar");
Assert.Equal(string.Empty, globalResult.StandardOutput.Trim());
Assert.Equal("bob", localResult.StandardOutput.Trim());
}
finally
{
// Cleanup global config changes
ExecGit(repoPath, workDirPath, "config --global --unset core.foobar");
}
}
[Fact]
public void GitConfiguration_Unset_Local_UnsetsLocalConfig()
{
string repoPath = CreateRepository(out string workDirPath);
try
{
ExecGit(repoPath, workDirPath, "config --global core.foobar alice").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local core.foobar bob").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
config.Unset(GitConfigurationLevel.Local, "core.foobar");
GitResult globalResult = ExecGit(repoPath, workDirPath, "config --global core.foobar");
GitResult localResult = ExecGit(repoPath, workDirPath, "config --local core.foobar");
Assert.Equal("alice", globalResult.StandardOutput.Trim());
Assert.Equal(string.Empty, localResult.StandardOutput.Trim());
}
finally
{
// Cleanup global config changes
ExecGit(repoPath, workDirPath, "config --global --unset core.foobar");
}
}
[Fact]
public void GitConfiguration_Unset_All_ThrowsException()
{
string repoPath = CreateRepository(out _);
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
Assert.Throws<InvalidOperationException>(() => config.Unset(GitConfigurationLevel.All, "core.foobar"));
}
[Fact]
public void GitConfiguration_UnsetAll_UnsetsAllConfig()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local --add core.foobar foo1").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local --add core.foobar foo2").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local --add core.foobar bar1").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
config.UnsetAll(GitConfigurationLevel.Local, "core.foobar", "foo*");
GitResult result = ExecGit(repoPath, workDirPath, "config --local --get-all core.foobar");
Assert.Equal("bar1", result.StandardOutput.Trim());
}
[Fact]
public void GitConfiguration_UnsetAll_All_ThrowsException()
{
string repoPath = CreateRepository(out _);
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
Assert.Throws<InvalidOperationException>(() =>
config.UnsetAll(GitConfigurationLevel.All, "core.foobar", Constants.RegexPatterns.Any));
}
[Fact]
public void GitConfiguration_CacheTryGet_ReturnsValueFromCache()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local user.name john.doe").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local user.email [email protected]").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
// First access loads cache
bool result1 = config.TryGet("user.name", false, out string value1);
Assert.True(result1);
Assert.Equal("john.doe", value1);
// Second access should use cache
bool result2 = config.TryGet("user.email", false, out string value2);
Assert.True(result2);
Assert.Equal("[email protected]", value2);
}
[Fact]
public void GitConfiguration_CacheGetAll_ReturnsAllValuesFromCache()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local --add test.multi value1").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local --add test.multi value2").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local --add test.multi value3").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
var values = new List<string>(config.GetAll("test.multi"));
Assert.Equal(3, values.Count);
Assert.Equal("value1", values[0]);
Assert.Equal("value2", values[1]);
Assert.Equal("value3", values[2]);
}
[Fact]
public void GitConfiguration_CacheEnumerate_EnumeratesFromCache()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local cache.name test-value").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local cache.enabled true").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
var cacheEntries = new List<(string key, string value)>();
config.Enumerate(entry =>
{
if (entry.Key.StartsWith("cache."))
{
cacheEntries.Add((entry.Key, entry.Value));
}
return true;
});
Assert.Equal(2, cacheEntries.Count);
Assert.Contains(("cache.name", "test-value"), cacheEntries);
Assert.Contains(("cache.enabled", "true"), cacheEntries);
}
[Fact]
public void GitConfiguration_CacheInvalidation_SetInvalidatesCache()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local test.value initial").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
// Load cache with initial value
bool result1 = config.TryGet("test.value", false, out string value1);
Assert.True(result1);
Assert.Equal("initial", value1);
// Set new value (should invalidate cache)
config.Set(GitConfigurationLevel.Local, "test.value", "updated");
// Next read should get updated value
bool result2 = config.TryGet("test.value", false, out string value2);
Assert.True(result2);
Assert.Equal("updated", value2);
}
[Fact]
public void GitConfiguration_CacheInvalidation_AddInvalidatesCache()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local test.multi first").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
// Load cache
var values1 = new List<string>(config.GetAll("test.multi"));
Assert.Single(values1);
Assert.Equal("first", values1[0]);
// Add new value (should invalidate cache)
config.Add(GitConfigurationLevel.Local, "test.multi", "second");
// Next read should include new value
var values2 = new List<string>(config.GetAll("test.multi"));
Assert.Equal(2, values2.Count);
Assert.Equal("first", values2[0]);
Assert.Equal("second", values2[1]);
}
[Fact]
public void GitConfiguration_CacheInvalidation_UnsetInvalidatesCache()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local test.value exists").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
// Load cache
bool result1 = config.TryGet("test.value", false, out string value1);
Assert.True(result1);
Assert.Equal("exists", value1);
// Unset value (should invalidate cache)
config.Unset(GitConfigurationLevel.Local, "test.value");
// Next read should not find value
bool result2 = config.TryGet("test.value", false, out string value2);
Assert.False(result2);
Assert.Null(value2);
}
[Fact]
public void GitConfiguration_CacheLevelFilter_ReturnsOnlyLocalValues()
{
string repoPath = CreateRepository(out string workDirPath);
try
{
ExecGit(repoPath, workDirPath, "config --global test.level global-value").AssertSuccess();
ExecGit(repoPath, workDirPath, "config --local test.level local-value").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
// Get local value only
bool result = config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Raw,
"test.level", out string value);
Assert.True(result);
Assert.Equal("local-value", value);
}
finally
{
// Cleanup global config
ExecGit(repoPath, workDirPath, "config --global --unset test.level");
}
}
[Fact]
public void GitConfiguration_TypedQuery_CanonicalizesValues()
{
string repoPath = CreateRepository(out string workDirPath);
ExecGit(repoPath, workDirPath, "config --local test.path ~/example").AssertSuccess();
string gitPath = GetGitPath();
var trace = new NullTrace();
var trace2 = new NullTrace2();
var processManager = new TestProcessManager();
var git = new GitProcess(trace, trace2, processManager, gitPath, repoPath);
IGitConfiguration config = git.GetConfiguration();
// Path type queries use a separate cache loaded with --type=path,
// so Git canonicalizes the values during cache load.
bool result = config.TryGet(GitConfigurationLevel.Local, GitConfigurationType.Path,
"test.path", out string value);
Assert.True(result);
Assert.NotNull(value);
// Value should be canonicalized path, not raw "~/example"
Assert.NotEqual("~/example", value);
}
}
}