Skip to content

Commit f8181f7

Browse files
committed
Merge pull request #227 from retailcoder/source_control
Source control API is solid.
2 parents c7e44bb + 0abb2c3 commit f8181f7

File tree

7 files changed

+150
-39
lines changed

7 files changed

+150
-39
lines changed

RetailCoder.VBE/Interop/Branches.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@
99

1010
namespace Rubberduck.Interop
1111
{
12-
[ComVisible(true)]
13-
[Guid("24015981-B6A1-4416-983F-83D4AE51BDEA")]
14-
public interface IBranches : IEnumerable{}
15-
1612
[ComVisible(true)]
1713
[Guid("423A3B28-376B-4F96-A2E0-96E354965048")]
1814
[ProgId("Rubberduck.Branches")]
1915
[ClassInterface(ClassInterfaceType.None)]
2016
[System.ComponentModel.Description("Collection of string representation of branches in a repository.")]
21-
public class Branches : IBranches
17+
public class Branches : IEnumerable
2218
{
2319
private IEnumerable<string> branches;
2420
internal Branches(IEnumerable<string> branches)
2521
{
2622
this.branches = branches;
2723
}
2824

25+
[DispId(-4)]
2926
public IEnumerator GetEnumerator()
3027
{
3128
return branches.GetEnumerator();

RetailCoder.VBE/Interop/FileStatusEntries.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@
1010

1111
namespace Rubberduck.Interop
1212
{
13-
[ComVisible(true)]
14-
[Guid("E7769AE2-7C28-425D-B833-544AD54D0534")]
15-
public interface IFileStatusEntries : IEnumerable { }
16-
1713
[ComVisible(true)]
1814
[Guid("E68A88BB-E15C-40D8-8D18-CAF7637312B5")]
1915
[ProgId("Rubberduck.FileStatusEntries")]
2016
[ClassInterface(ClassInterfaceType.None)]
2117
[System.ComponentModel.Description("Collection of IFileEntries representing the status of the repository files.")]
22-
public class FileStatusEntries : IFileStatusEntries
18+
public class FileStatusEntries : IEnumerable
2319
{
2420
private IEnumerable<IFileStatusEntry> entries;
2521
public FileStatusEntries(IEnumerable<IFileStatusEntry> entries)
2622
{
2723
this.entries = entries;
2824
}
2925

26+
[DispId(-4)]
3027
public IEnumerator GetEnumerator()
3128
{
3229
return entries.GetEnumerator();

RetailCoder.VBE/Interop/GitProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ public GitProvider(VBProject project, IRepository repository)
2727
public GitProvider(VBProject project, IRepository repository, string userName, string passWord)
2828
: base(project, repository, userName, passWord){}
2929

30-
private IBranches branches;
31-
public new IBranches Branches
30+
public new IEnumerable Branches
3231
{
3332
get { return new Branches(base.Branches); }
3433
}
3534

36-
public new IFileStatusEntries Status()
35+
public new IEnumerable Status()
3736
{
3837
return new FileStatusEntries(base.Status());
3938
}

RetailCoder.VBE/Interop/ISourceControlProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -19,7 +20,7 @@ public interface ISourceControlProvider
1920
string CurrentBranch { get; }
2021

2122
[DispId(2)]
22-
IBranches Branches { get; }
23+
IEnumerable Branches { get; }
2324

2425
[DispId(3)]
2526
IRepository Clone(string remotePathOrUrl, string workingDirectory);
@@ -64,6 +65,6 @@ public interface ISourceControlProvider
6465
void RemoveFile(string filePath);
6566

6667
[DispId(17)]
67-
IFileStatusEntries Status();
68+
IEnumerable Status();
6869
}
6970
}

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<Compile Include="Interop\ISourceControlProvider.cs" />
106106
<Compile Include="Interop\SourceControlClassFactory.cs" />
107107
<Compile Include="SourceControl\FileStatus.cs" />
108+
<Compile Include="SourceControl\FileStatusEntry.cs" />
108109
<Compile Include="UI\CodeExplorer\CodeExplorerNavigateArgs.cs" />
109110
<Compile Include="UI\Refactorings\ExtractMethod\ExtractedDeclarationUsage.cs" />
110111
<Compile Include="UI\Refactorings\ExtractMethod\ExtractedParameter.cs" />

RetailCoder.VBE/SourceControl/FileStatus.cs

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,104 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Threading.Tasks;
56
using System.Runtime.InteropServices;
6-
using System.ComponentModel;
77

88
namespace Rubberduck.SourceControl
99
{
10+
//This file was taken from the [Lib2GitSharp project][1] so this enum could be exposed to COM interop.
11+
//Otherwise, this file remains unchanged.
12+
//
13+
//[1]:https://github.com/libgit2/libgit2sharp/
14+
//
15+
//The MIT License
16+
//Copyright (c) LibGit2Sharp contributors
17+
//
18+
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
19+
//to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
20+
//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:
21+
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22+
//
23+
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
//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,
25+
//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.
26+
27+
/// <summary>
28+
/// Calculated status of a filepath in the working directory.
29+
/// </summary>
30+
[Flags]
1031
[ComVisible(true)]
11-
[Guid("577CB2D3-A84B-44FF-94EF-F4FC78363D74")]
12-
public interface IFileStatusEntry
32+
[Guid("4DDA743E-E3A7-440A-A030-92DF616B2C7B")]
33+
public enum FileStatus
1334
{
14-
[DispId(0)]
15-
string FilePath { get; }
35+
/// <summary>
36+
/// The file doesn't exist.
37+
/// </summary>
38+
Nonexistent = (1 << 31),
1639

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-
}
40+
/// <summary>
41+
/// The file hasn't been modified.
42+
/// </summary>
43+
Unaltered = 0, /* GIT_STATUS_CURRENT */
2144

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; }
45+
/// <summary>
46+
/// New file has been added to the Index. It's unknown from the Head.
47+
/// </summary>
48+
Added = (1 << 0), /* GIT_STATUS_INDEX_NEW */
49+
50+
/// <summary>
51+
/// New version of a file has been added to the Index. A previous version exists in the Head.
52+
/// </summary>
53+
Staged = (1 << 1), /* GIT_STATUS_INDEX_MODIFIED */
54+
55+
/// <summary>
56+
/// The deletion of a file has been promoted from the working directory to the Index. A previous version exists in the Head.
57+
/// </summary>
58+
Removed = (1 << 2), /* GIT_STATUS_INDEX_DELETED */
59+
60+
/// <summary>
61+
/// The renaming of a file has been promoted from the working directory to the Index. A previous version exists in the Head.
62+
/// </summary>
63+
RenamedInIndex = (1 << 3), /* GIT_STATUS_INDEX_RENAMED */
64+
65+
/// <summary>
66+
/// A change in type for a file has been promoted from the working directory to the Index. A previous version exists in the Head.
67+
/// </summary>
68+
StagedTypeChange = (1 << 4), /* GIT_STATUS_INDEX_TYPECHANGE */
69+
70+
/// <summary>
71+
/// New file in the working directory, unknown from the Index and the Head.
72+
/// </summary>
73+
Untracked = (1 << 7), /* GIT_STATUS_WT_NEW */
74+
75+
/// <summary>
76+
/// The file has been updated in the working directory. A previous version exists in the Index.
77+
/// </summary>
78+
Modified = (1 << 8), /* GIT_STATUS_WT_MODIFIED */
79+
80+
/// <summary>
81+
/// The file has been deleted from the working directory. A previous version exists in the Index.
82+
/// </summary>
83+
Missing = (1 << 9), /* GIT_STATUS_WT_DELETED */
84+
85+
/// <summary>
86+
/// The file type has been changed in the working directory. A previous version exists in the Index.
87+
/// </summary>
88+
TypeChanged = (1 << 10), /* GIT_STATUS_WT_TYPECHANGE */
89+
90+
/// <summary>
91+
/// The file has been renamed in the working directory. The previous version at the previous name exists in the Index.
92+
/// </summary>
93+
RenamedInWorkDir = (1 << 11), /* GIT_STATUS_WT_RENAMED */
3094

31-
public FileStatusEntry(string filePath, LibGit2Sharp.FileStatus fileStatus)
32-
{
33-
this.FilePath = filePath;
34-
this.FileStatus = fileStatus;
35-
}
95+
/// <summary>
96+
/// The file is unreadable in the working directory.
97+
/// </summary>
98+
Unreadable = (1 << 12), /* GIT_STATUS_WT_UNREADABLE */
3699

37-
public FileStatusEntry(LibGit2Sharp.StatusEntry status)
38-
: this(status.FilePath, status.State) { }
100+
/// <summary>
101+
/// The file is <see cref="Untracked"/> but its name and/or path matches an exclude pattern in a <c>gitignore</c> file.
102+
/// </summary>
103+
Ignored = (1 << 14), /* GIT_STATUS_IGNORED */
39104
}
40105
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
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 FileStatus FileStatus { get; private set; }
30+
31+
private FileStatusEntry(string filePath)
32+
{
33+
this.FilePath = filePath;
34+
}
35+
36+
public FileStatusEntry(string filePath, LibGit2Sharp.FileStatus fileStatus)
37+
:this(filePath)
38+
{
39+
this.FileStatus = (SourceControl.FileStatus)fileStatus;
40+
}
41+
42+
public FileStatusEntry(string filePath, SourceControl.FileStatus fileStatus)
43+
:this(filePath)
44+
{
45+
this.FileStatus = fileStatus;
46+
}
47+
48+
public FileStatusEntry(LibGit2Sharp.StatusEntry status)
49+
: this(status.FilePath, status.State) { }
50+
}
51+
}

0 commit comments

Comments
 (0)