8000 The case for the removal of overloads which take an identity from the configuration by nulltoken · Pull Request #1173 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

The case for the removal of overloads which take an identity from the configuration #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,32 +538,11 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
}
}

[Theory]
[InlineData(null, "x@example.com")]
[InlineData("", "x@example.com")]
[InlineData("X", null)]
[InlineData("X", "")]
public void CommitWithInvalidSignatureConfigThrows(string name, string email)
{
string repoPath = InitNewRepository();
string configPath = CreateConfigurationWithDummyUser(name, email);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

using (var repo = new Repository(repoPath, options))
{
Assert.Equal(name, repo.Config.GetValueOrDefault<string>("user.name"));
Assert.Equal(email, repo.Config.GetValueOrDefault<string>("user.email"));

Assert.Throws<LibGit2SharpException>(
() => repo.Commit("Initial egotistic commit", new CommitOptions { AllowEmptyCommit = true }));
}
}

[Fact]
public void CanCommitWithSignatureFromConfig()
{
string repoPath = InitNewRepository();
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

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

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

Commit commit = repo.Commit("Initial egotistic commit");
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);

Commit commit = repo.Commit("Initial egotistic commit", signature, signature);

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

AssertCommitSignaturesAre(commit, Constants.Signature);
AssertCommitIdentitiesAre(commit, Constants.Identity);
}
}

Expand Down
28 changes: 25 additions & 3 deletions LibGit2Sharp.Tests/ConfigurationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void CanReadStringValue()
[Fact]
public void CanEnumerateGlobalConfig()
{
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

var path = SandboxStandardTestRepoGitDir();
Expand Down Expand Up @@ -200,7 +200,7 @@ public void CanFindInLocalConfig()
[Fact]
public void CanFindInGlobalConfig()
{
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

var path = SandboxStandardTestRepoGitDir();
Expand Down Expand Up @@ -387,7 +387,7 @@ public void CanAccessConfigurationWithoutARepository(Func<string, string> localC
{
var path = SandboxStandardTestRepoGitDir();

string globalConfigPath = CreateConfigurationWithDummyUser(Constants.Signature);
string globalConfigPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = globalConfigPath };

using (var repo = new Repository(path, options))
Expand All @@ -409,5 +409,27 @@ public void PassingANonExistingLocalConfigurationFileToBuildFromthrowss()
Assert.Throws<FileNotFoundException>(() => Configuration.BuildFrom(
Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())));
}

[Theory]
[InlineData(null, "x@example.com")]
[InlineData("", "x@example.com")]
[InlineData("X", null)]
[InlineData("X", "")]
public void CannotBuildAProperSignatureFromConfigWhenFullIdentityCannotBeFoundInTheConfig(string name, string email)
{
string repoPath = InitNewRepository();
string configPath = CreateConfigurationWithDummyUser(name, email);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

using (var repo = new Repository(repoPath, options))
{
Assert.Equal(name, repo.Config.GetValueOrDefault<string>("user.name"));
Assert.Equal(email, repo.Config.GetValueOrDefault<string>("user.email"));

Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);

Assert.Null(signature);
}
}
}
}
12 changes: 6 additions & 6 deletions LibGit2Sharp.Tests/FilterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void CleanFilterWritesOutputToObjectTree()
using (var repo = CreateTestRepository(repoPath))
{
FileInfo expectedFile = StageNewFile(repo, decodedInput);
var commit = repo.Commit("Clean that file");
var commit = repo.Commit("Clean that file", Constants.Signature, Constants.Signature);
var blob = (Blob)commit.Tree[expectedFile.Name].Target;

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

string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };

using (Repository repo = new Repository(repoPath, repositoryOptions))
{
File.WriteAllText(attributesPath, "*.blob filter=test");
repo.Stage(attributesFile.Name);
repo.Stage(contentFile.Name);
repo.Commit("test");
repo.Commit("test", Constants.Signature, Constants.Signature);
contentFile.Delete();
repo.Checkout("HEAD", new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
}
Expand Down Expand Up @@ -346,7 +346,7 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin
{
StageNewFile(repo, content);

repo.Commit("Initial commit");
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);

expectedPath = CommitFileOnBranch(repo, branchName, content);

Expand All @@ -363,7 +363,7 @@ private static FileInfo CommitFileOnBranch(Repository repo, string branchName, S
repo.Checkout(branch.FriendlyName);

FileInfo expectedPath = StageNewFile(repo, content);
repo.Commit("Commit");
repo.Commit("Commit", Constants.Signature, Constants.Signature);
return expectedPath;
}

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

private Repository CreateTestRepository(string path)
{
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
var repository = new Repository(path, repositoryOptions);
CreateAttributesFile(repository, "* filter=test");
Expand Down
14 changes: 7 additions & 7 deletions LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void SmugdeIsNotCalledForFileWhichDoesNotMatchAnAttributeEntry()

string repoPath = InitNewRepository();
string fileName = Guid.NewGuid() + ".rot13";
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
{
Expand Down Expand Up @@ -61,7 +61,7 @@ public void CorrectlyEncodesAndDecodesInput()

string repoPath = InitNewRepository();
string fileName = Guid.NewGuid() + ".rot13";
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public void WhenStagedFileDoesNotMatchPathSpecFileIsNotFiltered(string pathSpec,
string repoPath = InitNewRepository();
string fileName = Guid.NewGuid() + fileExtension;

string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
{
Expand Down Expand Up @@ -141,7 +141,7 @@ public void CleanIsCalledIfAttributeEntryMatches(string filterAttribute, string
string repoPath = InitNewRepository();
string fileName = Guid.NewGuid() + ".txt";

string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
{
Expand Down Expand Up @@ -172,7 +172,7 @@ public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string
string repoPath = InitNewRepository();
string fileName = Guid.NewGuid() + ".txt";

string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
{
Expand Down Expand Up @@ -203,15 +203,15 @@ private static void DeleteFile(Repository repo, string fileName)
{
File.Delete(Path.Combine(repo.Info.WorkingDirectory, fileName));
repo.Stage(fileName);
repo.Commit("remove file");
repo.Commit("remove file", Constants.Signature, Constants.Signature);
}

private static Blob CommitOnBranchAndReturnDatabaseBlob(Repository repo, string fileName, string input)
{
Touch(repo.Info.WorkingDirectory, fileName, input);
repo.Stage(fileName);

var commit = repo.Commit("new file");
var commit = repo.Commit("new file", Constants.Signature, Constants.Signature);

var blob = (Blob)commit.Tree[fileName].Target;
return blob;
Expand Down
17 changes: 11 additions & 6 deletions LibGit2Sharp.Tests/NoteFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,25 @@ public void CreatingANoteWhichAlreadyExistsOverwritesThePreviousNote()
[Fact]
public void CanAddANoteWithSignatureFromConfig()
{
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
string path = SandboxBareTestRepo();

using (var repo = new Repository(path, options))
{
var commit = repo.Lookup<Commit>("9fd738e8f7967c078dceed8190330fc8648ee56a");
var note = repo.Notes.Add(commit.Id, "I'm batman!\n", "batmobile");

Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);

var note = repo.Notes.Add(commit.Id, "I'm batman!\n", signature, signature, "batmobile");

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

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

AssertCommitSignaturesAre(repo.Lookup<Commit>("refs/notes/batmobile"), Constants.Signature);
AssertCommitIdentitiesAre(repo.Lookup<Commit>("refs/notes/batmobile"), Constants.Identity);
}
}

Expand Down Expand Up @@ -265,7 +268,7 @@ public void RemovingANonExistingNoteDoesntThrow()
[Fact]
public void CanRemoveANoteWithSignatureFromConfig()
{
string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
RepositoryOptions options = new RepositoryOptions() { GlobalConfigurationLocation = configPath };
string path = SandboxBareTestRepo();

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

Assert.NotEmpty(notes);

repo.Notes.Remove(commit.Id, repo.Notes.DefaultNamespace);
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);

repo.Notes.Remove(commit.Id, signature, signature, repo.Notes.DefaultNamespace);

Assert.Empty(notes);

AssertCommitSignaturesAre(repo.Lookup<Commit>("refs/notes/" + repo.Notes.DefaultNamespace), Constants.Signature);
AssertCommitIdentitiesAre(repo.Lookup<Commit>("refs/notes/" + repo.Notes.DefaultNamespace), Constants.Identity);
}
}

Expand Down
18 changes: 9 additions & 9 deletions LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ private static RepositoryOptions BuildFakeRepositoryOptions(SelfCleaningDirector
/// Creates a configuration file with user.name and user.email set to signature
/// </summary>
/// <remarks>The configuration file will be removed automatically when the tests are finished</remarks>
/// <param name="signature">The signature to use for user.name and user.email</param>
/// <param name="identity">The identity to use for user.name and user.email</param>
/// <returns>The path to the configuration file</returns>
protected string CreateConfigurationWithDummyUser(Signature signature)
protected string CreateConfigurationWithDummyUser(Identity identity)
{
return CreateConfigurationWithDummyUser(signature.Name, signature.Email);
return CreateConfigurationWithDummyUser(identity.Name, identity.Email);
}

protected string CreateConfigurationWithDummyUser(string name, string email)
Expand Down Expand Up @@ -361,13 +361,13 @@ protected string CreateConfigurationWithDummyUser(string name, string email)
/// Asserts that the commit has been authored and committed by the specified signature
/// </summary>
/// <param name="commit">The commit</param>
/// <param name="signature">The signature to compare author and commiter to</param>
protected void AssertCommitSignaturesAre(Commit commit, Signature signature)
/// <param name="identity">The identity to compare author and commiter to</param>
protected void AssertCommitIdentitiesAre(Commit commit, Identity identity)
{
Assert.Equal(signature.Name, commit.Author.Name);
Assert.Equal(signature.Email, commit.Author.Email);
Assert.Equal(signature.Name, commit.Committer.Name);
Assert.Equal(signature.Email, commit.Committer.Email);
Assert.Equal(identity.Name, commit.Author.Name);
Assert.Equal(identity.Email, commit.Author.Email);
Assert.Equal(identity.Name, commit.Committer.Name);
Assert.Equal(identity.Email, commit.Committer.Email);
}

protected static string Touch(string parent, string file, string content = null, Encoding encoding = null)
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/CheckoutOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ CheckoutStrategy IConvertableToGitCheckoutOpts.CheckoutStrategy
{
get
{
return CheckoutModifiers.HasFlag(CheckoutModifiers.Force)
? CheckoutStrategy.GIT_CHECKOUT_FORCE
return CheckoutModifiers.HasFlag(CheckoutModifiers.Force)
? CheckoutStrategy.GIT_CHECKOUT_FORCE
: CheckoutStrategy.GIT_CHECKOUT_SAFE;
}
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ private string DebuggerDisplay
get
{
return string.Format(CultureInfo.InvariantCulture,
"{0} {1}",
Id.ToString(7),
"{0} {1}",
Id.ToString(7),
MessageShort);
}
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/ConflictCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private List<Conflict> AllConflicts()
default:
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
"Entry '{0}' bears an unexpected StageLevel '{1}'",
entry.Path,
entry.Path,
entry.StageLevel));
}
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/ContentChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private string DebuggerDisplay
{
return string.Format(CultureInfo.InvariantCulture,
@"{{+{0}, -{1}}}",
LinesAdded,
LinesAdded,
LinesDeleted);
}
}
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Core/EncodingMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public virtual IntPtr MarshalManagedToNative(Object managedObj)

if (str == null)
{
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
"{0} must be used on a string.",
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
"{0} must be used on a string.",
GetType().Name));
}

Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Core/FilePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private static string Replace(string path, char oldChar, char newChar)

public bool Equals(FilePath other)
{
return other == null
? posix == null
return other == null
? posix == null
: string.Equals(posix, other.posix, StringComparison.Ordinal);
}

Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/Core/FilePathMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public override IntPtr MarshalManagedToNative(Object managedObj)

if (null == filePath)
{
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
"{0} must be used on a FilePath.",
throw new MarshalDirectiveException(string.Format(CultureInfo.InvariantCulture,
"{0} must be used on a FilePath.",
GetType().Name));
}

Expand Down
Loading
0