Skip to content

Commit 6249f4d

Browse files
committed
Changing libs for git
1 parent a7d33b1 commit 6249f4d

File tree

7 files changed

+73
-92
lines changed

7 files changed

+73
-92
lines changed

AddActionsWorkflow/AddActionsWorkflow.csproj

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,22 @@
9191
</ItemGroup>
9292
<ItemGroup>
9393
<PackageReference Include="CliWrap">
94-
<Version>3.5.0</Version>
94+
<Version>3.6.4</Version>
95+
</PackageReference>
96+
<PackageReference Include="Community.VisualStudio.Toolkit.17">
97+
<Version>17.0.507</Version>
9598
</PackageReference>
9699
<PackageReference Include="Community.VisualStudio.VSCT" Version="16.0.29.6" PrivateAssets="all" />
97-
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.5.4074">
100+
<PackageReference Include="LibGit2Sharp">
101+
<Version>0.27.2</Version>
102+
</PackageReference>
103+
<PackageReference Include="LibGit2Sharp.NativeBinaries">
104+
<Version>2.0.320</Version>
105+
</PackageReference>
106+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.6.2164">
98107
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
99108
<PrivateAssets>all</PrivateAssets>
100109
</PackageReference>
101-
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.492" ExcludeAssets="Runtime">
102-
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
103-
</PackageReference>
104110
</ItemGroup>
105111
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
106112
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />

AddActionsWorkflow/AddActionsWorkflowPackage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace AddActionsWorkflow;
1414
[Guid(PackageGuids.AddActionsWorkflowString)]
1515
[ProvideOptionPage(typeof(OptionsProvider.GeneralOptions), "GitHub Actions Workflow", "General", 0, 0, true)]
1616
[ProvideProfile(typeof(OptionsProvider.GeneralOptions), "GitHub Actions Workflow", "General", 0, 0, true)]
17+
[ProvideBindingPath]
1718
public sealed class AddActionsWorkflowPackage : ToolkitPackage
1819
{
1920
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)

AddActionsWorkflow/Commands/AddWorkflowCommand.cs

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using AddActionsWorkflow.Options;
22
using CliWrap;
3-
using Microsoft;
3+
using LibGit2Sharp;
44
using System.Diagnostics;
55
using System.IO;
66
using System.Text;
@@ -11,7 +11,7 @@ namespace AddActionsWorkflow;
1111
[Command(PackageIds.AddWorkflowCommand)]
1212
internal sealed class AddWorkflowCommand : BaseCommand<AddWorkflowCommand>
1313
{
14-
string finaleWorkflowname = "";
14+
string finaleWorkflowname = string.Empty;
1515
string branchName = "main";
1616

1717
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
@@ -23,7 +23,7 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
2323
var options = await General.GetLiveInstanceAsync();
2424

2525
// try to get the repo root
26-
string repoRoot = await GetGitRootDirAsync(slnDir, options.UseCurrentBranchName);
26+
string repoRoot = await GetGitRootDirAsync(dirInfo.FullName, options.UseCurrentBranchName);
2727
var workflowCreated = await CreateWorkflowTemplateAsync(repoRoot, options);
2828

2929
if (workflowCreated)
@@ -88,50 +88,25 @@ internal async Task<String> GetGitRootDirAsync(string workingDirectory, bool use
8888
{
8989
await VS.StatusBar.ShowMessageAsync("Establishing git root directory...");
9090
var rootGitDir = workingDirectory;
91-
var stdOutBuffer = new StringBuilder();
92-
var stdErrBuffer = new StringBuilder();
9391

94-
var result = await Cli.Wrap("git")
95-
.WithArguments("rev-parse --show-toplevel")
96-
.WithWorkingDirectory(workingDirectory)
97-
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
98-
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
99-
.WithValidation(CommandResultValidation.None)
100-
.ExecuteAsync();
101-
102-
var stdOut = stdOutBuffer.ToString();
103-
var stdErr = stdErrBuffer.ToString();
104-
105-
if (result.ExitCode == 0)
92+
while (!Directory.Exists(Path.Combine(rootGitDir, ".git")))
10693
{
107-
rootGitDir = stdOut;
108-
rootGitDir = rootGitDir.Replace('/', '\\').Replace("\n", "");
109-
110-
if (useCurrentBranch) await GetCurrentBranchNameAsync(workingDirectory);
94+
rootGitDir = Path.GetFullPath(Path.Combine(rootGitDir, ".."));
11195
}
11296

113-
return rootGitDir;
114-
}
115-
116-
internal async Task GetCurrentBranchNameAsync(string workingDirectory)
117-
{
118-
var stdOutBuffer = new StringBuilder();
119-
var stdErrBuffer = new StringBuilder();
120-
121-
var result = await Cli.Wrap("git")
122-
.WithArguments("branch --show-current")
123-
.WithWorkingDirectory(workingDirectory)
124-
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
125-
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
126-
.WithValidation(CommandResultValidation.None)
127-
.ExecuteAsync();
128-
129-
var stdOut = stdOutBuffer.ToString();
130-
var stdErr = stdErrBuffer.ToString();
131-
132-
if (result.ExitCode == 0)
97+
try
98+
{
99+
using (var repo = new Repository(rootGitDir))
100+
{
101+
if (useCurrentBranch) branchName = repo.Head.FriendlyName;
102+
rootGitDir = repo.Info.WorkingDirectory;
103+
}
104+
}
105+
catch (Exception ex)
133106
{
134-
branchName = stdOut;
107+
Debug.WriteLine(ex.Message);
135108
}
109+
110+
return rootGitDir;
136111
}
137112
}

AddActionsWorkflow/Commands/LaunchRemoteUrlCommand.cs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using AddActionsWorkflow.Options;
2-
using CliWrap;
3-
using System;
4-
using System.Collections.Generic;
1+
using LibGit2Sharp;
52
using System.Diagnostics;
63
using System.IO;
74
using System.Linq;
85
using System.Text;
9-
using System.Threading.Tasks;
106

117
namespace AddActionsWorkflow.Commands;
128

@@ -17,29 +13,31 @@ protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
1713
{
1814
// get the repo URI
1915
var dirInfo = new DirectoryInfo((await VS.Solutions.GetCurrentSolutionAsync()).FullPath);
20-
var slnDir = dirInfo.Parent.FullName;
16+
17+
string path = dirInfo.FullName;
18+
19+
while (!Directory.Exists(Path.Combine(path, ".git")))
20+
{
21+
path = Path.GetFullPath(Path.Combine(path, ".."));
22+
}
2123

2224
var stdOutBuffer = new StringBuilder();
2325
var stdErrBuffer = new StringBuilder();
26+
var remoteUri = string.Empty;
2427

25-
var result = await Cli.Wrap("git")
26-
.WithArguments("remote get-url origin --push")
27-
.WithWorkingDirectory(slnDir)
28-
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer))
29-
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))
30-
.WithValidation(CommandResultValidation.None)
31-
.ExecuteAsync();
32-
33-
var stdOut = stdOutBuffer.ToString();
34-
var stdErr = stdErrBuffer.ToString();
35-
36-
if (result.ExitCode == 0)
28+
try
3729
{
38-
_ = Process.Start(stdOut);
39-
}
40-
else
30+
using (var repo = new Repository(path))
31+
{
32+
var headRemote = repo.Head.RemoteName;
33+
var remote = repo.Network.Remotes.FirstOrDefault(r => r.Name == headRemote);
34+
remoteUri = remote.Url;
35+
}
36+
_ = Process.Start(remoteUri);
37+
}
38+
catch (Exception ex)
4139
{
42-
var argError = new UriFormatException(stdErr);
40+
var argError = new UriFormatException(ex.Message);
4341
await argError.LogAsync();
4442
}
4543
}

AddActionsWorkflow/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
[assembly: AssemblyVersion(Vsix.Version)]
1717
[assembly: AssemblyFileVersion(Vsix.Version)]
18+
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\LibGit2Sharp.dll")]
1819

1920
namespace System.Runtime.CompilerServices
2021
{

AddActionsWorkflow/source.extension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal sealed partial class Vsix
1111
public const string Name = "Add Actions Workflow";
1212
public const string Description = @"Adds a GitHub Actions workflow to the solution";
1313
public const string Language = "en-US";
14-
public const string Version = "1.0.0";
14+
public const string Version = "1.0.1";
1515
public const string Author = "Tim Heuer";
1616
public const string Tags = "github, actions, devops, workflow";
1717
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
3-
<Metadata>
4-
<Identity Id="AddActionsWorkflow.727729af-a64d-474f-b03e-aaddf3b5dff6" Version="1.0.0" Language="en-US" Publisher="Tim Heuer" />
5-
<DisplayName>Add Actions Workflow</DisplayName>
6-
<Description xml:space="preserve">Adds a GitHub Actions workflow to the solution</Description>
7-
<MoreInfo>https://github.com/timheuer/AddActionsWorkflow</MoreInfo>
8-
<License>LICENSE.txt</License>
9-
<GettingStartedGuide>https://github.com/timheuer/AddActionsWorkflow</GettingStartedGuide>
10-
<Icon>Resources\Icon.png</Icon>
11-
<PreviewImage>Resources\Icon.png</PreviewImage>
12-
<Tags>github, actions, devops, workflow</Tags>
13-
</Metadata>
14-
<Installation>
15-
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
16-
<ProductArchitecture>amd64</ProductArchitecture>
17-
</InstallationTarget>
18-
</Installation>
19-
<Prerequisites>
20-
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,)" DisplayName="Visual Studio core editor" />
21-
</Prerequisites>
22-
<Assets>
23-
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
24-
</Assets>
3+
<Metadata>
4+
<Identity Id="AddActionsWorkflow.727729af-a64d-474f-b03e-aaddf3b5dff6" Version="1.0.1" Language="en-US" Publisher="Tim Heuer" />
5+
<DisplayName>Add Actions Workflow</DisplayName>
6+
<Description xml:space="preserve">Adds a GitHub Actions workflow to the solution</Description>
7+
<MoreInfo>https://github.com/timheuer/AddActionsWorkflow</MoreInfo>
8+
<License>LICENSE.txt</License>
9+
<GettingStartedGuide>https://github.com/timheuer/AddActionsWorkflow</GettingStartedGuide>
10+
<Icon>Resources\Icon.png</Icon>
11+
<PreviewImage>Resources\Icon.png</PreviewImage>
12+
<Tags>github, actions, devops, workflow</Tags>
13+
</Metadata>
14+
<Installation>
15+
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0, 18.0)">
16+
<ProductArchitecture>amd64</ProductArchitecture>
17+
</InstallationTarget>
18+
</Installation>
19+
<Prerequisites>
20+
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,)" DisplayName="Visual Studio core editor" />
21+
</Prerequisites>
22+
<Assets>
23+
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
24+
</Assets>
2525
</PackageManifest>

0 commit comments

Comments
 (0)