Skip to content

Commit c8c6147

Browse files
committed
Fix coding standards
Updated to output that the process is killed. Up'd version number Updated to have text when performing operation Made all the GIT commands accept cancellation tokens
1 parent 79c0307 commit c8c6147

File tree

11 files changed

+41
-52
lines changed

11 files changed

+41
-52
lines changed

GitSquash.VisualStudio.Extension/CommentWriter/CommentWriter.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
<ErrorReport>prompt</ErrorReport>
3636
<WarningLevel>4</WarningLevel>
3737
<DocumentationFile>bin\Release\CommentWriter.XML</DocumentationFile>
38+
<RunCodeAnalysis>true</RunCodeAnalysis>
39+
<CodeAnalysisRuleSet>..\gitsquashruleset.ruleset</CodeAnalysisRuleSet>
3840
</PropertyGroup>
3941
<ItemGroup>
4042
<Reference Include="System" />

GitSquash.VisualStudio.Extension/CommentWriter/Program.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ public static void Main(string[] args)
2323

2424
var tempCommentFileName = Environment.GetEnvironmentVariable("COMMENT_FILE_NAME");
2525

26-
if (string.IsNullOrWhiteSpace(tempCommentFileName))
27-
{
28-
string[] lines = File.ReadAllLines(fileName);
29-
WriteCommentFile(fileName, lines);
30-
}
31-
else
32-
{
33-
string[] lines = File.ReadAllLines(tempCommentFileName);
34-
WriteCommentFile(fileName, lines);
35-
}
26+
string[] lines = File.ReadAllLines(string.IsNullOrWhiteSpace(tempCommentFileName) ? fileName : tempCommentFileName);
27+
28+
WriteCommentFile(fileName, lines);
3629
}
3730

3831
private static void WriteCommentFile(string fileName, string[] lines)

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio.Extension/Converters/FalseToVisibilityConverter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Globalization;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
96
using System.Windows;
107
using System.Windows.Data;
118

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
<ErrorReport>prompt</ErrorReport>
5959
<WarningLevel>4</WarningLevel>
6060
<DocumentationFile>bin\Release\GitSquash.VisualStudio.Extension.xml</DocumentationFile>
61+
<RunCodeAnalysis>true</RunCodeAnalysis>
62+
<CodeAnalysisRuleSet>..\gitsquashruleset.ruleset</CodeAnalysisRuleSet>
6163
</PropertyGroup>
6264
<ItemGroup>
6365
<Compile Include="Converters\AllTrueToVisibleConverter.cs" />

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio.Extension/SquashNavigationItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public SquashNavigationItem([Import(typeof(SVsServiceProvider))] IServiceProvide
3333
this.Image = Properties.Resources.SquashIcon;
3434
this.IsVisible = false;
3535
this.Text = Properties.Resources.SquashName;
36-
var teamExplorer = this.GetService<ITeamExplorer>();
36+
ITeamExplorer teamExplorer = this.GetService<ITeamExplorer>();
3737
teamExplorer.PropertyChanged += this.TeamExplorerOnPropertyChanged;
3838
this.gitService = (IGitExt)serviceProvider.GetService(typeof(IGitExt));
3939
}
@@ -58,7 +58,7 @@ public override void Execute()
5858
this.ShowNotification(ex.Message, NotificationType.Error);
5959
}
6060

61-
var service = this.GetService<ITeamExplorer>();
61+
ITeamExplorer service = this.GetService<ITeamExplorer>();
6262
service?.NavigateToPage(new Guid(GitSquashPackage.SquashPageGuidString), null);
6363
}
6464

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio.Extension/SquashPage.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
using System;
44
using System.ComponentModel.Composition;
55
using System.IO;
6-
using System.Linq;
76
using System.Windows;
87
using System.Windows.Threading;
9-
108
using GalaSoft.MvvmLight.Command;
11-
12-
using GitSquash.VisualStudio.Extension.View;
13-
using GitSquash.VisualStudio.Extension.ViewModel;
14-
159
using Microsoft.TeamFoundation.Controls;
1610
using Microsoft.VisualStudio.Shell;
1711
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
18-
1912
using TeamExplorer.Common;
13+
using View;
14+
using ViewModel;
2015

2116
/// <summary>
2217
/// Represents a page in the team explorer
@@ -62,7 +57,7 @@ public override void Initialize(object sender, PageInitializeEventArgs e)
6257

6358
this.Title = "Squash";
6459

65-
if (this.AreGitToolsInstalled() == false)
60+
if (AreGitToolsInstalled() == false)
6661
{
6762
this.ShowPage(TeamExplorerPageIds.GitInstallThirdPartyTools);
6863
return;
@@ -83,21 +78,21 @@ public override void Refresh()
8378
this.view.ViewModel.Refresh();
8479
}
8580

86-
private void SetViewModel()
87-
{
88-
var showBranches = new RelayCommand(() => this.ShowPage(TeamExplorerPageIds.GitBranches));
89-
var showConflicts = new RelayCommand(() => this.ShowPage(TeamExplorerPageIds.GitConflicts));
90-
var showChanges = new RelayCommand(() => this.ShowPage(TeamExplorerPageIds.GitChanges));
91-
var squashWrapper = this.GetService<IGitSquashWrapper>();
92-
this.view.ViewModel = new SquashViewModel(squashWrapper, showBranches, showConflicts, showChanges);
93-
}
94-
95-
private bool AreGitToolsInstalled()
81+
private static bool AreGitToolsInstalled()
9682
{
9783
var gitInstallationPath = GitHelper.GetGitInstallationPath();
9884
string pathToGit = Path.Combine(Path.Combine(gitInstallationPath, "bin\\git.exe"));
9985

10086
return File.Exists(pathToGit);
10187
}
88+
89+
private void SetViewModel()
90+
{
91+
RelayCommand showBranches = new RelayCommand(() => this.ShowPage(TeamExplorerPageIds.GitBranches));
92+
RelayCommand showConflicts = new RelayCommand(() => this.ShowPage(TeamExplorerPageIds.GitConflicts));
93+
RelayCommand showChanges = new RelayCommand(() => this.ShowPage(TeamExplorerPageIds.GitChanges));
94+
IGitSquashWrapper squashWrapper = this.GetService<IGitSquashWrapper>();
95+
this.view.ViewModel = new SquashViewModel(squashWrapper, showBranches, showConflicts, showChanges);
96+
}
10297
}
10398
}

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio.Extension/View/SquashView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
using System.Windows;
44

5-
using GitSquash.VisualStudio.Extension.ViewModel;
5+
using ViewModel;
66

77
/// <summary>
88
/// Interaction logic for SquashView.xaml

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
<ErrorReport>prompt</ErrorReport>
3636
<WarningLevel>4</WarningLevel>
3737
<DocumentationFile>bin\Release\GitSquash.VisualStudio.xml</DocumentationFile>
38+
<CodeAnalysisRuleSet>..\gitsquashruleset.ruleset</CodeAnalysisRuleSet>
39+
<RunCodeAnalysis>true</RunCodeAnalysis>
3840
</PropertyGroup>
3941
<PropertyGroup>
4042
<SignAssembly>true</SignAssembly>

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class GitSquashWrapper : IGitSquashWrapper
2525

2626
private static StringBuilder error = new StringBuilder();
2727

28-
private readonly IGitSquashOutputLogger outputLogger;
28+
private static IGitSquashOutputLogger outputLogger;
2929

3030
private readonly string repoDirectory;
3131

@@ -37,11 +37,11 @@ public class GitSquashWrapper : IGitSquashWrapper
3737
/// Initializes a new instance of the <see cref="GitSquashWrapper" /> class.
3838
/// </summary>
3939
/// <param name="repoDirectory">The directory where the repository is located</param>
40-
/// <param name="outputLogger">The output logger to output git transactions.</param>
41-
public GitSquashWrapper(string repoDirectory, IGitSquashOutputLogger outputLogger)
40+
/// <param name="logger">The output logger to output git transactions.</param>
41+
public GitSquashWrapper(string repoDirectory, IGitSquashOutputLogger logger)
4242
{
4343
this.repoDirectory = repoDirectory;
44-
this.outputLogger = outputLogger;
44+
outputLogger = logger;
4545

4646
this.repository = new Repository(repoDirectory);
4747
}
@@ -208,7 +208,7 @@ protected virtual void Dispose(bool isDisposing)
208208

209209
if (isDisposing)
210210
{
211-
this.repository?.Dispose();
211+
this.repository.Dispose();
212212
}
213213

214214
this.isDisposed = true;
@@ -225,7 +225,11 @@ private static Task<int> RunProcessAsync(Process process, CancellationToken toke
225225
{
226226
var tcs = new TaskCompletionSource<int>();
227227

228-
token.Register(process.Kill);
228+
token.Register(() =>
229+
{
230+
process.Kill();
231+
outputLogger.WriteLine("Killing GIT process.");
232+
});
229233

230234
process.Exited += (s, ea) => tcs.SetResult(process.ExitCode);
231235

@@ -281,7 +285,7 @@ private bool GetWritersName(out string rebaseWriter, out string commentWriter)
281285

282286
private async Task<GitCommandResponse> RunGit(string gitArguments, CancellationToken token, IDictionary<string, string> extraEnvironmentVariables = null, [CallerMemberName] string callerMemberName = null)
283287
{
284-
this.outputLogger.WriteLine($"execute: git {gitArguments}");
288+
outputLogger.WriteLine($"execute: git {gitArguments}");
285289
error = new StringBuilder();
286290
output = new StringBuilder();
287291

@@ -317,7 +321,7 @@ private void OnOutputDataReceived(object sender, DataReceivedEventArgs dataRecei
317321
}
318322

319323
output.Append(dataReceivedEventArgs.Data);
320-
this.outputLogger.WriteLine(dataReceivedEventArgs.Data);
324+
outputLogger.WriteLine(dataReceivedEventArgs.Data);
321325
}
322326

323327
private void OnErrorReceived(object sender, DataReceivedEventArgs dataReceivedEventArgs)
@@ -329,14 +333,13 @@ private void OnErrorReceived(object sender, DataReceivedEventArgs dataReceivedEv
329333

330334
if (!dataReceivedEventArgs.Data.StartsWith("fatal:", StringComparison.OrdinalIgnoreCase))
331335
{
332-
this.outputLogger.WriteLine(dataReceivedEventArgs.Data);
336+
outputLogger.WriteLine(dataReceivedEventArgs.Data);
333337
return;
334338
}
335339

336340
error = new StringBuilder();
337341
error.Append(dataReceivedEventArgs.Data);
338-
Debug.WriteLine(dataReceivedEventArgs.Data);
339-
this.outputLogger.WriteLine($"Error: {dataReceivedEventArgs.Data}");
342+
outputLogger.WriteLine($"Error: {dataReceivedEventArgs.Data}");
340343
}
341344
}
342345
}

GitSquash.VisualStudio.Extension/GitSquash.VisualStudio/GlobalSuppressions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
// a specific target and scoped to a namespace, type, member, etc.
55
using System.Diagnostics.CodeAnalysis;
66

7-
[assembly:
8-
SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1636:File header copyright text must match", Justification = "Don't care", Scope = "namespace", Target = "~N:GitRebase.VisualStudio")]
7+
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1636:File header copyright text must match", Justification = "Don't care", Scope = "namespace", Target = "~N:GitRebase.VisualStudio")]

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// <copyright file="IGitSquashWrapper.cs" company="Glenn Watson">
2-
// Copyright (c) Glenn Watson. All rights reserved.
3-
// </copyright>
4-
5-
namespace GitSquash.VisualStudio
1+
namespace GitSquash.VisualStudio
62
{
73
using System;
84
using System.Collections.Generic;

0 commit comments

Comments
 (0)