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:20:01 +0300
committerMike Krüger <mikkrg@microsoft.com>2019-09-20 11:56:37 +0300
commit151e3b54d572ce74dbaf316d5004a73d73b4170b (patch)
treefc3a4a7cdc2a3c9ff23dc4ae756379ecacc332c7 /main/src
parentffc791b0cd0323073c83ff650d7a75492405f514 (diff)
[VersionControl] Implemented git init & get current branch.
Started to implement git references/branches/tags. This is needed for more complex git operations.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests.csproj3
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitBranchTests.cs63
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitInitTests.cs53
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/TestUtil.cs48
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary.csproj8
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/BranchUtil.cs51
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitBranch.cs42
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitLocalBranch.cs37
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitReference.cs57
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitTag.cs39
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/GitProcess.cs110
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Init/GitInit.cs55
12 files changed, 512 insertions, 54 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests.csproj b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests.csproj
index b949740733..99d076ab60 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests.csproj
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests.csproj
@@ -43,6 +43,9 @@
<Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary.Tests\GitVersionTests.cs" />
<Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary.Tests\Git_v1_StatusTests.cs" />
<Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary.Tests\Git_v2_StatusTests.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary.Tests\GitBranchTests.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary.Tests\GitInitTests.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary.Tests\TestUtil.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
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
new file mode 100644
index 0000000000..57c781b5ce
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitBranchTests.cs
@@ -0,0 +1,63 @@
+//
+// GitBranchTests.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using NUnit.Framework;
+using System.Threading.Tasks;
+using NUnit.Framework.Internal;
+using System.IO;
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary.Tests
+{
+ public class GitTestBase
+ {
+ protected static async Task RunTest (Func<string, Task> action)
+ {
+ var path = TestUtil.CreateTempDirectory ();
+ try {
+ var result = await GitInit.InitAsync (path);
+ Assert.IsTrue (result.Success, "git init failed:" + result.ErrorMessage);
+ await action (path);
+ } finally {
+ if (Directory.Exists (path))
+ Directory.Delete (path, true);
+ }
+ }
+ }
+
+ [TestFixture]
+ public class GitBranchTests : GitTestBase
+ {
+ [Test]
+ public Task GetCurrentBranch()
+ {
+ return RunTest (async root => {
+ var currentBranch = await BranchUtil.GetCurrentBranchAsync (root);
+ Assert.AreEqual ("master", currentBranch.Name);
+ });
+ }
+ }
+}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitInitTests.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitInitTests.cs
new file mode 100644
index 0000000000..841d96e422
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/GitInitTests.cs
@@ -0,0 +1,53 @@
+//
+// GitInitTests.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using NUnit.Framework;
+using System.Threading.Tasks;
+using NUnit.Framework.Internal;
+using System.IO;
+using System;
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary.Tests
+{
+ [TestFixture]
+ public class GitInitTests
+ {
+ [Test]
+ public async Task TestGitInit ()
+ {
+ var path = TestUtil.CreateTempDirectory ();
+ try {
+ var result = await GitInit.InitAsync (path);
+ Assert.IsTrue (result.Success, result.ErrorMessage);
+ Assert.IsTrue (Directory.Exists (path));
+ Assert.IsTrue (Directory.Exists (Path.Combine (path, ".git")));
+ } finally {
+ if (Directory.Exists (path))
+ Directory.Delete (path, true);
+ }
+ }
+ }
+}
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
new file mode 100644
index 0000000000..27d436b4f4
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/MonoDevelop.VersionControl.Git.ClientLibrary.Tests/TestUtil.cs
@@ -0,0 +1,48 @@
+//
+// GitInitTests.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.IO;
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary.Tests
+{
+ static class TestUtil
+ {
+
+ public static string CreateTempDirectory ()
+ {
+ Random rnd = new Random ();
+ string result;
+ while (true) {
+ result = Path.Combine (Path.GetTempPath (), "gitLibTest_" + rnd.Next ());
+ if (!Directory.Exists (result))
+ break;
+ }
+ Directory.CreateDirectory (result);
+ return result;
+ }
+ }
+}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary.csproj b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary.csproj
index 25de0877ad..8ed885882a 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary.csproj
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary.csproj
@@ -55,12 +55,20 @@
<Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Status\GitStatusCode.cs" />
<Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Status\GitSubmoduleState.cs" />
<Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Status\GitRenameOrCopyScore.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Branches\GitBranch.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Branches\GitLocalBranch.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Branches\GitReference.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Branches\BranchUtil.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Branches\GitTag.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Git.ClientLibrary\Init\GitInit.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="MonoDevelop.VersionControl.Git.ClientLibrary\" />
<Folder Include="MonoDevelop.VersionControl.Git.ClientLibrary\Clone\" />
<Folder Include="MonoDevelop.VersionControl.Git.ClientLibrary\Version\" />
<Folder Include="MonoDevelop.VersionControl.Git.ClientLibrary\Status\" />
+ <Folder Include="MonoDevelop.VersionControl.Git.ClientLibrary\Branches\" />
+ <Folder Include="MonoDevelop.VersionControl.Git.ClientLibrary\Init\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> \ No newline at end of file
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
new file mode 100644
index 0000000000..72ab31c7fa
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/BranchUtil.cs
@@ -0,0 +1,51 @@
+//
+// BranchUtil.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Threading.Tasks;
+using System.Text;
+using System.Threading;
+using System.Text.RegularExpressions;
+using System.IO;
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary
+{
+ public static class BranchUtil
+ {
+ public static async Task<GitLocalBranch> GetCurrentBranchAsync (string rootPath, CancellationToken cancellationToken = default)
+ {
+ var handler = new GitOutputTrackerCallbackHandler ();
+ var arguments = new GitArguments (rootPath);
+ 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 ());
+ }
+ }
+}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitBranch.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitBranch.cs
new file mode 100644
index 0000000000..0deadeaa03
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitBranch.cs
@@ -0,0 +1,42 @@
+//
+// GitBranch.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary
+{
+ public abstract class GitBranch : GitReference
+ {
+ static readonly string REFS_HEADS_PREFIX = "refs/heads/";
+ static readonly string REFS_REMOTES_PREFIX = "refs/remotes/";
+
+ public abstract bool IsRemote { get; }
+
+ public override string FullName => (IsRemote ? REFS_REMOTES_PREFIX : REFS_HEADS_PREFIX) + Name;
+
+ public GitBranch (string name) : base (name)
+ {
+ }
+ }
+}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitLocalBranch.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitLocalBranch.cs
new file mode 100644
index 0000000000..0f199ad506
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitLocalBranch.cs
@@ -0,0 +1,37 @@
+//
+// GitLocalBranch.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary
+{
+ public sealed class GitLocalBranch : GitBranch
+ {
+ public override bool IsRemote => false;
+
+ public GitLocalBranch (string name) : base (name)
+ {
+ }
+ }
+}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitReference.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitReference.cs
new file mode 100644
index 0000000000..dfbab41aae
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitReference.cs
@@ -0,0 +1,57 @@
+//
+// GitReference.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary
+{
+ /// <summary>
+ /// Base class for named git branches and tags.
+ /// </summary>
+ public abstract class GitReference : IComparable<GitReference>, IEquatable<GitReference>
+ {
+ public string Name { get; private set; }
+
+ public abstract string FullName { get; }
+
+ public GitReference (string name)
+ {
+ Name = name ?? throw new ArgumentNullException (nameof (name));
+ }
+
+ public int CompareTo (GitReference other)
+ => other == null ? 1 : string.Compare(FullName, other.FullName, StringComparison.Ordinal);
+
+ public bool Equals (GitReference other)
+ {
+ if (other == this)
+ return true;
+ if (other == null || other.GetType () != GetType ())
+ return false;
+ return Name.Equals (other.Name);
+ }
+ }
+
+}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitTag.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitTag.cs
new file mode 100644
index 0000000000..e9a1a5d64a
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Branches/GitTag.cs
@@ -0,0 +1,39 @@
+//
+// GitTag.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary
+{
+ public class GitTag : GitReference
+ {
+ public static readonly string REFS_TAGS_PREFIX = "refs/tags/";
+
+ public override string FullName => REFS_TAGS_PREFIX + Name;
+
+ public GitTag (string name) : base (name)
+ {
+ }
+ }
+}
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/GitProcess.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/GitProcess.cs
index aec694bccb..0a260430e5 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/GitProcess.cs
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/GitProcess.cs
@@ -119,66 +119,68 @@ namespace MonoDevelop.VersionControl.Git.ClientLibrary
throw new ArgumentNullException (nameof (arguments));
if (callbackHandler is null)
throw new ArgumentNullException (nameof (callbackHandler));
-
-
return (askPass ? exclusiveOperationFactory : concurrentOperationFactory).StartNew (delegate {
- try {
- this.callbacks = callbackHandler;
- var startInfo = new ProcessStartInfo ("git");
- startInfo.WorkingDirectory = arguments.GitRootPath;
- startInfo.RedirectStandardError = true;
- startInfo.RedirectStandardOutput = true;
- startInfo.UseShellExecute = false;
- startInfo.Arguments = arguments.Arguments;
+ return StartProcess (arguments, callbackHandler, askPass, cancellationToken);
+ }, cancellationToken);
+ }
- if (askPass) {
- var passApp = Path.Combine (Path.GetDirectoryName (typeof (GitProcess).Assembly.Location), "GitAskPass");
- startInfo.EnvironmentVariables.Add ("GIT_ASKPASS", passApp);
- startInfo.EnvironmentVariables.Add ("SSH_ASKPASS", passApp);
- startInfo.EnvironmentVariables.Add ("MONODEVELOP_GIT_ASKPASS_PIPE", pipe);
- server = new NamedPipeServerStream (pipe);
- }
+ GitResult StartProcess (GitArguments arguments, AbstractGitCallbackHandler callbackHandler, bool askPass, CancellationToken cancellationToken)
+ {
+ try {
+ this.callbacks = callbackHandler;
+ var startInfo = new ProcessStartInfo ("git") {
+ WorkingDirectory = arguments.GitRootPath,
+ RedirectStandardError = true,
+ RedirectStandardOutput = true,
+ UseShellExecute = false,
+ Arguments = arguments.Arguments
+ };
- process = Process.Start (startInfo);
- process.OutputDataReceived += (sender, e) => {
- if (cancellationToken.IsCancellationRequested) {
- SafeKillProcess ();
- cancellationToken.ThrowIfCancellationRequested ();
- }
- if (e?.Data == null)
- return;
+ if (askPass) {
+ var passApp = Path.Combine (Path.GetDirectoryName (typeof (GitProcess).Assembly.Location), "GitAskPass");
+ startInfo.EnvironmentVariables.Add ("GIT_ASKPASS", passApp);
+ startInfo.EnvironmentVariables.Add ("SSH_ASKPASS", passApp);
+ startInfo.EnvironmentVariables.Add ("MONODEVELOP_GIT_ASKPASS_PIPE", pipe);
+ server = new NamedPipeServerStream (pipe);
+ }
+ process = Process.Start (startInfo);
+ process.OutputDataReceived += (sender, e) => {
+ if (cancellationToken.IsCancellationRequested) {
+ SafeKillProcess ();
+ cancellationToken.ThrowIfCancellationRequested ();
+ }
+ if (e?.Data == null)
+ return;
+ if (arguments.TrackProgress && ProgressParser.ParseProgress (e.Data, callbackHandler))
+ return;
+ callbackHandler.OnOutput (e.Data);
+ };
+ process.ErrorDataReceived += (sender, e) => {
+ if (cancellationToken.IsCancellationRequested) {
+ SafeKillProcess ();
+ cancellationToken.ThrowIfCancellationRequested ();
+ }
+ if (e?.Data == null)
+ return;
+ if (IsError (e.Data)) {
+ errorText.AppendLine (e.Data);
+ } else {
if (arguments.TrackProgress && ProgressParser.ParseProgress (e.Data, callbackHandler))
return;
callbackHandler.OnOutput (e.Data);
- };
- process.ErrorDataReceived += (sender, e) => {
- if (cancellationToken.IsCancellationRequested) {
- SafeKillProcess ();
- cancellationToken.ThrowIfCancellationRequested ();
- }
- if (e?.Data == null)
- return;
- if (IsError (e.Data)) {
- errorText.AppendLine (e.Data);
- } else {
- if (arguments.TrackProgress && ProgressParser.ParseProgress (e.Data, callbackHandler))
- return;
- callbackHandler.OnOutput (e.Data);
- }
- };
- if (!process.Start ())
- throw new InvalidOperationException ("Can't start git process.");
- process.BeginOutputReadLine ();
- process.BeginErrorReadLine ();
- cancellationToken.Register (SafeKillProcess);
- if (askPass)
- server.BeginWaitForConnection (HandleAsyncCallback, server);
- process.WaitForExit ();
- } finally {
- SafeKillProcess ();
- }
- return new GitResult { Success = process.ExitCode == 0, ExitCode = process.ExitCode, ErrorMessage = errorText.ToString () };
- }, cancellationToken);
+ }
+ };
+ process.BeginOutputReadLine ();
+ process.BeginErrorReadLine ();
+ cancellationToken.Register (SafeKillProcess);
+ if (askPass)
+ server.BeginWaitForConnection (HandleAsyncCallback, server);
+
+ process.WaitForExit ();
+ } finally {
+ SafeKillProcess ();
+ }
+ return new GitResult { Success = process.ExitCode == 0, ExitCode = process.ExitCode, ErrorMessage = errorText.ToString () };
}
void SafeKillProcess ()
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Init/GitInit.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Init/GitInit.cs
new file mode 100644
index 0000000000..9d29f51136
--- /dev/null
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git.ClientLibrary/MonoDevelop.VersionControl.Git.ClientLibrary/Init/GitInit.cs
@@ -0,0 +1,55 @@
+//
+// GitInit.cs
+//
+// Author:
+// Mike Krüger <mikkrg@microsoft.com>
+//
+// Copyright (c) 2019 Microsoft Corporation. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using System.IO;
+
+namespace MonoDevelop.VersionControl.Git.ClientLibrary
+{
+ public static class GitInit
+ {
+ /// <summary>
+ /// Creates an empty Git repository
+ /// </summary>
+ /// <param name="rootPath">The directory to create the repository in. If this directory does not exist, it will be created.</param>
+ /// <param name="bare">If true, create a bare repository. </param>
+ public static async Task<GitResult> InitAsync (string rootPath, bool bare = false, CancellationToken cancellationToken = default)
+ {
+ var handler = new GitOutputTrackerCallbackHandler ();
+ if (!Directory.Exists (rootPath)) {
+ Directory.CreateDirectory (rootPath);
+ }
+ var arguments = new GitArguments (".");
+ arguments.AddArgument ("init");
+ if (bare)
+ arguments.AddArgument ("--bare");
+ arguments.AddArgument (rootPath);
+ return await new GitProcess ().StartAsync (arguments, handler, false, cancellationToken);
+ }
+ }
+}