Skip to content

Commit

Permalink
Feature request. git svn support #45
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Jun 22, 2018
1 parent 38b8ee3 commit cfe6171
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 9 deletions.
49 changes: 49 additions & 0 deletions TGit/Commands/GitSVNMenuCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using SamirBoulema.TGit.Helpers;
using System;
using Microsoft.VisualStudio.Shell;
using EnvDTE;

namespace SamirBoulema.TGit.Commands
{
public class GitSVNMenuCommands
{
private readonly OptionPageGrid _options;
private readonly OleMenuCommandService _mcs;
private readonly DTE _dte;
private readonly EnvHelper _envHelper;

public GitSVNMenuCommands(OleMenuCommandService mcs, DTE dte,
OptionPageGrid options, EnvHelper envHelper)
{
_mcs = mcs;
_options = options;
_dte = dte;
_envHelper = envHelper;
}

public void AddCommands()
{
CommandHelper.AddCommand(_mcs, SvnDCommitCommand, PkgCmdIDList.SvnDCommit);
CommandHelper.AddCommand(_mcs, SvnFetchCommand, PkgCmdIDList.SvnFetch);
CommandHelper.AddCommand(_mcs, SvnRebaseCommand, PkgCmdIDList.SvnRebase);
}

private void SvnDCommitCommand(object sender, EventArgs e)
{
FileHelper.SaveAllFiles(_dte);
ProcessHelper.StartTortoiseGitProc(_envHelper, $"/command:svndcommit /path:\"{_envHelper.GetSolutionDir()}\" /closeonend:{_options.CloseOnEnd}");
}

private void SvnFetchCommand(object sender, EventArgs e)
{
FileHelper.SaveAllFiles(_dte);
ProcessHelper.StartTortoiseGitProc(_envHelper, $"/command:svnrebase /path:\"{_envHelper.GetSolutionDir()}\" /closeonend:{_options.CloseOnEnd}");
}

private void SvnRebaseCommand(object sender, EventArgs e)
{
FileHelper.SaveAllFiles(_dte);
ProcessHelper.StartTortoiseGitProc(_envHelper, $"/command:svnfetch /path:\"{_envHelper.GetSolutionDir()}\" /closeonend:{_options.CloseOnEnd}");
}
}
}
8 changes: 7 additions & 1 deletion TGit/GitConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GitConfig
public string HotfixPrefix;
public string TagPrefix;
public string BugTraqMessage;
public string SvnUrl;

public GitConfig()
{
Expand All @@ -25,6 +26,7 @@ public GitConfig(string input)
ReleasePrefix = string.Empty;
HotfixPrefix = string.Empty;
TagPrefix = string.Empty;
SvnUrl = string.Empty;

foreach (var line in input.Split(';'))
{
Expand Down Expand Up @@ -55,7 +57,11 @@ public GitConfig(string input)
else if (line.StartsWith("bugtraq.message"))
{
BugTraqMessage = line.Split(' ').Last();
}
}
else if (line.StartsWith("svn-remote.svn.url"))
{
SvnUrl = line.Split('=').Last();
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions TGit/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@ public static void GitHubFlow_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand) sender).Visible = EnvHelper.HasSolutionDir() && !EnvHelper.IsGitFlow();
}

public static void GitSvn_BeforeQueryStatus(object sender, EventArgs e)
=> ((OleMenuCommand)sender).Visible = EnvHelper.HasSolutionDir() && EnvHelper.IsGitSvn();
}
}
13 changes: 12 additions & 1 deletion TGit/Helpers/EnvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,25 @@ public EnvHelper(DTE dte)
/// <summary>
/// Check if GitFlow is initialized
/// </summary>
/// <remarks>Getting the actual flow config is cached for 1m</remarks>
/// <remarks>Getting the actual git config is cached for 1m</remarks>
/// <returns></returns>
public bool IsGitFlow()
{
var gitConfig = GetGitConfig();
return !string.IsNullOrEmpty(gitConfig.MasterBranch);
}

/// <summary>
/// Check if Git SVN is used for this repo
/// </summary>
/// <remarks>Getting the actual git config is cached for 1m</remarks>
/// <returns></returns>
public bool IsGitSvn()
{
var gitConfig = GetGitConfig();
return !string.IsNullOrEmpty(gitConfig.SvnUrl);
}

/// <summary>
/// Get the Git config
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion TGit/Helpers/GitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static string GetSshSetup(EnvHelper envHelper)

public static GitConfig GetGitConfig(EnvHelper envHelper)
{
return new GitConfig(ProcessHelper.StartProcessGitResult(envHelper, "config --get-regexp gitflow"));
return new GitConfig(ProcessHelper.StartProcessGitResult(envHelper, "config --get-regexp \"gitflow|bugtraq|svn-remote\""));
}

public static bool RemoteBranchExists(EnvHelper envHelper, string branch)
Expand Down
3 changes: 2 additions & 1 deletion TGit/IconMappings.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ fec49b6d-c04a-42bd-b021-b8b2e5cfb291,17,d53d7256-d44d-4245-bdd2-bfd22943659c,17
fec49b6d-c04a-42bd-b021-b8b2e5cfb291,18,d53d7256-d44d-4245-bdd2-bfd22943659c,18
fec49b6d-c04a-42bd-b021-b8b2e5cfb291,19,d53d7256-d44d-4245-bdd2-bfd22943659c,19
fec49b6d-c04a-42bd-b021-b8b2e5cfb291,20,d53d7256-d44d-4245-bdd2-bfd22943659c,20
fec49b6d-c04a-42bd-b021-b8b2e5cfb291,21,d53d7256-d44d-4245-bdd2-bfd22943659c,21
fec49b6d-c04a-42bd-b021-b8b2e5cfb291,21,d53d7256-d44d-4245-bdd2-bfd22943659c,21
fec49b6d-c04a-42bd-b021-b8b2e5cfb291,22,d53d7256-d44d-4245-bdd2-bfd22943659c,22
4 changes: 4 additions & 0 deletions TGit/Images.imagemanifest
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<ID Name="BrowseRef" Value="19" />
<ID Name="Tag" Value="20" />
<ID Name="AbortMerge" Value="21" />
<ID Name="Rebase" Value="22" />
</Symbols>
<Images>
<Image Guid="$(CustomMoniker)" ID="$(ShowChanges)">
Expand Down Expand Up @@ -94,6 +95,9 @@
<Image Guid="$(CustomMoniker)" ID="$(AbortMerge)">
<Source Uri="$(Resources)/AbortMerge.xaml" />
</Image>
<Image Guid="$(CustomMoniker)" ID="$(Rebase)">
<Source Uri="$(Resources)/Rebase.xaml" />
</Image>
</Images>
<ImageLists />
</ImageManifest>
5 changes: 5 additions & 0 deletions TGit/PkgCmdID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static class PkgCmdIDList
public const uint TGitContextMenu = 0x1027;
public const uint TGitGitFlowMenu = 0x2000;
public const uint TGitGitHubFlowMenu = 0x3000;
public const uint TGitSvnMenu = 0x4000;

public const uint Resolve = 0x137;
public const uint Sync = 0x138;
Expand All @@ -59,5 +60,9 @@ static class PkgCmdIDList
public const uint Tag = 0x141;

public const uint AbortMerge = 0x142;

public const uint SvnDCommit = 0x143;
public const uint SvnFetch = 0x144;
public const uint SvnRebase = 0x145;
}
}
13 changes: 13 additions & 0 deletions TGit/Resources/Images/Rebase.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush Stretch="None">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#FF000000" Geometry="F0 M12,16z M0,0z M11,11.28L11,5C10.97,4.22 10.66,3.53 10.06,2.94 9.46,2.35 8.78,2.03 8,2L7,2 7,0 4,3 7,6 7,4 8,4C8.27,4.02 8.48,4.11 8.69,4.31 8.9,4.51 8.99,4.73 9,5L9,11.28A1.993,1.993,0,0,0,10,15A1.993,1.993,0,0,0,11,11.28z M10,14.2C9.34,14.2 8.8,13.65 8.8,13 8.8,12.35 9.35,11.8 10,11.8 10.65,11.8 11.2,12.35 11.2,13 11.2,13.65 10.65,14.2 10,14.2z M4,3C4,1.89,3.11,1,2,1A1.993,1.993,0,0,0,1,4.72L1,11.28A1.993,1.993,0,0,0,2,15A1.993,1.993,0,0,0,3,11.28L3,4.72C3.59,4.38,4,3.74,4,3z M3.2,13C3.2,13.66 2.65,14.2 2,14.2 1.35,14.2 0.8,13.65 0.8,13 0.8,12.35 1.35,11.8 2,11.8 2.65,11.8 3.2,12.35 3.2,13z M2,4.2C1.34,4.2 0.8,3.65 0.8,3 0.8,2.35 1.35,1.8 2,1.8 2.65,1.8 3.2,2.35 3.2,3 3.2,3.65 2.65,4.2 2,4.2z" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>
2 changes: 1 addition & 1 deletion TGit/Resources/License.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Samir Boulema
Copyright (c) 2018 Samir Boulema

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file modified TGit/Resources/octicons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified TGit/Resources/octicons.pxd
Binary file not shown.
5 changes: 5 additions & 0 deletions TGit/TGIT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\GitSVNMenuCommands.cs" />
<Compile Include="Commands\GitFlowMenuCommands.cs" />
<Compile Include="Commands\MainMenuCommands.cs" />
<Compile Include="Commands\ContextMenuCommands.cs" />
Expand Down Expand Up @@ -321,6 +322,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Resources\Images\Rebase.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Resources\Images\Tag.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
51 changes: 51 additions & 0 deletions TGit/TGIT.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
</Strings>
</Menu>

<!--Git SVN Menu-->
<Menu guid="guidTGitCmdSet" id="TGitSVNMenu" priority="0x0300" type="Menu">
<Parent guid="guidTGitCmdSet" id="firstMenuGroup"/>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<Strings>
<ButtonText>SVN</ButtonText>
<CommandName>SVN</CommandName>
</Strings>
</Menu>

<!--Toolbar Menu-->
<Menu guid="guidTGitCmdSet" id="Toolbar" type="Toolbar">
<Strings>
Expand All @@ -58,6 +69,11 @@
</Menus>

<Groups>
<!--SVN-->
<Group guid="guidTGitCmdSet" id="TGitSVNMenuGroup" priority="0x0000">
<Parent guid="guidTGitCmdSet" id="TGitSVNMenu"/>
</Group>

<!--Flow Group-->
<Group guid="guidTGitCmdSet" id="TGitGitFlowMenuGroup" priority="0x0000">
<Parent guid="guidTGitCmdSet" id="TGitGitFlowMenu"/>
Expand Down Expand Up @@ -138,6 +154,32 @@
</Groups>

<Buttons>
<!--SVN Buttons-->
<Button guid="guidTGitCmdSet" id="svnDCommit" priority="0x0100" type="Button">
<Parent guid="guidTGitCmdSet" id="TGitSVNMenuGroup" />
<Icon guid="guidImages" id="commit" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Commit...</ButtonText>
</Strings>
</Button>
<Button guid="guidTGitCmdSet" id="svnFetch" priority="0x0100" type="Button">
<Parent guid="guidTGitCmdSet" id="TGitSVNMenuGroup" />
<Icon guid="guidImages" id="fetch" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Fetch...</ButtonText>
</Strings>
</Button>
<Button guid="guidTGitCmdSet" id="svnRebase" priority="0x0100" type="Button">
<Parent guid="guidTGitCmdSet" id="TGitSVNMenuGroup" />
<Icon guid="guidImages" id="rebase" />
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Rebase...</ButtonText>
</Strings>
</Button>

<!--GitFlow Buttons-->
<Button guid="guidTGitCmdSet" id="startFeature" priority="0x0100" type="Button">
<Parent guid="guidTGitCmdSet" id="TGitGitFlowMenuGroup" />
Expand Down Expand Up @@ -490,6 +532,7 @@
<IDSymbol name="browseRef" value="19" />
<IDSymbol name="tag" value="20" />
<IDSymbol name="abortMerge" value="21" />
<IDSymbol name="rebase" value="22" />
</GuidSymbol>

<!--Special Context Menus-->
Expand All @@ -514,6 +557,14 @@
<IDSymbol name="fifthMenuGroup" value="0x1025" />
<IDSymbol name="sixthMenuGroup" value="0x1026" />

<!--SVN Menu-->
<IDSymbol name="TGitSVNMenu" value="0x4000"/>
<IDSymbol name="TGitSVNMenuGroup" value="0x4001"/>

<IDSymbol name="svnDCommit" value="0x0143"/>
<IDSymbol name="svnRebase" value="0x0144"/>
<IDSymbol name="svnFetch" value="0x0145"/>

<!--GitFlow Menu-->
<IDSymbol name="TGitGitFlowMenu" value="0x2000"/>
<IDSymbol name="TGitGitFlowMenuGroup" value="0x2001"/>
Expand Down
8 changes: 6 additions & 2 deletions TGit/TGITPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ private void MainThreadInitialization()
{
if (null == _mcs) return;

// Add all commands
new MainMenuCommands(_mcs, _dte, _options, _envHelper).AddCommands();

new ContextMenuCommands(_mcs, _dte, _options, _envHelper).AddCommands();

new GitFlowMenuCommands(_mcs, _dte, _options, _envHelper).AddCommands();
new GitSVNMenuCommands(_mcs, _dte, _options, _envHelper).AddCommands();

// Add all menus
var tgitMenu = CommandHelper.CreateCommand(PkgCmdIDList.TGitMenu);
Expand All @@ -121,6 +121,10 @@ private void MainThreadInitialization()
var tgitGitHubFlowMenu = CommandHelper.CreateCommand(PkgCmdIDList.TGitGitHubFlowMenu);
tgitGitHubFlowMenu.BeforeQueryStatus += CommandHelper.GitHubFlow_BeforeQueryStatus;
_mcs.AddCommand(tgitGitHubFlowMenu);

var tgitGitSvnMenu = CommandHelper.CreateCommand(PkgCmdIDList.TGitSvnMenu);
tgitGitSvnMenu.BeforeQueryStatus += CommandHelper.GitSvn_BeforeQueryStatus;
_mcs.AddCommand(tgitGitSvnMenu);
}
}
}
2 changes: 1 addition & 1 deletion TGit/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<Metadata>
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="4.8" Language="en-US" Publisher="Samir L. Boulema" />
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="4.9" Language="en-US" Publisher="Samir L. Boulema" />
<DisplayName>TGit</DisplayName>
<Description xml:space="preserve">Control TortoiseGit from within Visual Studio</Description>
<MoreInfo>https://github.com/sboulema/TGit</MoreInfo>
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 4.8.{build}
version: 4.9.{build}
skip_tags: true

image: Visual Studio 2017
Expand Down

0 comments on commit cfe6171

Please sign in to comment.