Skip to content

Commit bb06075

Browse files
committed
Now using the visual studio version of libgit2sharp
Updated the git wrapper to use repository only when needed, not keeping instance open Bumped version to 1.0.0.8
1 parent c8c6147 commit bb06075

File tree

8 files changed

+277
-60
lines changed

8 files changed

+277
-60
lines changed

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio.Extension/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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">
33
<Metadata>
4-
<Identity Id="GitSquash.VisualStudio.Extension.Glenn Watson.9d974827-f458-4741-b96c-f6926984b1d8" Version="1.0.0.7" Language="en-US" Publisher="Glenn Watson" />
4+
<Identity Id="GitSquash.VisualStudio.Extension.Glenn Watson.9d974827-f458-4741-b96c-f6926984b1d8" Version="1.0.0.8" Language="en-US" Publisher="Glenn Watson" />
55
<DisplayName>Git Squash</DisplayName>
66
<Description xml:space="preserve">Allows rebasing with squash in Visual Studio Team Explorer</Description>
77
<MoreInfo>https://github.com/glennawatson/GitSquash-VIsualStudio</MoreInfo>

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio/GitSquash.VisualStudio.csproj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
4646
</PropertyGroup>
4747
<ItemGroup>
48-
<Reference Include="LibGit2Sharp">
49-
<HintPath>..\..\packages\LibGit2Sharp.0.22.0\lib\net40\LibGit2Sharp.dll</HintPath>
50-
<Private>True</Private>
48+
<Reference Include="LibGit2Sharp, Version=0.22.0.0, Culture=neutral, PublicKeyToken=7cbde695407f0333, processorArchitecture=MSIL">
49+
<SpecificVersion>False</SpecificVersion>
50+
<HintPath>.\LibGit2Sharp.dll</HintPath>
5151
</Reference>
5252
<Reference Include="Microsoft.TeamFoundation.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5353
<SpecificVersion>False</SpecificVersion>
@@ -84,6 +84,11 @@
8484
<Compile Include="IGitSquashWrapper.cs" />
8585
<Compile Include="Properties\AssemblyInfo.cs" />
8686
<Compile Include="GitSquashWrapper.cs" />
87+
<Compile Include="Properties\Resources.Designer.cs">
88+
<AutoGen>True</AutoGen>
89+
<DesignTime>True</DesignTime>
90+
<DependentUpon>Resources.resx</DependentUpon>
91+
</Compile>
8792
</ItemGroup>
8893
<ItemGroup>
8994
<None Include="Key.snk" />
@@ -96,6 +101,12 @@
96101
<ItemGroup>
97102
<Content Include="FodyWeavers.xml" />
98103
</ItemGroup>
104+
<ItemGroup>
105+
<EmbeddedResource Include="Properties\Resources.resx">
106+
<Generator>ResXFileCodeGenerator</Generator>
107+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
108+
</EmbeddedResource>
109+
</ItemGroup>
99110
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100111
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
101112
<PropertyGroup>

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio/GitSquashWrapper.cs

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using GitSquash.VisualStudio.Properties;
2+
13
namespace GitSquash.VisualStudio
24
{
35
using System;
@@ -29,10 +31,6 @@ public class GitSquashWrapper : IGitSquashWrapper
2931

3032
private readonly string repoDirectory;
3133

32-
private readonly Repository repository;
33-
34-
private bool isDisposed;
35-
3634
/// <summary>
3735
/// Initializes a new instance of the <see cref="GitSquashWrapper" /> class.
3836
/// </summary>
@@ -42,15 +40,6 @@ public GitSquashWrapper(string repoDirectory, IGitSquashOutputLogger logger)
4240
{
4341
this.repoDirectory = repoDirectory;
4442
outputLogger = logger;
45-
46-
this.repository = new Repository(repoDirectory);
47-
}
48-
49-
/// <inheritdoc />
50-
public void Dispose()
51-
{
52-
this.Dispose(true);
53-
GC.SuppressFinalize(this);
5443
}
5544

5645
/// <inheritdoc />
@@ -62,10 +51,12 @@ public string GetCommitMessages(GitCommit startCommit)
6251
}
6352

6453
var sb = new StringBuilder();
65-
66-
foreach (Commit commit in this.repository.Head.Commits.TakeWhile(x => x.Sha != startCommit.Sha))
54+
using (var repository = GetRepository())
6755
{
68-
sb.AppendLine(commit.Message);
56+
foreach (Commit commit in repository.Head.Commits.TakeWhile(x => x.Sha != startCommit.Sha))
57+
{
58+
sb.AppendLine(commit.Message);
59+
}
6960
}
7061

7162
return sb.ToString();
@@ -74,31 +65,40 @@ public string GetCommitMessages(GitCommit startCommit)
7465
/// <inheritdoc />
7566
public GitBranch GetCurrentBranch()
7667
{
77-
return new GitBranch(this.repository.Head.FriendlyName);
68+
using (var repository = GetRepository())
69+
{
70+
return new GitBranch(repository.Head.FriendlyName);
71+
}
7872
}
7973

8074
/// <inheritdoc />
8175
public async Task<GitCommandResponse> PushForce(CancellationToken token)
8276
{
83-
if (this.repository.Head.IsTracking == false)
77+
using (var repository = GetRepository())
8478
{
85-
return new GitCommandResponse(false, "The branch has not been pushed before.");
86-
}
79+
if (repository.Head.IsTracking == false)
80+
{
81+
return new GitCommandResponse(false, "The branch has not been pushed before.");
82+
}
8783

88-
return await this.RunGit("push -f", token);
84+
return await this.RunGit("push -f", token);
85+
}
8986
}
9087

9188
/// <inheritdoc />
9289
public IEnumerable<GitCommit> GetCommitsForBranch(GitBranch branch, int number = 25)
9390
{
94-
Branch internalBranch = this.repository.Branches.FirstOrDefault(x => x.FriendlyName == branch.FriendlyName);
95-
96-
if (internalBranch == null)
91+
using (var repository = GetRepository())
9792
{
98-
return Enumerable.Empty<GitCommit>();
99-
}
93+
Branch internalBranch = repository.Branches.FirstOrDefault(x => x.FriendlyName == branch.FriendlyName);
94+
95+
if (internalBranch == null)
96+
{
97+
return Enumerable.Empty<GitCommit>();
98+
}
10099

101-
return internalBranch.Commits.Take(number).Select(x => new GitCommit(x.Sha, x.MessageShort));
100+
return internalBranch.Commits.Take(number).Select(x => new GitCommit(x.Sha, x.MessageShort));
101+
}
102102
}
103103

104104
/// <inheritdoc />
@@ -112,21 +112,30 @@ public bool IsRebaseHappening()
112112
/// <inheritdoc />
113113
public bool IsWorkingDirectoryDirty()
114114
{
115-
return this.repository.RetrieveStatus().IsDirty;
115+
using (var repository = GetRepository())
116+
{
117+
return repository.RetrieveStatus().IsDirty;
118+
}
116119
}
117120

118121
/// <inheritdoc />
119122
public bool HasConflicts()
120123
{
121-
return this.repository.Index.IsFullyMerged == false;
124+
using (var repository = GetRepository())
125+
{
126+
return repository.Index.IsFullyMerged == false;
127+
}
122128
}
123129

124130
/// <inheritdoc />
125131
public async Task<GitCommandResponse> Squash(CancellationToken token, string newCommitMessage, GitCommit startCommit)
126132
{
127-
if (this.repository.RetrieveStatus().IsDirty)
133+
using (var repository = GetRepository())
128134
{
129-
return new GitCommandResponse(false, "Cannot rebase: You have unstaged changes.");
135+
if (repository.RetrieveStatus().IsDirty)
136+
{
137+
return new GitCommandResponse(false, "Cannot rebase: You have unstaged changes.");
138+
}
130139
}
131140

132141
string rewriterName;
@@ -155,9 +164,12 @@ public Task<GitCommandResponse> FetchOrigin(CancellationToken token)
155164
/// <inheritdoc />
156165
public async Task<GitCommandResponse> Rebase(CancellationToken token, GitBranch parentBranch)
157166
{
158-
if (this.repository.RetrieveStatus().IsDirty)
167+
using (var repository = GetRepository())
159168
{
160-
return new GitCommandResponse(false, "Cannot rebase: You have unstaged changes.");
169+
if (repository.RetrieveStatus().IsDirty)
170+
{
171+
return new GitCommandResponse(false, "Cannot rebase: You have unstaged changes.");
172+
}
161173
}
162174

163175
GitCommandResponse response = await this.FetchOrigin(token);
@@ -192,26 +204,10 @@ public async Task<GitCommandResponse> Continue(CancellationToken token)
192204
/// <inheritdoc />
193205
public IList<GitBranch> GetBranches()
194206
{
195-
return this.repository.Branches.OrderBy(x => x.FriendlyName).Select(x => new GitBranch(x.FriendlyName)).ToList();
196-
}
197-
198-
/// <summary>
199-
/// Disposes of any objects contained in the class.
200-
/// </summary>
201-
/// <param name="isDisposing">If the ,method is being called by the dispose method.</param>
202-
protected virtual void Dispose(bool isDisposing)
203-
{
204-
if (this.isDisposed)
207+
using (var repository = GetRepository())
205208
{
206-
return;
209+
return repository.Branches.OrderBy(x => x.FriendlyName).Select(x => new GitBranch(x.FriendlyName)).ToList();
207210
}
208-
209-
if (isDisposing)
210-
{
211-
this.repository.Dispose();
212-
}
213-
214-
this.isDisposed = true;
215211
}
216212

217213
private static Process CreateGitProcess(string arguments, string repoDirectory)
@@ -228,7 +224,7 @@ private static Task<int> RunProcessAsync(Process process, CancellationToken toke
228224
token.Register(() =>
229225
{
230226
process.Kill();
231-
outputLogger.WriteLine("Killing GIT process.");
227+
outputLogger.WriteLine(Resources.KillingProcess);
232228
});
233229

234230
process.Exited += (s, ea) => tcs.SetResult(process.ExitCode);
@@ -247,6 +243,11 @@ private static Task<int> RunProcessAsync(Process process, CancellationToken toke
247243
return tcs.Task;
248244
}
249245

246+
private Repository GetRepository()
247+
{
248+
return new Repository(repoDirectory);
249+
}
250+
250251
private bool GetWritersName(out string rebaseWriter, out string commentWriter)
251252
{
252253
rebaseWriter = null;
@@ -339,7 +340,7 @@ private void OnErrorReceived(object sender, DataReceivedEventArgs dataReceivedEv
339340

340341
error = new StringBuilder();
341342
error.Append(dataReceivedEventArgs.Data);
342-
outputLogger.WriteLine($"Error: {dataReceivedEventArgs.Data}");
343+
outputLogger.WriteLine(string.Format(Resources.ErrorGit, dataReceivedEventArgs.Data));
343344
}
344345
}
345346
}

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio/IGitSquashWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// <summary>
99
/// A wrapper around git that will provide the GIT squash actions.
1010
/// </summary>
11-
public interface IGitSquashWrapper : IDisposable
11+
public interface IGitSquashWrapper
1212
{
1313
/// <summary>
1414
/// Determines if there are any conflicts.
Binary file not shown.

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio/Properties/Resources.Designer.cs

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)