8000 Make repo.Config.Get() return the originating store · Saaman/libgit2sharp@3cb5145 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3cb5145

Browse files
yorahnulltoken
authored andcommitted
Make repo.Config.Get() return the originating store
Signed-off-by: Unit Test <yoram.harmelin@gmail.com>
1 parent 0332c35 commit 3cb5145

14 files changed

+281
-175
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,12 @@ public void CanCommitWithSignatureFromConfig()
500500
AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n");
501501
AssertBlobContent(commit[relativeFilepath], "nulltoken\n");
502502

503-
var name = repo.Config.Get<string>("user.name", null);
504-
var email = repo.Config.Get<string>("user.email", null);
505-
Assert.Equal(commit.Author.Name, name);
506-
Assert.Equal(commit.Author.Email, email);
507-
Assert.Equal(commit.Committer.Name, name);
508-
Assert.Equal(commit.Committer.Email, email);
503+
var name = repo.Config.Get<string>("user.name");
504+
var email = repo.Config.Get<string>("user.email");
505+
Assert.Equal(commit.Author.Name, name.Value);
506+
Assert.Equal(commit.Author.Email, email.Value);
507+
Assert.Equal(commit.Committer.Name, name.Value);
508+
Assert.Equal(commit.Committer.Email, email.Value);
509509
}
510510
}
511511

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public void CanUnsetAnEntryFromTheLocalConfiguration()
5050
var path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
5151
using (var repo = new Repository(path.RepositoryPath))
5252
{
53-
Assert.False(repo.Config.Get<bool>("unittests.boolsetting", false));
53+
Assert.Null(repo.Config.Get<bool>("unittests.boolsetting"));
5454

5555
repo.Config.Set("unittests.boolsetting", true);
56-
Assert.True(repo.Config.Get<bool>("unittests.boolsetting", false));
56+
Assert.True(repo.Config.Get<bool>("unittests.boolsetting").Value);
5757

5858
repo.Config.Unset("unittests.boolsetting");
5959

60-
Assert.False(repo.Config.Get<bool>("unittests.boolsetting", false));
60+
Assert.Null(repo.Config.Get<bool>("unittests.boolsetting"));
6161
}
6262
}
6363

@@ -88,13 +88,13 @@ public void CanUnsetAnEntryFromTheGlobalConfiguration()
8888
using (var repo = new Repository(BareTestRepoPath, options))
8989
{
9090
Assert.True(repo.Config.HasGlobalConfig);
91-
Assert.Equal(42, repo.Config.Get("Wow.Man-I-am-totally-global", 1337));
91+
Assert.Equal(42, repo.Config.Get<int>("Wow.Man-I-am-totally-global").Value);
9292

9393
repo.Config.Unset("Wow.Man-I-am-totally-global");
94-
Assert.Equal(42, repo.Config.Get("Wow.Man-I-am-totally-global", 1337));
94+
Assert.Equal(42, repo.Config.Get<int>("Wow.Man-I-am-totally-global").Value);
9595

9696
repo.Config.Unset("Wow.Man-I-am-totally-global", ConfigurationLevel.Global);
97-
Assert.Equal(1337, repo.Config.Get("Wow.Man-I-am-totally-global", 1337));
97+
Assert.Null(repo.Config.Get<int>("Wow.Man-I-am-totally-global"));
9898
}
9999
}
100100

@@ -105,7 +105,7 @@ public void CanGetGlobalStringValue()
105105
{
106106
InconclusiveIf(() => !repo.Config.HasGlobalConfig, "No Git global configuration available");
107107

108-
Assert.NotNull(repo.Config.Get<string>("user.name", null));
108+
Assert.NotNull(repo.Config.Get<string>("user.name"));
109109
}
110110
}
111111

@@ -115,7 +115,7 @@ public void CanGetGlobalStringValueWithoutRepo()
115115
using (var config = new Configuration())
116116
{
117117
InconclusiveIf(() => !config.HasGlobalConfig, "No Git global configuration available");
118-
Assert.NotNull(config.Get<string>("user.name", null));
118+
Assert.NotNull(config.Get<string>("user.name"));
119119
}
120120
}
121121

@@ -124,8 +124,7 @@ public void CanReadBooleanValue()
124124
{
125125
using (var repo = new Repository(StandardTestRepoPath))
126126
{
127-
Assert.True(repo.Config.Get<bool>("core.ignorecase", false));
128-
Assert.True(repo.Config.Get<bool>("core", "ignorecase", false));
127+
Assert.True(repo.Config.Get<bool>("core.ignorecase").Value);
129128
}
130129
}
131130

@@ -134,8 +133,7 @@ public void CanReadIntValue()
134133
{
135134
using (var repo = new Repository(StandardTestRepoPath))
136135
{
137-
Assert.Equal(2, repo.Config.Get<int>("unittests.intsetting", 42));
138-
Assert.Equal(2, repo.Config.Get<int>("unittests", "intsetting", 42));
136+
Assert.Equal(2, repo.Config.Get<int>("unittests.intsetting").Value);
139137
}
140138
}
141139

@@ -144,8 +142,7 @@ public void CanReadLongValue()
144142
{
145143
using (var repo = new Repository(StandardTestRepoPath))
146144
{
147-
Assert.Equal(15234, repo.Config.Get<long>("unittests.longsetting", 42));
148-
Assert.Equal(15234, repo.Config.Get<long>("unittests", "longsetting", 42));
145+
Assert.Equal(15234, repo.Config.Get<long>("unittests.longsetting").Value);
149146
}
150147
}
151148

@@ -154,8 +151,8 @@ public void CanReadStringValue()
154151
{
155152
using (var repo = new Repository(StandardTestRepoPath))
156153
{
157-
Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.Get<string>("remote.origin.fetch", null));
158-
Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.Get<string>("remote", "origin", "fetch", null));
154+
Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.Get<string>("remote.origin.fetch").Value);
155+
Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.Get<string>("remote", "origin", "fetch").Value);
159156
}
160157
}
161158

@@ -165,7 +162,7 @@ public void CanEnumerateGlobalConfig()
165162
using (var repo = new Repository(StandardTestRepoPath))
166163
{
167164
InconclusiveIf(() => !repo.Config.HasGlobalConfig, "No Git global configuration available");
168-
var entry = repo.Config.FirstOrDefault(e => e.Key == "user.name");
165+
var entry = repo.Config.FirstOrDefault<ConfigurationEntry<string>>(e => e.Key == "user.name");
169166
Assert.NotNull(entry);
170167
Assert.NotNull(entry.Value);
171168
}
@@ -176,7 +173,7 @@ public void CanEnumerateLocalConfig()
176173
{
177174
using (var repo = new Repository(StandardTestRepoPath))
178175
{
179-
var entry = repo.Config.FirstOrDefault(e => e.Key == "core.ignorecase");
176+
var entry = repo.Config.FirstOrDefault<ConfigurationEntry<string>>(e => e.Key == "core.ignorecase");
180177
Assert.NotNull(entry);
181178
Assert.Equal("true", entry.Value);
182179
}
@@ -201,7 +198,7 @@ public void CanSetGlobalStringValue()
201198
{
202199
InconclusiveIf(() => !repo.Config.HasGlobalConfig, "No Git global configuration available");
203200

204-
var existing = repo.Config.Get<string>("user.name", null);
201+
var existing = repo.Config.Get<string>("user.name");
205202
Assert.NotNull(existing);
206203

207204
try
@@ -212,7 +209,7 @@ public void CanSetGlobalStringValue()
212209
}
213210
finally
214211
{
215-
repo.Config.Set("user.name", existing, ConfigurationLevel.Global);
212+
repo.Config.Set("user.name", existing.Value, ConfigurationLevel.Global);
216213
}
217214
}
218215
}
@@ -224,7 +221,7 @@ public void CanSetGlobalStringValueWithoutRepo()
224221
{
225222
InconclusiveIf(() => !config.HasGlobalConfig, "No Git global configuration available");
226223

227-
var existing = config.Get<string>("user.name", null);
224+
var existing = config.Get<string>("user.name");
228225
Assert.NotNull(existing);
229226

230227
try
@@ -235,7 +232,7 @@ public void CanSetGlobalStringValueWithoutRepo()
235232
}
236233
finally
237234
{
238-
config.Set("user.name", existing, ConfigurationLevel.Global);
235+
config.Set("user.name", existing.Value, ConfigurationLevel.Global);
239236
}
240237
}
241238
}
@@ -295,14 +292,14 @@ public void CanSetAndReadUnicodeStringValue()
295292

296293
AssertValueInLocalConfigFile(path.RepositoryPath, "stringsetting = Juliën$");
297294

298-
string val = repo.Config.Get("unittests.stringsetting", "");
295+
string val = repo.Config.Get<string>("unittests.stringsetting").Value;
299296
Assert.Equal("Juliën", val);
300297
}
301298

302299
// Make sure the change is permanent
303300
using (var repo = new Repository(path.RepositoryPath))
304301
{
305-
string val = repo.Config.Get("unittests.stringsetting", "");
302+
string val = repo.Config.Get<string>("unittests.stringsetting").Value;
306303
Assert.Equal("Juliën", val);
307304
}
308305
}
@@ -312,24 +309,20 @@ public void ReadingUnsupportedTypeThrows()
312309
{
313310
using (var repo = new Repository(StandardTestRepoPath))
314311
{
315-
Assert.Throws<ArgumentException>(() => repo.Config.Get<short>("unittests.setting", 42));
316-
Assert.Throws<ArgumentException>(() => repo.Config.Get<Configuration>("unittests.setting", null));
312+
Assert.Throws<ArgumentException>(() => repo.Config.Get<short>("unittests.setting"));
313+
Assert.Throws<ArgumentException>(() => repo.Config.Get<Configuration>("unittests.setting"));
317314
}
318315
}
319316

320317
[Fact]
321-
public void ReadingValueThatDoesntExistReturnsDefault()
318+
public void ReadingValueThatDoesntExistReturnsNull()
322319
{
323320
using (var repo = new Repository(StandardTestRepoPath))
324321
{
325-
Assert.Null(repo.Config.Get<string>("unittests.ghostsetting", null));
326-
Assert.Equal(0, repo.Config.Get<int>("unittests.ghostsetting", 0));
327-
Assert.Equal(0L, repo.Config.Get<long>("unittests.ghostsetting", 0L));
328-
Assert.False(repo.Config.Get<bool>("unittests.ghostsetting", false));
329-
Assert.Equal("42", repo.Config.Get("unittests.ghostsetting", "42"));
330-
Assert.Equal(42, repo.Config.Get("unittests.ghostsetting", 42));
331-
Assert.Equal(42L, repo.Config.Get("unittests.ghostsetting", 42L));
332-
Assert.True(repo.Config.Get("unittests.ghostsetting", true));
322+
Assert.Null(repo.Config.Get<string>("unittests.ghostsetting"));
323+
Assert.Null(repo.Config.Get<int>("unittests.ghostsetting"));
324+
Assert.Null(repo.Config.Get<long>("unittests.ghostsetting"));
325+
Assert.Null(repo.Config.Get<bool>("unittests.ghostsetting"));
333326
}
334327
}
335328

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ public void CreatingANewRemoteAddsADefaultRefSpec()
165165
Assert.Equal(name, remote.Name);
166166
Assert.Equal(url, remote.Url);
167167

168-
var refSpec = repo.Config.Get<string>("remote", remote.Name, "fetch", null);
168+
var refSpec = repo.Config.Get<string>("remote", remote.Name, "fetch");
169169
Assert.NotNull(refSpec);
170170

171-
Assert.Equal("+refs/heads/*:refs/remotes/upstream/*", refSpec);
171+
Assert.Equal("+refs/heads/*:refs/remotes/upstream/*", refSpec.Value);
172172
}
173173
}
174174

@@ -185,10 +185,10 @@ public void CanAddANewRemoteWithAFetchRefSpec()
185185

186186
repo.Remotes.Add(name, url, fetchRefSpec);
187187

188-
var refSpec = repo.Config.Get<string>("remote", name, "fetch", null);
188+
var refSpec = repo.Config.Get<string>("remote", name, "fetch");
189189
Assert.NotNull(refSpec);
190190

191-
Assert.Equal(fetchRefSpec, refSpec);
191+
Assert.Equal(fetchRefSpec, refSpec.Value);
192192
}
193193
}
194194
}

LibGit2Sharp.Tests/RepositoryOptionsFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ public void CanProvideDifferentConfigurationFilesToARepository()
167167
using (var repo = new Repository(BareTestRepoPath, options))
168168
{
169169
Assert.True(repo.Config.HasGlobalConfig);
170-
Assert.Equal(name, repo.Config.Get<string>("user", "name", null));
171-
Assert.Equal(email, repo.Config.Get<string>("user", "email", null));
170+
Assert.Equal(name, repo.Config.Get<string>("user.name").Value);
171+
Assert.Equal(email, repo.Config.Get<string>("user.email").Value);
172172

173173
repo.Config.Set("help.link", "https://twitter.com/xpaulbettsx/status/205761932626636800", ConfigurationLevel.System);
174174
}

LibGit2Sharp/Branch.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ public virtual Remote Remote
169169
{
170170
get
171171
{
172-
string remoteName = repo.Config.Get<string>("branch", Name, "remote", null);
172+
ConfigurationEntry<string> remoteEntry = repo.Config.Get<string>("branch", Name, "remote");
173+
174+
if (remoteEntry == null)
175+
{
176+
return null;
177+
}
178+
179+
string remoteName = remoteEntry.Value;
173180

174181
if (string.IsNullOrEmpty(remoteName) ||
175182
string.Equals(remoteName, ".", StringComparison.Ordinal))

0 commit comments

Comments
 (0)
0