Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Melcher <info@yogularm.de>2013-11-11 22:52:56 +0400
committerJan Melcher <info@yogularm.de>2013-11-11 22:54:18 +0400
commit91d52df424bb140a736b2ad98c15f3115ca8009d (patch)
tree7fdbb71bba746a85e4e3ddf1d4c6f06a1b274541 /LibGit2Sharp.Tests
parent1679067e35348335130e6c7a206f497e1c378d73 (diff)
Extension methods for NoteCollection using user from config
Similar to Repository.Commit, NoteCollectionExtensions.Add/Remove take the committer and author signature from the global git config user.name / user.email. This allows modifying notes without specifying the commiter explicitly
Diffstat (limited to 'LibGit2Sharp.Tests')
-rw-r--r--LibGit2Sharp.Tests/NoteFixture.cs60
-rw-r--r--LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs21
2 files changed, 81 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/NoteFixture.cs b/LibGit2Sharp.Tests/NoteFixture.cs
index e24eb00a..0f608615 100644
--- a/LibGit2Sharp.Tests/NoteFixture.cs
+++ b/LibGit2Sharp.Tests/NoteFixture.cs
@@ -151,6 +151,28 @@ namespace LibGit2Sharp.Tests
}
[Fact]
+ public void CanAddANoteWithSignatureFromConfig()
+ {
+ string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
+ RepositoryOptions options = new RepositoryOptions() { GlobalConfigurationLocation = configPath };
+ string path = CloneBareTestRepo();
+
+ 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");
+
+ var newNote = commit.Notes.Single();
+ Assert.Equal(note, newNote);
+
+ Assert.Equal("I'm batman!\n", newNote.Message);
+ Assert.Equal("batmobile", newNote.Namespace);
+
+ AssertCommitSignaturesAre(repo, "refs/notes/batmobile", Constants.Signature);
+ }
+ }
+
+ [Fact]
public void CanCompareTwoUniqueNotes()
{
string path = CloneBareTestRepo();
@@ -226,6 +248,28 @@ namespace LibGit2Sharp.Tests
}
[Fact]
+ public void CanRemoveANoteWithSignatureFromConfig()
+ {
+ string configPath = CreateConfigurationWithDummyUser(Constants.Signature);
+ RepositoryOptions options = new RepositoryOptions() { GlobalConfigurationLocation = configPath };
+ string path = CloneBareTestRepo();
+
+ using (var repo = new Repository(path, options))
+ {
+ var commit = repo.Lookup<Commit>("8496071c1b46c854b31185ea97743be6a8774479");
+ var notes = repo.Notes[commit.Id];
+
+ Assert.NotEmpty(notes);
+
+ repo.Notes.Remove(commit.Id, repo.Notes.DefaultNamespace);
+
+ Assert.Empty(notes);
+
+ AssertCommitSignaturesAre(repo, "refs/notes/" + repo.Notes.DefaultNamespace, Constants.Signature);
+ }
+ }
+
+ [Fact]
public void CanRetrieveTheListOfNotesForAGivenNamespace()
{
var expectedNotes = new[]
@@ -245,6 +289,22 @@ namespace LibGit2Sharp.Tests
}
}
+ /// <summary>
+ /// Verifies that the commit has been authored and committed by the specified signature
+ /// </summary>
+ /// <param name="repo">The repository</param>
+ /// <param name="commitish">The commit whose author and commiter properties to verify</param>
+ /// <param name="signature">The signature to compare author and commiter to</param>
+ private void AssertCommitSignaturesAre(Repository repo, string commitish, Signature signature)
+ {
+ Commit commit = repo.Lookup<Commit>(commitish);
+ Assert.NotNull(commit);
+ 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);
+ }
+
private static T[] SortedNotes<T>(IEnumerable<Note> notes, Func<Note, T> selector)
{
return notes.OrderBy(n => n.Message, StringComparer.Ordinal).Select(selector).ToArray();
diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
index ae92297c..e4903478 100644
--- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
+++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
@@ -265,6 +265,27 @@ namespace LibGit2Sharp.Tests.TestHelpers
};
}
+ /// <summary>
+ /// 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>
+ /// <returns>The path to the configuration file</returns>
+ protected string CreateConfigurationWithDummyUser(Signature signature)
+ {
+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
+ Directory.CreateDirectory(scd.DirectoryPath);
+ string configFilePath = Path.Combine(scd.DirectoryPath, "global-config");
+
+ using (Configuration config = new Configuration(configFilePath))
+ {
+ config.Set("user.name", signature.Name, ConfigurationLevel.Global);
+ config.Set("user.email", signature.Email, ConfigurationLevel.Global);
+ }
+
+ return configFilePath;
+ }
+
protected static string Touch(string parent, string file, string content = null, Encoding encoding = null)
{
string filePath = Path.Combine(parent, file);