Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ITask<string> Pull(string remote, string branch,
ITask<string> Push(string remote, string branch,
IOutputProcessor<string> processor = null);

ITask<string> Revert(string changeset,
IOutputProcessor<string> processor = null);

ITask<string> Fetch(string remote,
IOutputProcessor<string> processor = null);

Expand Down Expand Up @@ -198,6 +201,12 @@ public ITask<string> Push(string remote, string branch,
.Configure(processManager);
}

public ITask<string> Revert(string changeset, IOutputProcessor<string> processor = null)
{
return new GitRevertTask(changeset, cancellationToken, processor)
.Configure(processManager);
}

public ITask<string> Fetch(string remote,
IOutputProcessor<string> processor = null)
{
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Api/Git/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface IRepository : IEquatable<IRepository>
ITask SetupRemote(string remoteName, string remoteUrl);
ITask Pull();
ITask Push();
ITask Revert(string changeset);
ITask ListLocks();
ITask RequestLock(string file);
ITask ReleaseLock(string file, bool force);
Expand Down
5 changes: 5 additions & 0 deletions src/GitHub.Api/Git/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public ITask Push()
return repositoryManager.Push(CurrentRemote.Value.Name, CurrentBranch);
}

public ITask Revert(string changeset)
{
return repositoryManager.Revert(changeset);
}

public ITask ListLocks()
{
return repositoryManager.ListLocks(false);
Expand Down
7 changes: 7 additions & 0 deletions src/GitHub.Api/Git/RepositoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface IRepositoryManager : IDisposable
ITask Fetch(string remote);
ITask Pull(string remote, string branch);
ITask Push(string remote, string branch);
ITask Revert(string changeset);
ITask RemoteAdd(string remote, string url);
ITask RemoteRemove(string remote);
ITask RemoteChange(string remote, string url);
Expand Down Expand Up @@ -234,6 +235,12 @@ public ITask Push(string remote, string branch)
return HookupHandlers(task);
}

public ITask Revert(string changeset)
{
var task = GitClient.Revert(changeset);
return HookupHandlers(task);
}

public ITask RemoteAdd(string remote, string url)
{
var task = GitClient.RemoteAdd(remote, url);
Expand Down
22 changes: 22 additions & 0 deletions src/GitHub.Api/Git/Tasks/GitRevertTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Threading;

namespace GitHub.Unity
{
class GitRevertTask : ProcessTask<string>
{
private readonly string arguments;

public GitRevertTask(string changeset,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
{
Guard.ArgumentNotNull(changeset, "changeset");

arguments = $"revert --no-edit {changeset}";
}

public override string Name { get { return "git revert"; } }
public override string ProcessArguments { get { return arguments; } }
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
}
}
1 change: 1 addition & 0 deletions src/GitHub.Api/GitHub.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<Compile Include="Git\GitObjectFactory.cs" />
<Compile Include="Git\GitStatusEntry.cs" />
<Compile Include="Git\IGitObjectFactory.cs" />
<Compile Include="Git\Tasks\GitRevertTask.cs" />
<Compile Include="IO\FileSystemHelpers.cs" />
<Compile Include="Application\IApplicationManager.cs" />
<Compile Include="NewTaskSystem\ActionTask.cs" />
Expand Down
30 changes: 30 additions & 0 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,28 @@ private void CullHistory()
EntryHeight + 1, 0, history.Count);
}

private void RevertCommit()
{
var selection = history[selectionIndex];

var dialogTitle = "Revert commit";
var dialogBody = string.Format(@"Are you sure you want to revert the following commit:""{0}""", selection.Summary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these strings need to go into the Localization.resx file. We'll need to do a pass on this, we're accumulating way too many strings all over the place.

Copy link
Contributor Author

@StanleyGoldman StanleyGoldman Jun 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (EditorUtility.DisplayDialog(dialogTitle, dialogBody, "Revert", "Cancel"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these strings (and we already have Localization.Cancel for the cancel buttton)

{
Repository
.Revert(selection.CommitID)
.FinallyInUI((success, e) => {
if (!success)
{
EditorUtility.DisplayDialog(dialogTitle,
"Error reverting commit: " + e.Message, Localization.Cancel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this error message

}
})
.Start();
}
}

private bool HistoryEntry(GitLogEntry entry, LogEntryState state, bool selected)
{
var entryRect = GUILayoutUtility.GetRect(Styles.HistoryEntryHeight, Styles.HistoryEntryHeight);
Expand Down Expand Up @@ -620,6 +642,14 @@ private bool HistoryEntry(GitLogEntry entry, LogEntryState state, bool selected)
GUI.DrawTexture(normalIndicatorRect, Styles.DotIcon);
}
}
else if (Event.current.type == EventType.ContextClick && entryRect.Contains(Event.current.mousePosition))
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("Revert"), false, RevertCommit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string should be in the localization resources file

menu.ShowAsContext();

Event.current.Use();
}
else if (Event.current.type == EventType.MouseDown && entryRect.Contains(Event.current.mousePosition))
{
Event.current.Use();
Expand Down