Skip to content

Commit 4930ffb

Browse files
committed
Move reset overloads to extension methods
1 parent 91aad11 commit 4930ffb

File tree

3 files changed

+44
-47
lines changed

3 files changed

+44
-47
lines changed

LibGit2Sharp/IRepository.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,13 @@ public interface IRepository : IDisposable
125125
/// <param name = "commit">The target commit object.</param>
126126
void Reset(ResetOptions resetOptions, Commit commit);
127127

128-
/// <summary>
129-
/// Sets the current <see cref = "Repository.Head" /> to the specified commit and optionally resets the <see cref = "Repository.Index" /> and
130-
/// the content of the working tree to match.
131-
/// </summary>
132-
/// <param name = "resetOptions">Flavor of reset operation to perform.</param>
133-
/// <param name = "committish">A revparse spec for the target commit object.</param>
134-
void Reset(ResetOptions resetOptions, string committish = "HEAD");
135-
136128
/// <summary>
137129
/// Replaces entries in the <see cref="Repository.Index"/> with entries from the specified commit.
138130
/// </summary>
139131
/// <param name = "commit">The target commit object.</param>
140132
/// <param name = "paths">The list of paths (either files or directories) that should be considered.</param>
141133
void Reset(Commit commit, IEnumerable<string> paths = null);
142134

143-
/// <summary>
144-
/// Replaces entries in the <see cref="Repository.Index"/> with entries from the specified commit.
145-
/// </summary>
146-
/// <param name = "committish">A revparse spec for the target commit object.</param>
147-
/// <param name = "paths">The list of paths (either files or directories) that should be considered.</param>
148-
void Reset(string committish = "HEAD", IEnumerable<string> paths = null);
149-
150135
/// <summary>
151136
/// Clean the working tree by removing files that are not under version control.
152137
/// </summary>

LibGit2Sharp/Repository.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -539,20 +539,6 @@ public void Reset(ResetOptions resetOptions, Commit commit)
539539
Proxy.git_reset(handle, commit.Id, resetOptions);
540540
}
541541

542-
/// <summary>
543-
/// Sets the current <see cref = "Head" /> to the specified commit and optionally resets the <see cref = "Index" /> and
544-
/// the content of the working tree to match.
545-
/// </summary>
546-
/// <param name = "resetOptions">Flavor of reset operation to perform.</param>
547-
/// <param name = "committish">A revparse spec for the target commit object.</param>
548-
public void Reset(ResetOptions resetOptions, string committish = "HEAD")
549-
{
550-
Ensure.ArgumentNotNullOrEmptyString(committish, "committish");
551-
552-
Commit commit = LookupCommit(committish);
553-
Reset(resetOptions, commit);
554-
}
555-
556542
/// <summary>
557543
/// Replaces entries in the <see cref="Repository.Index"/> with entries from the specified commit.
558544
/// </summary>
@@ -571,24 +557,6 @@ public void Reset(Commit commit, IEnumerable<string> paths = null)
571557
Index.Reset(changes);
572558
}
573559

574-
/// <summary>
575-
/// Replaces entries in the <see cref="Index"/> with entries from the specified commit.
576-
/// </summary>
577-
/// <param name = "committish">A revparse spec for the target commit object.</param>
578-
/// <param name = "paths">The list of paths (either files or directories) that should be considered.</param>
579-
public void Reset(string committish = "HEAD", IEnumerable<string> paths = null)
580-
{
581-
if (Info.IsBare)
582-
{
583-
throw new BareRepositoryException("Reset is not allowed in a bare repository");
584-
}
585-
586-
Ensure.ArgumentNotNullOrEmptyString(committish, "committish");
587-
588-
Commit commit = LookupCommit(committish);
589-
Reset(commit, paths);
590-
}
591-
592560
/// <summary>
593561
/// Stores the content of the <see cref = "Repository.Index" /> as a new <see cref = "Commit" /> into the repository.
594562
/// The tip of the <see cref = "Repository.Head"/> will be used as the parent of this new Commit.

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using LibGit2Sharp.Core;
34
using LibGit2Sharp.Handlers;
45

@@ -111,6 +112,49 @@ public static Branch CreateBranch(this IRepository repository, string branchName
111112
return repository.Branches.Add(branchName, committish);
112113
}
113114

115+
/// <summary>
116+
/// Sets the current <see cref="Repository.Head"/> /> to the specified commit and optionally resets the <see cref = "Index" /> and
117+
/// the content of the working tree to match.
118+
/// </summary>
119+
/// <param name = "repository">The <see cref = "Repository" /> being worked with.</param>
120+
/// <param name = "resetOptions">Flavor of reset operation to perform.</param>
121+
/// <param name = "committish">A revparse spec for the target commit object.</param>
122+
public static void Reset(this IRepository repository, ResetOptions resetOptions, string committish = "HEAD")
123+
{
124+
Ensure.ArgumentNotNullOrEmptyString(committish, "committish");
125+
126+
Commit commit = LookUpCommit(repository, committish);
127+
128+
repository.Reset(resetOptions, commit);
129+
}
130+
131+
/// <summary>
132+
/// Replaces entries in the <see cref="Index"/> with entries from the specified commit.
133+
/// </summary>
134+
/// <param name = "repository">The <see cref = "Repository" /> being worked with.</param>
135+
/// <param name = "committish">A revparse spec for the target commit object.</param>
136+
/// <param name = "paths">The list of paths (either files or directories) that should be considered.</param>
137+
public static void Reset(this IRepository repository, string committish = "HEAD", IEnumerable<string> paths = null)
138+
{
139+
if (repository.Info.IsBare)
140+
{
141+
throw new BareRepositoryException("Reset is not allowed in a bare repository");
142+
}
143+
144+
Ensure.ArgumentNotNullOrEmptyString(committish, "committish");
145+
146+
Commit commit = LookUpCommit(repository, committish);
147+
148+
repository.Reset(commit, paths);
149+
}
150+
151+
private static Commit LookUpCommit(IRepository repository, string committish)
152+
{
153+
GitObject obj = repository.Lookup(committish);
154+
Ensure.GitObjectIsNotNull(obj, committish);
155+
return obj.DereferenceToCommit(true);
156+
}
157+
114158
/// <summary>
115159
/// Stores the content of the <see cref = "Repository.Index" /> as a new <see cref = "LibGit2Sharp.Commit" /> into the repository.
116160
/// The tip of the <see cref = "Repository.Head"/> will be used as the parent of this new Commit.

0 commit comments

Comments
 (0)