Browse Source

close #230: Add option to disable automatic 'git add'

pull/573/merge
Siegfried Pammer 11 years ago
parent
commit
3ad5b751be
  1. 21
      data/resources/StringResources.resx
  2. 7
      src/AddIns/VersionControl/GitAddIn/GitAddIn.addin
  3. 22
      src/AddIns/VersionControl/GitAddIn/GitAddIn.csproj
  4. 65
      src/AddIns/VersionControl/GitAddIn/Src/AddInOptions.cs
  5. 14
      src/AddIns/VersionControl/GitAddIn/Src/Git.cs
  6. 35
      src/AddIns/VersionControl/GitAddIn/Src/GitOptionsPanel.xaml
  7. 77
      src/AddIns/VersionControl/GitAddIn/Src/GitOptionsPanel.xaml.cs
  8. 5
      src/AddIns/VersionControl/GitAddIn/Src/RegisterEventsCommand.cs

21
data/resources/StringResources.resx

@ -8353,4 +8353,25 @@ Press Esc to cancel this operation.</value> @@ -8353,4 +8353,25 @@ Press Esc to cancel this operation.</value>
<data name="CSharpBinding.Refactoring.EventCreation.EventHandlerText" xml:space="preserve">
<value>&lt;Create ${HandlerName}&gt;</value>
</data>
<data name="AddIns.Git.Options.Title" xml:space="preserve">
<value>Git Options</value>
</data>
<data name="AddIns.Git.NoPathFoundStatus" xml:space="preserve">
<value>No Git installation found.</value>
</data>
<data name="AddIns.Git.PathAutoDetectStatus" xml:space="preserve">
<value>(automatically detected)</value>
</data>
<data name="AddIns.Git.DirectoryDoesNotContainGit" xml:space="preserve">
<value>'git.exe' was not found in the selected directory!</value>
</data>
<data name="AddIns.Git.Options.FindGitPath" xml:space="preserve">
<value>Select Git path</value>
</data>
<data name="AddIns.Git.Options.ResetGitPath" xml:space="preserve">
<value>Reset Git path</value>
</data>
<data name="AddIns.Git.Options.GitPath" xml:space="preserve">
<value>Git Path</value>
</data>
</root>

7
src/AddIns/VersionControl/GitAddIn/GitAddIn.addin

@ -58,4 +58,11 @@ @@ -58,4 +58,11 @@
<Path name = "/SharpDevelop/Pads/ProjectBrowser/ContextMenu/FileNode">
<Include id = "SubversionInclude" path = "/SharpDevelop/Pads/ProjectBrowser/ContextMenu/GitItem"/>
</Path>
<Path name = "/SharpDevelop/Dialogs/OptionsDialog/ToolsOptions">
<OptionPanel id = "GitOptionsPanel"
insertafter="SubversionOptionsPanel"
label = "${res:AddIns.Git.Options.Title}"
class = "ICSharpCode.GitAddIn.GitOptionsPanel"/>
</Path>
</AddIn>

22
src/AddIns/VersionControl/GitAddIn/GitAddIn.csproj

@ -40,6 +40,8 @@ @@ -40,6 +40,8 @@
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@ -50,20 +52,29 @@ @@ -50,20 +52,29 @@
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\AddInOptions.cs" />
<Compile Include="Src\Commands.cs" />
<Compile Include="Src\Git.cs" />
<Compile Include="Src\GitGuiWrapper.cs" />
<Compile Include="Src\GitMessageView.cs" />
<Compile Include="Src\GitOptionsPanel.xaml.cs">
<DependentUpon>GitOptionsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\GitStatusCache.cs" />
<Compile Include="Src\GitVersionProvider.cs" />
<Compile Include="Src\IsUnderGitControlCondition.cs" />
@ -87,10 +98,21 @@ @@ -87,10 +98,21 @@
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>
<Name>ICSharpCode.Core.WinForms</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="Src\GitOptionsPanel.xaml" />
</ItemGroup>
</Project>

65
src/AddIns/VersionControl/GitAddIn/Src/AddInOptions.cs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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 ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
namespace ICSharpCode.GitAddIn
{
public static class AddInOptions
{
public static readonly string OptionsProperty = "ICSharpCode.Git.Options";
static readonly Properties properties;
static AddInOptions()
{
properties = SD.PropertyService.NestedProperties(OptionsProperty);
}
#region Properties
public static bool AutomaticallyAddFiles {
get {
return properties.Get("AutomaticallyAddFiles", true);
}
set {
properties.Set("AutomaticallyAddFiles", value);
}
}
public static bool AutomaticallyDeleteFiles {
get {
return properties.Get("AutomaticallyDeleteFiles", true);
}
set {
properties.Set("AutomaticallyDeleteFiles", value);
}
}
public static string PathToGit {
get {
return properties.Get("PathToGit", (string)null);
}
set {
properties.Set("PathToGit", value);
}
}
#endregion
}
}

14
src/AddIns/VersionControl/GitAddIn/Src/Git.cs

@ -105,6 +105,12 @@ namespace ICSharpCode.GitAddIn @@ -105,6 +105,12 @@ namespace ICSharpCode.GitAddIn
/// </summary>
public static string FindGit()
{
if (AddInOptions.PathToGit != null) {
if (File.Exists(AddInOptions.PathToGit))
return AddInOptions.PathToGit;
return null;
}
string pathVariable = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
string[] paths = pathVariable.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries);
foreach (string path in paths) {
@ -129,6 +135,14 @@ namespace ICSharpCode.GitAddIn @@ -129,6 +135,14 @@ namespace ICSharpCode.GitAddIn
return null;
}
/// <summary>
/// Checks whether 'git.exe' is available at the given path.
/// </summary>
public static bool IsGitPath(string path)
{
return File.Exists(Path.Combine(path, "git.exe"));
}
/*
/// <summary>
/// Runs git and returns the output if successful (exit code 0).

35
src/AddIns/VersionControl/GitAddIn/Src/GitOptionsPanel.xaml

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
<gui:OptionPanel x:Class="ICSharpCode.GitAddIn.GitOptionsPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
xmlns:local="clr-namespace:ICSharpCode.GitAddIn"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<widgets:StackPanelWithSpacing SpaceBetweenItems="10">
<GroupBox Header="{core:Localize AddIns.Git.Options.Title}">
<widgets:StackPanelWithSpacing SpaceBetweenItems="10">
<CheckBox
Content="{core:Localize AddIns.Subversion.Options.AutoDelete}"
IsChecked="{core:OptionBinding local:AddInOptions.AutomaticallyDeleteFiles}" />
<CheckBox
Content="{core:Localize AddIns.Subversion.Options.AutoAdd}"
IsChecked="{core:OptionBinding local:AddInOptions.AutomaticallyAddFiles}" />
</widgets:StackPanelWithSpacing>
</GroupBox>
<GroupBox Header="{core:Localize AddIns.Git.Options.GitPath}">
<StackPanel>
<TextBlock Margin="3,5,3,20" x:Name="status" TextAlignment="Center" TextWrapping="Wrap" />
<widgets:StackPanelWithSpacing SpaceBetweenItems="10" HorizontalAlignment="Center" Orientation="Horizontal">
<Button Content="{core:Localize AddIns.Git.Options.FindGitPath}"
HorizontalAlignment="Center"
Click="FindGitPath_Click"
Style="{x:Static core:GlobalStyles.ButtonStyle}" />
<Button Content="{core:Localize AddIns.Git.Options.ResetGitPath}"
HorizontalAlignment="Center"
Click="ResetGitPath_Click"
Style="{x:Static core:GlobalStyles.ButtonStyle}" />
</widgets:StackPanelWithSpacing>
</StackPanel>
</GroupBox>
</widgets:StackPanelWithSpacing>
</gui:OptionPanel>

77
src/AddIns/VersionControl/GitAddIn/Src/GitOptionsPanel.xaml.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// 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;
using System.Windows;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using Microsoft.Win32;
namespace ICSharpCode.GitAddIn
{
/// <summary>
/// Interaction logic for GitOptionsPanel.xaml
/// </summary>
public partial class GitOptionsPanel : OptionPanel
{
public GitOptionsPanel()
{
InitializeComponent();
SetGitStatus();
}
void SetGitStatus()
{
string path = AddInOptions.PathToGit;
if (path == null) {
path = Git.FindGit();
if (path == null) {
path = SD.ResourceService.GetString("AddIns.Git.NoPathFoundStatus");
} else {
path += Environment.NewLine + SD.ResourceService.GetString("AddIns.Git.PathAutoDetectStatus");
}
}
status.Text = path;
}
void FindGitPath_Click(object sender, RoutedEventArgs a)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = "exe";
dlg.Filter = StringParser.Parse("Git|git.exe|${res:SharpDevelop.FileFilter.AllFiles}|*.*");
if (dlg.ShowDialog() == true) {
string path = Path.GetDirectoryName(dlg.FileName);
if (Git.IsGitPath(path)) {
AddInOptions.PathToGit = Path.Combine(path, "git.exe");
} else {
MessageService.ShowError("${res:AddIns.Git.DirectoryDoesNotContainGit}");
}
}
SetGitStatus();
}
void ResetGitPath_Click(object sender, RoutedEventArgs a)
{
AddInOptions.PathToGit = null;
SetGitStatus();
}
}
}

5
src/AddIns/VersionControl/GitAddIn/Src/RegisterEventsCommand.cs

@ -49,12 +49,14 @@ namespace ICSharpCode.GitAddIn @@ -49,12 +49,14 @@ namespace ICSharpCode.GitAddIn
async void AddFile(string fileName)
{
if (!AddInOptions.AutomaticallyAddFiles) return;
await Git.AddAsync(fileName);
ClearStatusCacheAndEnqueueFile(fileName);
}
async void RemoveFile(string fileName)
{
if (!AddInOptions.AutomaticallyDeleteFiles) return;
if (GitStatusCache.GetFileStatus(fileName) == GitStatus.Added) {
await Git.RemoveAsync(fileName, true);
ClearStatusCacheAndEnqueueFile(fileName);
@ -63,7 +65,8 @@ namespace ICSharpCode.GitAddIn @@ -63,7 +65,8 @@ namespace ICSharpCode.GitAddIn
async void RenameFile(string sourceFileName, string targetFileName)
{
await Git.AddAsync(targetFileName);
if (AddInOptions.AutomaticallyAddFiles)
await Git.AddAsync(targetFileName);
ClearStatusCacheAndEnqueueFile(targetFileName);
RemoveFile(sourceFileName);
}

Loading…
Cancel
Save