8000 Merge pull request #1173 from libgit2/ntk/enforce_signature_usage · coding2233/libgit2sharp4unity3d@b279955 · GitHub
[go: up one dir, main page]

Skip to content

Commit b279955

Browse files
committed
Merge pull request libgit2#1173 from libgit2/ntk/enforce_signature_usage
The case for the removal of overloads which take an identity from the configuration
2 parents 7e2c42d + cfbec61 commit b279955

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+209
-196
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -538,32 +538,11 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
538538
}
539539
}
540540

541-
[Theory]
542-
[InlineData(null, "x@example.com")]
543-
[InlineData("", "x@example.com")]
544-
[InlineData("X", null)]
545-
[InlineData("X", "")]
546-
public void CommitWithInvalidSignatureConfigThrows(string name, string email)
547-
{
548-
string repoPath = InitNewRepository();
549-
string configPath = CreateConfigurationWithDummyUser(name, email);
550-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
551-
552-
using (var repo = new Repository(repoPath, options))
553-
{
554-
Assert.Equal(name, repo.Config.GetValueOrDefault<string>("user.name"));
555-
Assert.Equal(email, repo.Config.GetValueOrDefault<string>("user.email"));
556-
557-
Assert.Throws<LibGit2SharpException>(
558-
() => repo.Commit("Initial egotistic commit", new CommitOptions { AllowEmptyCommit = true }));
559-
}
560-
}
561-
562541
[Fact]
563542
public void CanCommitWithSignatureFromConfig()
564543
{
565544
string repoPath = InitNewRepository();
566-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
545+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
567546
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
568547

569548
using (var repo = new Repository(repoPath, options))
@@ -581,12 +560,14 @@ public void CanCommitWithSignatureFromConfig()
581560

582561
Assert.Null(repo.Head[relativeFilepath]);
583562

584-
Commit commit = repo.Commit("Initial egotistic commit");
563+
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);
564+
565+
Commit commit = repo.Commit("Initial egotistic commit", signature, signature);
585566

586567
AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n");
587568
AssertBlobContent(commit[relativeFilepath], "nulltoken\n");
588569

589-
AssertCommitSignaturesAre(commit, Constants.Signature);
570+
AssertCommitIdentitiesAre(commit, Constants.Identity);
590571
}
591572
}
592573

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void CanReadStringValue()
143143
[Fact]
144144
public void CanEnumerateGlobalConfig()
145145
{
146-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
146+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
147147
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
148148

149149
var path = SandboxStandardTestRepoGitDir();
@@ -200,7 +200,7 @@ public void CanFindInLocalConfig()
200200
[Fact]
201201
public void CanFindInGlobalConfig()
202202
{
203-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
203+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
204204
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
205205

206206
var path = SandboxStandardTestRepoGitDir();
@@ -387,7 +387,7 @@ public void CanAccessConfigurationWithoutARepository(Func<string, string> localC
387387
{
388388
var path = SandboxStandardTestRepoGitDir();
389389

390-
string globalConfigPath = CreateConfigurationWithDummyUser(Constants.Signature);
390+
string globalConfigPath = CreateConfigurationWithDummyUser(Constants.Identity);
391391
var options = new RepositoryOptions { GlobalConfigurationLocation = globalConfigPath };
392392

393393
using (var repo = new Repository(path, options))
@@ -409,5 +409,27 @@ public void PassingANonExistingLocalConfigurationFileToBuildFromthrowss()
409409
Assert.Throws<FileNotFoundException>(() => Configuration.BuildFrom(
410410
Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())));
411411
}
412+
413+
[Theory]
414+
[InlineData(null, "x@example.com")]
415+
[InlineData("", "x@example.com")]
416+
[InlineData("X", null)]
417+
[InlineData("X", "")]
418+
public void CannotBuildAProperSignatureFromConfigWhenFullIdentityCannotBeFoundInTheConfig(string name, string email)
419+
{
420+
string repoPath = InitNewRepository();
421+
string configPath = CreateConfigurationWithDummyUser(name, email);
422+
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
423+
424+
using (var repo = new Repository(repoPath, options))
425+
{
426+
Assert.Equal(name, repo.Config.GetValueOrDefault<string>("user.name"));
427+
Assert.Equal(email, repo.Config.GetValueOrDefault<string>("user.email"));
428+
429+
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);
430+
431+
Assert.Null(signature);
432+
}
433+
}
412434
}
413435
}

LibGit2Sharp.Tests/FilterFixture.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void CleanFilterWritesOutputToObjectTree()
159159
using (var repo = CreateTestRepository(repoPath))
160160
{
161161
FileInfo expectedFile = StageNewFile(repo, decodedInput);
162-
var commit = repo.Commit("Clean that file");
162+
var commit = repo.Commit("Clean that file", Constants.Signature, Constants.Signature);
163163
var blob = (Blob)commit.Tree[expectedFile.Name].Target;
164164

165165
var textDetected = blob.GetContentText();
@@ -232,15 +232,15 @@ public void CanFilterLargeFiles()
232232
string attributesPath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, ".gitattributes");
233233
FileInfo attributesFile = new FileInfo(attributesPath);
234234

235-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
235+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
236236
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
237237

238238
using (Repository repo = new Repository(repoPath, repositoryOptions))
239239
{
240240
File.WriteAllText(attributesPath, "*.blob filter=test");
241241
repo.Stage(attributesFile.Name);
242242
repo.Stage(contentFile.Name);
243-
repo.Commit("test");
243+
repo.Commit("test", Constants.Signature, Constants.Signature);
244244
contentFile.Delete();
245245
repo.Checkout("HEAD", new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
246246
}
@@ -346,7 +346,7 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin
346346
{
347347
StageNewFile(repo, content);
348348

349-
repo.Commit("Initial commit");
349+
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
350350

351351
expectedPath = CommitFileOnBranch(repo, branchName, content);
352352

@@ -363,7 +363,7 @@ private static FileInfo CommitFileOnBranch(Repository repo, string branchName, S
363363
repo.Checkout< 10000 /span>(branch.FriendlyName);
364364

365365
FileInfo expectedPath = StageNewFile(repo, content);
366-
repo.Commit("Commit");
366+
repo.Commit("Commit", Constants.Signature, Constants.Signature);
367367
return expectedPath;
368368
}
369369

@@ -377,7 +377,7 @@ private static FileInfo StageNewFile(IRepository repo, string contents = "null")
377377

378378
private Repository CreateTestRepository(string path)
379379
{
380-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
380+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
381381
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
382382
var repository = new Repository(path, repositoryOptions);
383383
CreateAttributesFile(repository, "* filter=test");

LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void SmugdeIsNotCalledForFileWhichDoesNotMatchAnAttributeEntry()
2121

2222
string repoPath = InitNewRepository();
2323
string fileName = Guid.NewGuid() + ".rot13";
24-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
24+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
2525
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
2626
using (var repo = new Repository(repoPath, repositoryOptions))
2727
{
@@ -61,7 +61,7 @@ public void CorrectlyEncodesAndDecodesInput()
6161

6262
string repoPath = InitNewRepository();
6363
string fileName = Guid.NewGuid() + ".rot13";
64-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
64+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
6565
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
6666
using (var repo = new Repository(repoPath, repositoryOptions))
6767
{
@@ -106,7 +106,7 @@ public void WhenStagedFileDoesNotMatchPathSpecFileIsNotFiltered(string pathSpec,
106106
string repoPath = InitNewRepository();
107107
string fileName = Guid.NewGuid() + fileExtension;
108108

109-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
109+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
110110
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
111111
using (var repo = new Repository(repoPath, repositoryOptions))
112112
{
@@ -141,7 +141,7 @@ public void CleanIsCalledIfAttributeEntryMatches(string filterAttribute, string
141141
string repoPath = InitNewRepository();
142142
string fileName = Guid.NewGuid() + ".txt";
143143

144-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
144+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
145145
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
146146
using (var repo = new Repository(repoPath, repositoryOptions))
147147
{
@@ -172,7 +172,7 @@ public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string
172172
string repoPath = InitNewRepository();
173173
string fileName = Guid.NewGuid() + ".txt";
174174

175-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
175+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
176176
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
177177
using (var repo = new Repository(repoPath, repositoryOptions))
178178
{
@@ -203,15 +203,15 @@ private static void DeleteFile(Repository repo, string fileName)
203203
{
204204
File.Delete(Path.Combine(repo.Info.WorkingDirectory, fileName));
205205
repo.Stage(fileName);
206-
repo.Commit("remove file");
206+
repo.Commit("remove file", Constants.Signature, Constants.Signature);
207207
}
208208

209209
private static Blob CommitOnBranchAndReturnDatabaseBlob(Repository repo, string fileName, string input)
210210
{
211211
Touch(repo.Info.WorkingDirectory, fileName, input);
212212
repo.Stage(fileName);
213213

214-
var commit = repo.Commit("new file");
214+
var commit = repo.Commit("new file", Constants.Signature, Constants.Signature);
215215

216216
var blob = (Blob)commit.Tree[fileName].Target;
217217
return blob;

LibGit2Sharp.Tests/NoteFixture.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,25 @@ public void CreatingANoteWhichAlreadyExistsOverwritesThePreviousNote()
168168
[Fact]
169169
public void CanAddANoteWithSignatureFromConfig()
170170
{
171-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
171+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
172172
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
173173
string path = SandboxBareTestRepo();
174174

175175
using (var repo = new Repository(path, options))
176176
{
177177
var commit = repo.Lookup<Commit>("9fd738e8f7967c078dceed8190330fc8648ee56a");
178-
var note = repo.Notes.Add(commit.Id, "I'm batman!\n", "batmobile");
178+
179+
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);
180+
181+
var note = repo.Notes.Add(commit.Id, "I'm batman!\n", signature, signature, "batmobile");
179182

180183
var newNote = commit.Notes.Single();
181184
Assert.Equal(note, newNote);
182185

183186
Assert.Equal("I'm batman!\n", newNote.Message);
184187
Assert.Equal("batmobile", newNote.Namespace);
185188

186-
AssertCommitSignaturesAre(repo.Lookup<Commit>("refs/notes/batmobile"), Constants.Signature);
189+
AssertCommitIdentitiesAre(repo.Lookup<Commit>("refs/notes/batmobile"), Constants.Identity);
187190
}
188191
}
189192

@@ -265,7 +268,7 @@ public void RemovingANonExistingNoteDoesntThrow()
265268
[Fact]
266269
public void CanRemoveANoteWithSignatureFromConfig()
267270
{
268-
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
271+
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
269272
RepositoryOptions options = new RepositoryOptions() { GlobalConfigurationLocation = configPath };
270273
string path = SandboxBareTestRepo();
271274

@@ -276,11 +279,13 @@ public void CanRemoveANoteWithSignatureFromConfig()
276279

277280
Assert.NotEmpty(notes);
278281

279-
repo.Notes.Remove(commit.Id, repo.Notes.DefaultNamespace);
282+
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);
283+
284+
repo.Notes.Remove(commit.Id, signature, signature, repo.Notes.DefaultNamespace);
280285

281286
Assert.Empty(notes);
282287

283-
AssertCommitSignaturesAre(repo.Lookup<Commit>("refs/notes/" + repo.Notes.DefaultNamespace), Constants.Signature);
288+
AssertCommitIdentitiesAre(repo.Lookup<Commit>("refs/notes/" + repo.Notes.DefaultNamespace), Constants.Identity);
284289
}
285290
}
286291

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ private static RepositoryOptions BuildFakeRepositoryOptions(SelfCleaningDirector
328328
/// Creates a configuration file with user.name and user.email set to signature
329329
/// </summary>
330330
/// <remarks>The configuration file will be removed automatically when the tests are finished</remarks>
331-
/// <param name="signature">The signature to use for user.name and user.email</param>
331+
/// <param name="identity">The identity to use for user.name and user.email</param>
332332
/// <returns>The path to the configuration file</returns>
333-
protected string CreateConfigurationWithDummyUser(Signature signature)
333+
protected string CreateConfigurationWithDummyUser(Identity identity)
334334
{
335-
return CreateConfigurationWithDummyUser(signature.Name, signature.Email);
335+
return CreateConfigurationWithDummyUser(identity.Name, identity.Email);
336336
}
337337

338338
protected string CreateConfigurationWithDummyUser(string name, string email)
@@ -361,13 +361,13 @@ protected string CreateConfigurationWithDummyUser(string name, string email)
361361
/// Asserts that the commit has been authored and committed by the specified signature
362362
/// </summary>
363363
/// <param name="commit">The commit</param>
364-
/// <param name="signature">The signature to compare author and commiter to</param>
365-
protected void AssertCommitSignaturesAre(Commit commit, Signature signature)
364+
/// <param name="identity">The identity to compare author and commiter to F41A </param>
365+
protected void AssertCommitIdentitiesAre(Commit commit, Identity identity)
366366
{
367-
Assert.Equal(signature.Name, commit.Author.Name);
368-
Assert.Equal(signature.Email, commit.Author.Email);
369-
Assert.Equal(signature.Name, commit.Committer.Name);
370-
Assert.Equal(signature.Email, commit.Committer.Email);
367+
Assert.Equal(identity.Name, commit.Author.Name);
368+
Assert.Equal(identity.Email, commit.Author.Email);
369+
Assert.Equal(identity.Name, commit.Committer.Name);
370+
Assert.Equal(identity.Email, commit.Committer.Email);
371371
}
372372

373373
protected static string Touch(string parent, string file, string content = null, Encoding encoding = null)

LibGit2Sharp/CheckoutOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
3434
{
3535
get
3636
{
37-
return CheckoutModifiers.HasFlag(CheckoutModifiers.Force)
38-
? CheckoutStrategy.GIT_CHECKOUT_FORCE
37+
return CheckoutModifiers.HasFlag(CheckoutModifiers.Force)
38+
? CheckoutStrategy.GIT_CHECKOUT_FORCE
3939
: CheckoutStrategy.GIT_CHECKOUT_SAFE;
4040
}
4141
}

LibGit2Sharp/Commit.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ private string DebuggerDisplay
118118
get
119119
{
120120
return string.Format(CultureInfo.InvariantCulture,
121-
"{0} {1}",
122-
Id.ToString(7),
121+
"{0} {1}",
122+
Id.ToString(7),
123123
MessageShort);
124124
}
125125
}

LibGit2Sharp/ConflictCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private List<Conflict> AllConflicts()
104104
default:
105105
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
106106
"Entry '{0}' bears an unexpected StageLevel '{1}'",
107-
entry.Path,
107+
entry.Path,
108108
entry.StageLevel));
109109
}
110110
}

LibGit2Sharp/ContentChanges.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private string DebuggerDisplay
124124
{
125125
return string.Format(CultureInfo.InvariantCulture,
126126
@"{{+{0}, -{1}}}",
127-
LinesAdded,
127+
LinesAdded,
128128
LinesDeleted);
129129
}
130130
}

LibGit2Sharp/Core/EncodingMarshaler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public virtual IntPtr MarshalManagedToNative(Object managedObj)
4343

4444
if (str == null)
4545
{
46-
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
47-
"{0} must be used on a string.",
46+
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
47+
"{0} must be used on a string.",
4848
GetType().Name));
4949
}
5050

LibGit2Sharp/Core/FilePath.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ private static string Replace(string path, char oldChar, char newChar)
6060

6161
public bool Equals(FilePath other)
6262
{
63-
return other == null
64-
? posix == null
63+
return other == null
64+
? posix == null
6565
: string.Equals(posix, other.posix, StringComparison.Ordinal);
6666
}
6767

LibGit2Sharp/Core/FilePathMarshaler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public override IntPtr MarshalManagedToNative(Object managedObj)
6868

6969
if (null == filePath)
7070
{
71-
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
72-
"{0} must be used on a FilePath.",
71+
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
72+
"{0} must be used on a FilePath.",
7373
GetType().Name));
7474
}
7575

0 commit comments

Comments
 (0)
0