Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 5218f0d

Browse files
Adding functionality to revert a commit
1 parent 68571ef commit 5218f0d

File tree

7 files changed

+58
-3
lines changed

7 files changed

+58
-3
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ ITask<string> Pull(string remote, string branch,
3232
ITask<string> Push(string remote, string branch,
3333
IOutputProcessor<string> processor = null);
3434

35+
ITask<string> Revert(string changeset,
36+
IOutputProcessor<string> processor = null);
37+
3538
ITask<string> Fetch(string remote,
3639
IOutputProcessor<string> processor = null);
3740

@@ -198,6 +201,12 @@ public ITask<string> Push(string remote, string branch,
198201
.Configure(processManager);
199202
}
200203

204+
public ITask<string> Revert(string changeset, IOutputProcessor<string> processor = null)
205+
{
206+
return new GitRevertTask(changeset, cancellationToken, processor)
207+
.Configure(processManager);
208+
}
209+
201210
public ITask<string> Fetch(string remote,
202211
IOutputProcessor<string> processor = null)
203212
{

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface IRepository : IEquatable<IRepository>
1212
ITask SetupRemote(string remoteName, string remoteUrl);
1313
ITask Pull();
1414
ITask Push();
15+
ITask Revert(string changeset);
1516
ITask ListLocks();
1617
ITask RequestLock(string file);
1718
ITask ReleaseLock(string file, bool force);

src/GitHub.Api/Git/Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public ITask Push()
8888
return repositoryManager.Push(CurrentRemote.Value.Name, CurrentBranch);
8989
}
9090

91+
public ITask Revert(string changeset)
92+
{
93+
return repositoryManager.Revert(changeset);
94+
}
95+
9196
public ITask ListLocks()
9297
{
9398
return repositoryManager.ListLocks(false);

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface IRepositoryManager : IDisposable
3434
ITask Fetch(string remote);
3535
ITask Pull(string remote, string branch);
3636
ITask Push(string remote, string branch);
37+
ITask Revert(string changeset);
3738
ITask RemoteAdd(string remote, string url);
3839
ITask RemoteRemove(string remote);
3940
ITask RemoteChange(string remote, string url);
@@ -220,6 +221,12 @@ public ITask Push(string remote, string branch)
220221
return HookupHandlers(task);
221222
}
222223

224+
public ITask Revert(string changeset)
225+
{
226+
var task = GitClient.Revert(changeset);
227+
return HookupHandlers(task);
228+
}
229+
223230
public ITask RemoteAdd(string remote, string url)
224231
{
225232
var task = GitClient.RemoteAdd(remote, url);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Threading;
2+
3+
namespace GitHub.Unity
4+
{
5+
class GitRevertTask : ProcessTask<string>
6+
{
7+
private readonly string arguments;
8+
9+
public GitRevertTask(string changeset,
10+
CancellationToken token, IOutputProcessor<string> processor = null)
11+
: base(token, processor ?? new SimpleOutputProcessor())
12+
{
13+
Guard.ArgumentNotNull(changeset, "changeset");
14+
15+
arguments = $"revert --no-edit {changeset}";
16+
}
17+
18+
public override string Name { get { return "git revert"; } }
19+
public override string ProcessArguments { get { return arguments; } }
20+
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
21+
}
22+
}

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
<Compile Include="Git\GitObjectFactory.cs" />
116116
<Compile Include="Git\GitStatusEntry.cs" />
117117
<Compile Include="Git\IGitObjectFactory.cs" />
118+
<Compile Include="Git\Tasks\GitRevertTask.cs" />
118119
<Compile Include="IO\FileSystemHelpers.cs" />
119120
<Compile Include="Application\IApplicationManager.cs" />
120121
<Compile Include="NewTaskSystem\ActionTask.cs" />

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,23 @@ private void CullHistory()
550550

551551
private void RevertCommit()
552552
{
553-
var commitSummary = "An awesome commit title";
553+
var selection = history[selectionIndex];
554+
554555
var dialogTitle = "Revert commit";
555-
var dialogBody = "Are you sure you want to revert the following commit:\n" + "\"" + commitSummary + "\"";
556+
var dialogBody = string.Format(@"Are you sure you want to revert the following commit:""{0}""", selection.Summary);
556557

557558
if (EditorUtility.DisplayDialog(dialogTitle, dialogBody, "Revert", "Cancel"))
558559
{
559-
Debug.Log("(Pretend a commit was reverted)");
560+
Repository
561+
.Revert(selection.CommitID)
562+
.FinallyInUI((success, e) => {
563+
if (!success)
564+
{
565+
EditorUtility.DisplayDialog(dialogTitle,
566+
"Error reverting commit: " + e.Message, Localization.Cancel);
567+
}
568+
})
569+
.Start();
560570
}
561571
}
562572

0 commit comments

Comments
 (0)