Skip to content

Commit 44cf960

Browse files
committed
Merge pull request #223 from retailcoder/source_control
Source Control
2 parents b174d9c + 80652c0 commit 44cf960

15 files changed

+707
-53
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using System.Collections;
6+
using System.Collections.Generic;
7+
using System.Runtime.InteropServices;
8+
using System.ComponentModel;
9+
10+
namespace Rubberduck.Interop
11+
{
12+
[ComVisible(true)]
13+
[Guid("24015981-B6A1-4416-983F-83D4AE51BDEA")]
14+
public interface IBranches : IEnumerable{}
15+
16+
[ComVisible(true)]
17+
[Guid("423A3B28-376B-4F96-A2E0-96E354965048")]
18+
[ProgId("Rubberduck.Branches")]
19+
[ClassInterface(ClassInterfaceType.None)]
20+
[System.ComponentModel.Description("Collection of string representation of branches in a repository.")]
21+
public class Branches : IBranches
22+
{
23+
private IEnumerable<string> branches;
24+
internal Branches(IEnumerable<string> branches)
25+
{
26+
this.branches = branches;
27+
}
28+
29+
public IEnumerator GetEnumerator()
30+
{
31+
return branches.GetEnumerator();
32+
}
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Collections;
7+
using System.Runtime.InteropServices;
8+
using System.ComponentModel;
9+
using Rubberduck.SourceControl;
10+
11+
namespace Rubberduck.Interop
12+
{
13+
[ComVisible(true)]
14+
[Guid("E7769AE2-7C28-425D-B833-544AD54D0534")]
15+
public interface IFileStatusEntries : IEnumerable { }
16+
17+
[ComVisible(true)]
18+
[Guid("E68A88BB-E15C-40D8-8D18-CAF7637312B5")]
19+
[ProgId("Rubberduck.FileStatusEntries")]
20+
[ClassInterface(ClassInterfaceType.None)]
21+
[System.ComponentModel.Description("Collection of IFileEntries representing the status of the repository files.")]
22+
public class FileStatusEntries : IFileStatusEntries
23+
{
24+
private IEnumerable<IFileStatusEntry> entries;
25+
public FileStatusEntries(IEnumerable<IFileStatusEntry> entries)
26+
{
27+
this.entries = entries;
28+
}
29+
30+
public IEnumerator GetEnumerator()
31+
{
32+
return entries.GetEnumerator();
33+
}
34+
}
35+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Collections;
7+
using Rubberduck.SourceControl;
8+
using Microsoft.Vbe.Interop;
9+
using System.Runtime.InteropServices;
10+
using System.ComponentModel;
11+
12+
namespace Rubberduck.Interop
13+
{
14+
[ComVisible(true)]
15+
[Guid("0C22A01D-3255-4BB6-8D67-DCC40A548A32")]
16+
[ProgId("Rubberduck.GitProvider")]
17+
[ClassInterface(ClassInterfaceType.None)]
18+
[System.ComponentModel.Description("VBA Editor integrated access to Git.")]
19+
class GitProvider : SourceControl.GitProvider, ISourceControlProvider
20+
{
21+
public GitProvider(VBProject project)
22+
: base(project){}
23+
24+
public GitProvider(VBProject project, IRepository repository)
25+
: base(project, repository){}
26+
27+
public GitProvider(VBProject project, IRepository repository, string userName, string passWord)
28+
: base(project, repository, userName, passWord){}
29+
30+
private IBranches branches;
31+
public new IBranches Branches
32+
{
33+
get { return new Branches(base.Branches); }
34+
}
35+
36+
public new IFileStatusEntries Status()
37+
{
38+
return new FileStatusEntries(base.Status());
39+
}
40+
}
41+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Rubberduck.SourceControl;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Rubberduck.Interop
10+
{
11+
[ComVisible(true)]
12+
[Guid("A44AF849-3C48-4303-A855-4B156958F3C4")]
13+
public interface ISourceControlProvider
14+
{
15+
[DispId(0)]
16+
IRepository CurrentRepository { get; }
17+
18+
[DispId(1)]
19+
string CurrentBranch { get; }
20+
21+
[DispId(2)]
22+
IBranches Branches { get; }
23+
24+
[DispId(3)]
25+
IRepository Clone(string remotePathOrUrl, string workingDirectory);
26+
27+
[DispId(4)]
28+
IRepository Init(string directory, bool bare = false);
29+
30+
[DispId(5)]
31+
IRepository InitVBAProject(string directory);
32+
33+
[DispId(6)]
34+
void Push();
35+
36+
[DispId(7)]
37+
void Fetch([Optional] string remoteName);
38+
39+
[DispId(8)]
40+
void Pull();
41+
42+
[DispId(9)]
43+
void Commit(string message);
44+
45+
[DispId(10)]
46+
void Merge(string sourceBranch, string destinationBranch);
47+
48+
[DispId(11)]
49+
void Checkout(string branch);
50+
51+
[DispId(12)]
52+
void CreateBranch(string branch);
53+
54+
[DispId(13)]
55+
void Undo(string filePath);
56+
57+
[DispId(14)]
58+
void Revert();
59+
60+
[DispId(15)]
61+
void AddFile(string filePath);
62+
63+
[DispId(16)]
64+
void RemoveFile(string filePath);
65+
66+
[DispId(17)]
67+
IFileStatusEntries Status();
68+
}
69+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Runtime.InteropServices;
7+
using Microsoft.Vbe.Interop;
8+
using Rubberduck.SourceControl;
9+
using System.ComponentModel;
10+
11+
namespace Rubberduck.Interop
12+
{
13+
[ComVisible(true)]
14+
[Guid("335DA0D8-625C-4CB9-90CD-C9A306B9B787")]
15+
public interface _ISourceControlClassFactory
16+
{
17+
[DispId(1)]
18+
ISourceControlProvider CreateGitProvider(VBProject project, [Optional] IRepository repository, [Optional] string userName, [Optional] string passWord);
19+
20+
[DispId(2)]
21+
IRepository CreateRepository(string name, string localDirectory, string remotePathOrUrl);
22+
}
23+
24+
[ComVisible(true)]
25+
[Guid("29FB0A0E-F113-458F-823B-1CD1B60D2CA7")]
26+
[ProgId("Rubberduck.SourceControlClassFactory")]
27+
[ClassInterface(ClassInterfaceType.None)]
28+
public class SourceControlClassFactory : _ISourceControlClassFactory
29+
{
30+
[Description("Returns a new GitProvider. IRepository must be supplied if also passing user credentials.")]
31+
public ISourceControlProvider CreateGitProvider(VBProject project, [Optional] IRepository repository, [Optional] string userName, [Optional] string passWord)
32+
{
33+
if (passWord != null && userName != null)
34+
{
35+
if (repository == null)
36+
{
37+
throw new ArgumentNullException("Must supply an IRepository if supplying credentials.");
38+
}
39+
return new GitProvider(project, repository, userName, passWord);
40+
}
41+
42+
if (repository != null)
43+
{
44+
return new GitProvider(project, repository);
45+
}
46+
47+
return new GitProvider(project);
48+
}
49+
50+
[Description("Returns new instance of repository struct.")]
51+
public IRepository CreateRepository(string name, string localDirectory, string remotePathOrUrl)
52+
{
53+
return new Repository(name, localDirectory, remotePathOrUrl);
54+
}
55+
}
56+
}

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
<Compile Include="Inspections\QualifiedModuleName.cs" />
9898
<Compile Include="Inspections\VariableNotAssignedInspection.cs" />
9999
<Compile Include="Inspections\VariableNotAssignedInspetionResult.cs" />
100+
<Compile Include="Interop\Branches.cs" />
101+
<Compile Include="Interop\FileStatusEntries.cs" />
102+
<Compile Include="Interop\GitProvider.cs" />
103+
<Compile Include="Interop\ISourceControlProvider.cs" />
104+
<Compile Include="Interop\SourceControlClassFactory.cs" />
105+
<Compile Include="SourceControl\FileStatus.cs" />
100106
<Compile Include="UI\CodeExplorer\CodeExplorerNavigateArgs.cs" />
101107
<Compile Include="UI\Refactorings\ExtractMethod\ExtractedDeclarationUsage.cs" />
102108
<Compile Include="UI\Refactorings\ExtractMethod\ExtractedParameter.cs" />
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Runtime.InteropServices;
6+
using System.ComponentModel;
7+
8+
namespace Rubberduck.SourceControl
9+
{
10+
[ComVisible(true)]
11+
[Guid("577CB2D3-A84B-44FF-94EF-F4FC78363D74")]
12+
public interface IFileStatusEntry
13+
{
14+
[DispId(0)]
15+
string FilePath { get; }
16+
17+
//todo: find a way to make this com visible, even if you have to borrow the source code and cast (int) between them.
18+
[DispId(1)]
19+
LibGit2Sharp.FileStatus FileStatus { get; }
20+
}
21+
22+
[ComVisible(true)]
23+
[Guid("13AA3AF6-1397-4017-9E97-CBAD6A65FAFA")]
24+
[ProgId("Rubberduck.FileStatus")]
25+
[ClassInterface(ClassInterfaceType.AutoDual)]
26+
public class FileStatusEntry : IFileStatusEntry
27+
{
28+
public string FilePath { get; private set; }
29+
public LibGit2Sharp.FileStatus FileStatus { get; private set; }
30+
31+
public FileStatusEntry(string filePath, LibGit2Sharp.FileStatus fileStatus)
32+
{
33+
this.FilePath = filePath;
34+
this.FileStatus = fileStatus;
35+
}
36+
37+
public FileStatusEntry(LibGit2Sharp.StatusEntry status)
38+
: this(status.FilePath, status.State) { }
39+
}
40+
}

0 commit comments

Comments
 (0)