Skip to content

Commit 8ec4f12

Browse files
haackedyorah
authored andcommitted
Add IRepository interface
1 parent 8b87c23 commit 8ec4f12

File tree

4 files changed

+118
-13
lines changed

4 files changed

+118
-13
lines changed

LibGit2Sharp/IRepository.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
3+
namespace LibGit2Sharp
4+
{
5+
/// <summary>
6+
/// A Repository is the primary interface into a git repository
7+
/// </summary>
8+
public interface IRepository : IDisposable
9+
{
10+
/// <summary>
11+
/// Shortcut to return the branch pointed to by HEAD
12+
/// </summary>
13+
/// <returns></returns>
14+
Branch Head { get; }
15+
16+
/// <summary>
17+
/// Provides access to the configuration settings for this repository.
18+
/// </summary>
19+
Configuration Config { get; }
20+
21+
/// <summary>
22+
/// Gets the index.
23+
/// </summary>
24+
Index Index { get; }
25+
26+
/// <summary>
27+
/// Lookup and enumerate references in the repository.
28+
/// </summary>
29+
ReferenceCollection Refs { get; }
30+
31+
/// <summary>
32+
/// Lookup and manage remotes in the repository.
33+
/// </summary>
34+
RemoteCollection Remotes { get; }
35+
36+
/// <summary>
37+
/// Lookup and enumerate commits in the repository.
38+
/// Iterating this collection directly starts walking from the HEAD.
39+
/// </summary>
40+
IQueryableCommitLog Commits { get; }
41+
42+
/// <summary>
43+
/// Lookup and enumerate branches in the repository.
44+
/// </summary>
45+
BranchCollection Branches { get; }
46+
47+
/// <summary>
48+
/// Lookup and enumerate tags in the repository.
49+
/// </summary>
50+
TagCollection Tags { get; }
51+
52+
/// <summary>
53+
/// Provides high level information about this repository.
54+
/// </summary>
55+
RepositoryInformation Info { get; }
56+
57+
/// <summary>
58+
/// Provides access to diffing functionalities to show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, or changes between two files on disk.
59+
/// </summary>
60+
Diff Diff {get;}
61+
62+
/// <summary>
63+
/// Checkout the specified branch.
64+
/// </summary>
65+
/// <param name="branch">The branch to checkout.</param>
66+
/// <returns>The branch.</returns>
67+
Branch Checkout(Branch branch);
68+
69+
/// <summary>
70+
/// Checkout the specified branch, reference or SHA.
71+
/// </summary>
72+
/// <param name = "shaOrReferenceName">The sha of the commit, a canonical reference name or the name of the branch to checkout.</param>
73+
/// <returns>The new HEAD.</returns>
74+
Branch Checkout(string shaOrReferenceName);
75+
76+
/// <summary>
77+
/// Try to lookup an object by its <see cref = "ObjectId" /> and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
78+
/// </summary>
79+
/// <param name = "id">The id to lookup.</param>
80+
/// <param name = "type">The kind of GitObject being looked up</param>
81+
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
82+
GitObject Lookup(ObjectId id, GitObjectType type = GitObjectType.Any);
83+
84+
/// <summary>
85+
/// Try to lookup an object by its sha or a reference canonical name and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
86+
/// </summary>
87+
/// <param name = "shaOrReferenceName">The sha or reference canonical name to lookup.</param>
88+
/// <param name = "type">The kind of <see cref = "GitObject" /> being looked up</param>
89+
/// <returns>The <see cref = "GitObject" /> or null if it was not found.</returns>
90+
GitObject Lookup(string shaOrReferenceName, GitObjectType type = GitObjectType.Any);
91+
92+
/// <summary>
93+
/// Stores the content of the <see cref = "Repository.Index" /> as a new <see cref = "Commit" /> into the repository.
94+
/// The tip of the <see cref = "Repository.Head"/> will be used as the parent of this new Commit.
95+
/// Once the commit is created, the <see cref = "Repository.Head"/> will move forward to point at it.
96+
/// </summary>
97+
/// <param name = "message">The description of why a change was made to the repository.</param>
98+
/// <param name = "author">The <see cref = "Signature" /> of who made the change.</param>
99+
/// <param name = "committer">The <see cref = "Signature" /> of who added the change to the repository.</param>
100+
/// <param name = "amendPreviousCommit">True to amend the current <see cref = "Commit"/> pointed at by <see cref = "Repository.Head"/>, false otherwise.</param>
101+
/// <returns>The generated <see cref = "Commit" />.</returns>
102+
Commit Commit(string message, Signature author, Signature committer, bool amendPreviousCommit = false);
103+
}
104+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Compile Include="DetachedHead.cs" />
9797
<Compile Include="Diff.cs" />
9898
<Compile Include="DiffTarget.cs" />
99+
<Compile Include="IRepository.cs" />
99100
<Compile Include="NoteCollection.cs" />
100101
<Compile Include="Note.cs" />
101102
<Compile Include="TreeChanges.cs" />

LibGit2Sharp/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace LibGit2Sharp
1212
/// <summary>
1313
/// A Repository is the primary interface into a git repository
1414
/// </summary>
15-
public class Repository : IDisposable
15+
public class Repository : IRepository
1616
{
1717
private readonly BranchCollection branches;
1818
private readonly CommitLog commits;

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class RepositoryExtensions
1515
/// <param name = "repository">The <see cref = "Repository" /> being looked up.</param>
1616
/// <param name = "shaOrRef">The shaOrRef to lookup.</param>
1717
/// <returns></returns>
18-
public static T Lookup<T>(this Repository repository, string shaOrRef) where T : GitObject
18+
public static T Lookup<T>(this IRepository repository, string shaOrRef) where T : GitObject
1919
{
2020
return (T)repository.Lookup(shaOrRef, GitObject.TypeToTypeMap[typeof(T)]);
2121
}
@@ -27,7 +27,7 @@ public static T Lookup<T>(this Repository repository, string shaOrRef) where T :
2727
/// <param name = "repository">The <see cref = "Repository" /> being looked up.</param>
2828
/// <param name = "id">The id.</param>
2929
/// <returns></returns>
30-
public static T Lookup<T>(this Repository repository, ObjectId id) where T : GitObject
30+
public static T Lookup<T>(this IRepository repository, ObjectId id) where T : GitObject
3131
{
3232
return (T)repository.Lookup(id, GitObject.TypeToTypeMap[typeof(T)]);
3333
}
@@ -37,7 +37,7 @@ public static T Lookup<T>(this Repository repository, ObjectId id) where T : Git
3737
/// </summary>
3838
/// <param name = "repository">The <see cref = "Repository" /> being worked with.</param>
3939
/// <param name = "tagName">The name of the tag to create.</param>
40-
public static Tag ApplyTag(this Repository repository, string tagName)
40+
public static Tag ApplyTag(this IRepository repository, string tagName)
4141
{
4242
return ApplyTag(repository, tagName, repository.Head.CanonicalName);
4343
}
@@ -48,7 +48,7 @@ public static Tag ApplyTag(this Repository repository, string tagName)
4848
/// <param name = "repository">The <see cref = "Repository" /> being worked with.</param>
4949
/// <param name = "tagName">The name of the tag to create.</param>
5050
/// <param name = "target">The canonical reference name or sha which should be pointed at by the Tag.</param>
51-
public static Tag ApplyTag(this Repository repository, string tagName, string target)
51+
public static Tag ApplyTag(this IRepository repository, string tagName, string target)
5252
{
5353
return repository.Tags.Add(tagName, target);
5454
}
@@ -60,7 +60,7 @@ public static Tag ApplyTag(this Repository repository, string tagName, string ta
6060
/// <param name = "tagName">The name of the tag to create.</param>
6161
/// <param name = "tagger">The identity of the creator of this tag.</param>
6262
/// <param name = "message">The annotation message.</param>
63-
public static Tag ApplyTag(this Repository repository, string tagName, Signature tagger, string message)
63+
public static Tag ApplyTag(this IRepository repository, string tagName, Signature tagger, string message)
6464
{
6565
return ApplyTag(repository, tagName, repository.Head.CanonicalName, tagger, message);
6666
}
@@ -73,7 +73,7 @@ public static Tag ApplyTag(this Repository repository, string tagName, Signature
7373
/// <param name = "target">The canonical reference name or sha which should be pointed at by the Tag.</param>
7474
/// <param name = "tagger">The identity of the creator of this tag.</param>
7575
/// <param name = "message">The annotation message.</param>
76-
public static Tag ApplyTag(this Repository repository, string tagName, string target, Signature tagger, string message)
76+
public static Tag ApplyTag(this IRepository repository, string tagName, string target, Signature tagger, string message)
7777
{
7878
return repository.Tags.Add(tagName, target, tagger, message);
7979
}
@@ -83,7 +83,7 @@ public static Tag ApplyTag(this Repository repository, string tagName, string ta
8383
/// </summary>
8484
/// <param name = "repository">The <see cref = "Repository" /> being worked with.</param>
8585
/// <param name = "branchName">The name of the branch to create.</param>
86-
public static Branch CreateBranch(this Repository repository, string branchName)
86+
public static Branch CreateBranch(this IRepository repository, string branchName)
8787
{
8888
return CreateBranch(repository, branchName, repository.Head.CanonicalName);
8989
}
@@ -94,7 +94,7 @@ public static Branch CreateBranch(this Repository repository, string branchName)
9494
/// <param name = "repository">The <see cref = "Repository" /> being worked with.</param>
9595
/// <param name = "branchName">The name of the branch to create.</param>
9696
/// <param name = "target">The commit which should be pointed at by the Branch.</param>
97-
public static Branch CreateBranch(this Repository repository, string branchName, Commit target)
97+
public static Branch CreateBranch(this IRepository repository, string branchName, Commit target)
9898
{
9999
Ensure.ArgumentNotNull(target, "target");
100100
return CreateBranch(repository, branchName, target.Id.Sha);
@@ -106,7 +106,7 @@ public static Branch CreateBranch(this Repository repository, string branchName,
106106
/// <param name = "repository">The <see cref = "Repository" /> being worked with.</param>
107107
/// <param name = "branchName">The name of the branch to create.</param>
108108
/// <param name = "target">The canonical reference name or sha which should be pointed at by the Branch.</param>
109-
public static Branch CreateBranch(this Repository repository, string branchName, string target)
109+
public static Branch CreateBranch(this IRepository repository, string branchName, string target)
110110
{
111111
return repository.Branches.Add(branchName, target);
112112
}
@@ -121,7 +121,7 @@ public static Branch CreateBranch(this Repository repository, string branchName,
121121
/// <param name = "message">The description of why a change was made to the repository.</param>
122122
/// <param name = "amendPreviousCommit">True to amend the current <see cref = "LibGit2Sharp.Commit"/> pointed at by <see cref = "Repository.Head"/>, false otherwise.</param>
123123
/// <returns>The generated <see cref = "LibGit2Sharp.Commit" />.</returns>
124-
public static Commit Commit(this Repository repository, string message, bool amendPreviousCommit = false)
124+
public static Commit Commit(this IRepository repository, string message, bool amendPreviousCommit = false)
125125
{
126126
Signature author = BuildSignatureFromGlobalConfiguration(repository, DateTimeOffset.Now);
127127

@@ -139,14 +139,14 @@ public static Commit Commit(this Repository repository, string message, bool ame
139139
/// <param name = "message">The description of why a change was made to the repository.</param>
140140
/// <param name = "amendPreviousCommit">True to amend the current <see cref = "LibGit2Sharp.Commit"/> pointed at by <see cref = "Repository.Head"/>, false otherwise.</param>
141141
/// <returns>The generated <see cref = "LibGit2Sharp.Commit" />.</returns>
142-
public static Commit Commit(this Repository repository, string message, Signature author, bool amendPreviousCommit = false)
142+
public static Commit Commit(this IRepository repository, string message, Signature author, bool amendPreviousCommit = false)
143143
{
144144
Signature committer = BuildSignatureFromGlobalConfiguration(repository, DateTimeOffset.Now);
145145

146146
return repository.Commit(message, author, committer, amendPreviousCommit);
147147
}
148148

149-
private static Signature BuildSignatureFromGlobalConfiguration(Repository repository, DateTimeOffset now)
149+
private static Signature BuildSignatureFromGlobalConfiguration(IRepository repository, DateTimeOffset now)
150150
{
151151
var name = repository.Config.Get<string>("user.name", null);
152152
var email = repository.Config.Get<string>("user.email", null);

0 commit comments

Comments
 (0)