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

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorMike Krüger <mikkrg@microsoft.com>2019-09-17 12:56:27 +0300
committerMike Krüger <mikkrg@microsoft.com>2019-09-20 11:56:37 +0300
commitb3e3553ba4a2cbcacbef7ce3b1e92ff4c7a92154 (patch)
treefaba0f9f33bd4393c0470688e67326d5365a85e5 /main/src
parent151e3b54d572ce74dbaf316d5004a73d73b4170b (diff)
[VersionControl] Added tagging support.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitBranchTests.cs92
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/TestUtil.cs3
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/BranchUtil.cs46
3 files changed, 136 insertions, 5 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitBranchTests.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitBranchTests.cs
index 57c781b5ce..a588ed44a3 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitBranchTests.cs
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitBranchTests.cs
@@ -29,6 +29,8 @@ using NUnit.Framework;
using System.Threading.Tasks;
using NUnit.Framework.Internal;
using System.IO;
+using System.Diagnostics;
+using System.Linq;
namespace MonoDevelop.VersionControl.Git.ClientLibrary.Tests
{
@@ -52,12 +54,100 @@ namespace MonoDevelop.VersionControl.Git.ClientLibrary.Tests
public class GitBranchTests : GitTestBase
{
[Test]
- public Task GetCurrentBranch()
+ public Task GetCurrentBranchTest ()
{
return RunTest (async root => {
var currentBranch = await BranchUtil.GetCurrentBranchAsync (root);
Assert.AreEqual ("master", currentBranch.Name);
});
}
+
+ [Test]
+ public Task CreateTagTest ()
+ {
+ return RunTest (async root => {
+ Setup (root);
+ var result = await BranchUtil.CreateNewTagAsync (root, "newTag");
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+ });
+ }
+
+ [Test]
+ public Task CreateExistingTagTest ()
+ {
+ return RunTest (async root => {
+ Setup (root);
+ var result = await BranchUtil.CreateNewTagAsync (root, "newTag");
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+
+ result = await BranchUtil.CreateNewTagAsync (root, "newTag");
+ Assert.IsFalse (result.Success, "has to fail.");
+ });
+ }
+
+ [Test]
+ public Task DeleteTagTest ()
+ {
+ return RunTest (async root => {
+ Setup (root);
+ var result = await BranchUtil.CreateNewTagAsync (root, "newTag");
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+
+ result = await BranchUtil.DeleteTagAsync (root, "newTag");
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+ });
+ }
+
+ [Test]
+ public Task DeleteNonExistingTagTest ()
+ {
+ return RunTest (async root => {
+ Setup (root);
+ var result = await BranchUtil.DeleteTagAsync (root, "notExist");
+ Assert.IsFalse (result.Success, result.ErrorMessage);
+ });
+ }
+
+ [Test]
+ public Task ListAllTagsTest ()
+ {
+ return RunTest (async root => {
+ Setup (root);
+ var result = await BranchUtil.CreateNewTagAsync (root, "newTag");
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+ result = await BranchUtil.CreateNewTagAsync (root, "newTag2");
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+ result = await BranchUtil.CreateNewTagAsync (root, "otherTag");
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+
+ var allTags = await BranchUtil.GetAllTagsAsync (root);
+ Assert.IsTrue (allTags.Count == 3);
+
+ Assert.IsTrue (allTags.Single (t => t.Name == "newTag") != null);
+ Assert.IsTrue (allTags.Single (t => t.Name == "newTag2") != null);
+ Assert.IsTrue (allTags.Single (t => t.Name == "otherTag") != null);
+ });
+ }
+
+ void Setup (string root)
+ {
+ var path = Path.Combine (root, "foo.txt");
+ File.WriteAllText (path, "Test content.");
+ var si = new ProcessStartInfo ("git") {
+ WorkingDirectory = root,
+ Arguments = "add foo.txt"
+ };
+ var p = Process.Start (si);
+ p.WaitForExit ();
+ Assert.AreEqual (0, p.ExitCode);
+
+ si = new ProcessStartInfo ("git") {
+ WorkingDirectory = root,
+ Arguments = "commit -a -m 'first commit.'"
+ };
+ p = Process.Start (si);
+ p.WaitForExit ();
+ Assert.AreEqual (0, p.ExitCode);
+ }
}
}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/TestUtil.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/TestUtil.cs
index 27d436b4f4..86d6ab91fd 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/TestUtil.cs
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/TestUtil.cs
@@ -31,10 +31,9 @@ namespace MonoDevelop.VersionControl.Git.ClientLibrary.Tests
{
static class TestUtil
{
-
public static string CreateTempDirectory ()
{
- Random rnd = new Random ();
+ var rnd = new Random ();
string result;
while (true) {
result = Path.Combine (Path.GetTempPath (), "gitLibTest_" + rnd.Next ());
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/BranchUtil.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/BranchUtil.cs
index 72ab31c7fa..0657cd17fd 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/BranchUtil.cs
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/BranchUtil.cs
@@ -30,6 +30,7 @@ using System.Text;
using System.Threading;
using System.Text.RegularExpressions;
using System.IO;
+using System.Collections.Generic;
namespace MonoDevelop.VersionControl.Git.ClientLibrary
{
@@ -42,10 +43,51 @@ namespace MonoDevelop.VersionControl.Git.ClientLibrary
arguments.AddArgument ("symbolic-ref");
arguments.AddArgument ("--short");
arguments.AddArgument ("HEAD");
- Console.WriteLine (arguments.Arguments);
await new GitProcess ().StartAsync (arguments, handler, false, cancellationToken);
- Console.WriteLine (handler.Output);
return new GitLocalBranch (handler.Output.TrimEnd ());
}
+
+ #region Tags
+ public static async Task<GitResult> CreateNewTagAsync (string rootPath, string tagName, CancellationToken cancellationToken = default)
+ {
+ var handler = new GitOutputTrackerCallbackHandler ();
+ var arguments = new GitArguments (rootPath);
+ arguments.AddArgument ("tag");
+ arguments.AddArgument (tagName);
+ return await new GitProcess ().StartAsync (arguments, handler, false, cancellationToken);
+ }
+
+ public static async Task<GitResult> DeleteTagAsync (string rootPath, string tagName, CancellationToken cancellationToken = default)
+ {
+ var handler = new GitOutputTrackerCallbackHandler ();
+ var arguments = new GitArguments (rootPath);
+ arguments.AddArgument ("tag");
+ arguments.AddArgument ("-d");
+ arguments.AddArgument (tagName);
+ return await new GitProcess ().StartAsync (arguments, handler, false, cancellationToken);
+ }
+
+ class GitTagOutputHandler : GitOutputTrackerCallbackHandler
+ {
+ public List<GitTag> tags = new List<GitTag> ();
+
+ public override void OnOutput (string line)
+ {
+ tags.Add (new GitTag (line));
+ }
+ }
+
+ public static async Task<List<GitTag>> GetAllTagsAsync (string rootPath, CancellationToken cancellationToken = default)
+ {
+ var handler = new GitTagOutputHandler ();
+ var arguments = new GitArguments (rootPath);
+ arguments.AddArgument ("tag");
+ arguments.AddArgument ("-l");
+ var result = await new GitProcess ().StartAsync (arguments, handler, false, cancellationToken);
+ if (!result.Success)
+ throw new InvalidOperationException (result.ErrorMessage);
+ return handler.tags;
+ }
+ #endregion
}
}