-
Notifications
You must be signed in to change notification settings - Fork 16
/
GitTfsPlugin.cs
53 lines (45 loc) · 1.68 KB
/
GitTfsPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using GitUIPluginInterfaces;
using ResourceManager;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace GitTfs.GitExtensions.Plugin
{
public class GitTfsPlugin : GitPluginBase, IGitPluginForRepository
{
public GitTfsPlugin()
{
SetNameAndDescription("Git-TFS");
Translate();
}
public override bool Execute(GitUIBaseEventArgs gitUiCommands)
{
if (string.IsNullOrEmpty(gitUiCommands.GitModule.WorkingDir))
{
return false;
}
var remotes = GetTfsRemotes(gitUiCommands.GitUICommands);
if (remotes.Any())
{
new GitTfsDialog(gitUiCommands.GitUICommands, PluginSettings, remotes).ShowDialog();
return true;
}
MessageBox.Show("The active repository has no TFS remotes.", "Git-TFS Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
private static IEnumerable<string> GetTfsRemotes(IGitUICommands commands)
{
var result = commands.GitCommand("config --get-regexp tfs-remote");
var matches = Regex.Matches(result, @"tfs-remote\.(.+)\.repository ");
return matches.Count > 0
? matches.Cast<Match>().Select(g => g.Groups[1].Value).Distinct()
: Enumerable.Empty<string>();
}
public SettingsContainer PluginSettings
{
get { return new SettingsContainer(Settings); }
}
}
}