Skip to content

Commit

Permalink
Merge pull request rubberduck-vba#300 from retailcoder/sourcecontrol
Browse files Browse the repository at this point in the history
Sourcecontrol - Improved API & Documentation
  • Loading branch information
rubberduck203 committed Mar 8, 2015
2 parents 3dfbee3 + e7d5cdd commit 3c3f1ec
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
20 changes: 20 additions & 0 deletions RetailCoder.VBE/Interop/ISourceControlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Rubberduck.SourceControl;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace Rubberduck.Interop
{
Expand All @@ -23,48 +24,67 @@ public interface ISourceControlProvider
IEnumerable Branches { get; }

[DispId(3)]
[Description("Clones a remote repository to the local file system.")]
IRepository Clone(string remotePathOrUrl, string workingDirectory);

[DispId(4)]
[Description("Creates a new repository in/from the specified directory.")]
IRepository Init(string directory, bool bare = false);

[DispId(5)]
[Description("Creates a new repository and sets the CurrentRepository property from the VBProject passed to the ISourceControlProvider upon creation.")]
IRepository InitVBAProject(string directory);

[DispId(6)]
[Description("Pushes commits in the CurrentBranch of the Local repo to the Remote.")]
void Push();

[DispId(7)]
[Description("Fetches the specified remote for tracking.\n If argument is not supplied, returns a default remote defined by implementation.")]
void Fetch([Optional] string remoteName);

[DispId(8)]
[Description("Fetches the currently tracking remote and merges it into the CurrentBranch.")]
void Pull();

[DispId(9)]
[Description("Stages all modified files and commits to CurrentBranch.")]
void Commit(string message);

[DispId(10)]
[Description("Merges the source branch into the desitnation.")]
void Merge(string sourceBranch, string destinationBranch);

[DispId(11)]
[Description("Checks out the target branch.")]
void Checkout(string branch);

[DispId(12)]
[Description("Creates and checks out a new branch.")]
void CreateBranch(string branch);

[DispId(18)]
[Description("Deletes the specified branch from the local repository.")]
void DeleteBranch(string branch);

[DispId(13)]
[Description("Undoes uncommitted changes to a particular file.")]
void Undo(string filePath);

[DispId(14)]
[Description("Reverts entire branch to the last commit.")]
void Revert();

[DispId(15)]
[Description("Adds untracked file to repository.")]
void AddFile(string filePath);

[DispId(16)]
[Description("Removes file from tracking.")]
void RemoveFile(string filePath);

[DispId(17)]
[Description("Returns a collection of file status entries.\n Semantically the same as calling $git status.")]
IEnumerable Status();
}
}
9 changes: 7 additions & 2 deletions RetailCoder.VBE/Interop/SourceControlClassFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface _ISourceControlClassFactory
ISourceControlProvider CreateGitProvider(VBProject project, [Optional] IRepository repository, [Optional] string userName, [Optional] string passWord);

[DispId(2)]
IRepository CreateRepository(string name, string localDirectory, string remotePathOrUrl);
IRepository CreateRepository(string name, string localDirectory, [Optional] string remotePathOrUrl);
}

[ComVisible(true)]
Expand Down Expand Up @@ -44,8 +44,13 @@ public ISourceControlProvider CreateGitProvider(VBProject project, [Optional] IR
}

[Description("Returns new instance of repository struct.")]
public IRepository CreateRepository(string name, string localDirectory, string remotePathOrUrl)
public IRepository CreateRepository(string name, string localDirectory, [Optional] string remotePathOrUrl)
{
if (remotePathOrUrl == null)
{
remotePathOrUrl = string.Empty;
}

return new Repository(name, localDirectory, remotePathOrUrl);
}
}
Expand Down
15 changes: 15 additions & 0 deletions RetailCoder.VBE/SourceControl/GitProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ public override void Undo(string filePath)
}
}

public override void DeleteBranch(string branch)
{
try
{
if (repo.Branches.Any(b => b.Name == branch && !b.IsRemote))
{
repo.Branches.Remove(branch);
}
}
catch(LibGit2SharpException ex)
{
throw new SourceControlException("Branch deletion failed.", ex);
}
}

private Signature GetSignature()
{
return this.repo.Config.BuildSignature(DateTimeOffset.Now);
Expand Down
18 changes: 12 additions & 6 deletions RetailCoder.VBE/SourceControl/ISourceControlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface ISourceControlProvider
/// Fetches the specified remote for tracking.
/// If argument is not supplied, returns a default remote defined by implementation.
/// </summary>
/// <param name="remoteName"></param>
/// <param name="remoteName">Name of the remote to be fetched.</param>
void Fetch([Optional] string remoteName);

/// <summary>
Expand All @@ -53,28 +53,34 @@ public interface ISourceControlProvider
/// <summary>
/// Stages all modified files and commits to CurrentBranch.
/// </summary>
/// <param name="message"></param>
/// <param name="message">Commit message.</param>
void Commit(string message);

/// <summary>
/// Merges the source branch into the desitnation.
/// </summary>
/// <param name="sourceBranch"></param>
/// <param name="destinationBranch"></param>
/// <param name="sourceBranch">Name of the source branch.</param>
/// <param name="destinationBranch">Name of the target branch.</param>
void Merge(string sourceBranch, string destinationBranch);

/// <summary>
/// Checks out the target branch.
/// </summary>
/// <param name="branch"></param>
/// <param name="branch">Name of the branch to be checked out.</param>
void Checkout(string branch);

/// <summary>
/// Creates and checks out a new branch.
/// </summary>
/// <param name="branch"></param>
/// <param name="branch">Name of the branch to be created.</param>
void CreateBranch(string branch);

/// <summary>
/// Deletes the specified branch from the local repository.
/// </summary>
/// <param name="branch">Name of the branch to be deleted.</param>
void DeleteBranch(string branch);

/// <summary>
/// Undoes uncommitted changes to a particular file.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions RetailCoder.VBE/SourceControl/SourceControlProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public SourceControlProviderBase(VBProject project, IRepository repository)
public abstract void AddFile(string filePath);
public abstract void RemoveFile(string filePath);
public abstract void CreateBranch(string branch);
public abstract void DeleteBranch(string branch);
public abstract IRepository Init(string directory, bool bare = false);

public virtual IRepository InitVBAProject(string directory)
Expand Down

0 comments on commit 3c3f1ec

Please sign in to comment.