|
1 | 1 | using System;
|
| 2 | +using System.Collections.Generic; |
2 | 3 | using LibGit2Sharp.Core;
|
3 | 4 | using LibGit2Sharp.Handlers;
|
4 | 5 |
|
@@ -111,6 +112,49 @@ public static Branch CreateBranch(this IRepository repository, string branchName
|
111 | 112 | return repository.Branches.Add(branchName, committish);
|
112 | 113 | }
|
113 | 114 |
|
| 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 | + |
114 | 158 | /// <summary>
|
115 | 159 | /// Stores the content of the <see cref = "Repository.Index" /> as a new <see cref = "LibGit2Sharp.Commit" /> into the repository.
|
116 | 160 | /// The tip of the <see cref = "Repository.Head"/> will be used as the parent of this new Commit.
|
|
0 commit comments