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

File History #961

Closed
wants to merge 12 commits into from
6 changes: 3 additions & 3 deletions src/GitHub.Api/Application/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,20 @@ private GitHubUser GetValidatedGitHubUser()
}
}

class GitHubHostMeta
public class GitHubHostMeta
{
public bool VerifiablePasswordAuthentication { get; set; }
public string GithubServicesSha { get; set; }
public string InstalledVersion { get; set; }
}

class GitHubUser
public class GitHubUser
{
public string Name { get; set; }
public string Login { get; set; }
}

class GitHubRepository
public class GitHubRepository
{
public string Name { get; set; }
public string CloneUrl { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Api/Application/IApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitHub.Unity
{
interface IApiClient
public interface IApiClient
{
HostAddress HostAddress { get; }
void CreateRepository(string name, string description, bool isPrivate,
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub.Api/Application/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace GitHub.Unity
{
class Organization
public class Organization
{
public string Name { get; set; }
public string Login { get; set; }
}
}
}
34 changes: 34 additions & 0 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ public interface IGitClient
/// <returns>String output of git command</returns>
ITask<string> DiscardAll(IOutputProcessor<string> processor = null);

/// <summary>
/// Executes at least one `git checkout` command to checkout files at the given changeset
/// </summary>
/// <param name="changeset">The md5 of the changeset</param>
/// <param name="files">The files to check out</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> CheckoutVersion(string changeset, IList<string> files, IOutputProcessor<string> processor = null);

/// <summary>
/// Executes at least one `git reset HEAD` command to remove files from the git index.
/// </summary>
Expand Down Expand Up @@ -250,6 +259,13 @@ public interface IGitClient
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLogEntry"/> output</returns>
ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null);

/// <summary>
/// Executes `git log -- <file>` to get the history of a specific file.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLogEntry"/> output</returns>
ITask<List<GitLogEntry>> LogFile(NPath file, BaseOutputListProcessor<GitLogEntry> processor = null);

/// <summary>
/// Executes `git --version` to get the git version.
/// </summary>
Expand Down Expand Up @@ -341,6 +357,17 @@ public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> process
.Then((success, list) => success ? list : new List<GitLogEntry>());
}

///<inheritdoc/>
public ITask<List<GitLogEntry>> LogFile(NPath file, BaseOutputListProcessor<GitLogEntry> processor = null)
{
return new GitLogTask(file, new GitObjectFactory(environment), cancellationToken, processor)
.Configure(processManager)
.Catch(exception => exception is ProcessException &&
exception.Message.StartsWith("fatal: your current branch") &&
exception.Message.EndsWith("does not have any commits yet"))
.Then((success, list) => success ? list : new List<GitLogEntry>());
}

///<inheritdoc/>
public ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null)
{
Expand Down Expand Up @@ -565,6 +592,13 @@ public ITask<string> DiscardAll(IOutputProcessor<string> processor = null)
.Configure(processManager);
}

///<inheritdoc/>
public ITask<string> CheckoutVersion(string changeset, IList<string> files, IOutputProcessor<string> processor = null)
{
return new GitCheckoutTask(changeset, files, cancellationToken, processor)
.Configure(processManager);
}

///<inheritdoc/>
public ITask<string> Remove(IList<string> files,
IOutputProcessor<string> processor = null)
Expand Down
25 changes: 23 additions & 2 deletions src/GitHub.Api/Git/Tasks/GitCheckoutTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,29 @@ public GitCheckoutTask(CancellationToken token,
arguments = "checkout -- .";
}

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

arguments = "checkout ";
arguments += changeset;
arguments += " -- ";

foreach (var file in files)
{
arguments += " \"" + file.ToNPath().ToString(SlashMode.Forward) + "\"";
}

Message = "Checking out files at rev " + changeset.Substring(0, 7);
}

public override string ProcessArguments { get { return arguments; } }
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
public override string Message { get; set; } = "Checking out branch...";
public override string Message { get; set; } = "Checking out files...";
}
}
}
16 changes: 15 additions & 1 deletion src/GitHub.Api/Git/Tasks/GitLogTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@ namespace GitHub.Unity
class GitLogTask : ProcessTaskWithListOutput<GitLogEntry>
{
private const string TaskName = "git log";
private const string baseArguments = @"-c i18n.logoutputencoding=utf8 -c core.quotepath=false log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status";
private readonly string arguments;

public GitLogTask(IGitObjectFactory gitObjectFactory,
CancellationToken token, BaseOutputListProcessor<GitLogEntry> processor = null)
: base(token, processor ?? new LogEntryOutputProcessor(gitObjectFactory))
{
Name = TaskName;
arguments = baseArguments;
}

public GitLogTask(NPath file,
IGitObjectFactory gitObjectFactory,
CancellationToken token, BaseOutputListProcessor<GitLogEntry> processor = null)
: base(token, processor ?? new LogEntryOutputProcessor(gitObjectFactory))
{
Name = TaskName;
arguments = baseArguments;
arguments += " -- ";
arguments += " \"" + file.ToString(SlashMode.Forward) + "\"";
}

public override string ProcessArguments
{
get { return @"-c i18n.logoutputencoding=utf8 -c core.quotepath=false log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; }
get { return arguments; }
}
public override string Message { get; set; } = "Loading the history...";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ExtensionLoader",
"references": ["../../build/GitHub.UnityShim.dll"],
"precompiledReferences": ["../../build/GitHub.UnityShim.dll"],
"includePlatforms": [
"Editor"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Logging\UnityLogAdapter.cs" />
<Compile Include="EntryPoint.cs" />
<Compile Include="UI\ContextMenu.cs" />
<Compile Include="UI\FileHistoryWindow.cs" />
<Compile Include="UI\GitHubEnterpriseAuthenticationView.cs" />
<Compile Include="UI\GitHubAuthenticationView.cs" />
<Compile Include="UpdateCheck.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Logging\UnityLogAdapter.cs" />
<Compile Include="EntryPoint.cs" />
<Compile Include="UI\ContextMenu.cs" />
<Compile Include="UI\FileHistoryWindow.cs" />
<Compile Include="UI\GitHubAuthenticationView.cs" />
<Compile Include="UI\GitHubEnterpriseAuthenticationView.cs" />
<Compile Include="UpdateCheck.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace GitHub.Unity
{
abstract class BaseWindow : EditorWindow, IView
public abstract class BaseWindow : EditorWindow, IView
{
[NonSerialized] private bool initialized = false;
[NonSerialized] private IUser cachedUser;
Expand Down
36 changes: 36 additions & 0 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ContextMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace GitHub.Unity
{
public class ContextMenu
{
[MenuItem("Assets/Git/History", false)]
private static void GitFileHistory()
{
if (Selection.assetGUIDs != null)
{
int maxWindowsToOpen = 10;
int windowsOpened = 0;
foreach(var guid in Selection.assetGUIDs)
{
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
FileHistoryWindow.OpenWindow(assetPath);
windowsOpened++;
if (windowsOpened >= maxWindowsToOpen)
{
break;
}
}
}
}

[MenuItem("Assets/Git/History", true)]
private static bool GitFileHistoryValidation()
{
return Selection.assetGUIDs != null && Selection.assetGUIDs.Length > 0;
}
}
}
Loading