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

Commit a1ed765

Browse files
committed
Adding the ability to see diffs of files and folders using the configured diff viewer
1 parent 0aa40cb commit a1ed765

File tree

19 files changed

+211
-47
lines changed

19 files changed

+211
-47
lines changed

common/properties.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<BuildType Condition="Exists('$(SolutionDir)script\src\MetricsService.cs')">Internal</BuildType>
66
<BuildDefs Condition="Exists('$(SolutionDir)script\src\MetricsService.cs')">ENABLE_METRICS</BuildDefs>
7+
<BuildDefs>ENABLE_MONO</BuildDefs>
78

89
<UnityDir Condition="$(UnityDir) == '' and Exists('$(SolutionDir)\script\lib\Managed\UnityEditor.dll')">$(SolutionDir)script\lib\</UnityDir>
910
<UnityDir Condition="$(UnityDir) == '' and Exists('$(SolutionDir)\lib\Managed\UnityEditor.dll')">$(SolutionDir)lib\</UnityDir>

src/GitHub.Api/Cache/CacheInterfaces.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public interface IRepositoryInfoCacheData
102102
GitBranch? CurrentGitBranch { get; }
103103
ConfigRemote? CurrentConfigRemote { get; }
104104
ConfigBranch? CurrentConfigBranch { get; }
105+
string CurrentHead { get; }
105106
}
106107

107108
public interface IRepositoryInfoCache : IManagedCache, IRepositoryInfoCacheData, ICanUpdate<IRepositoryInfoCacheData>

src/GitHub.Api/Cache/CachingClasses.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ sealed class RepositoryInfoCacheData : IRepositoryInfoCacheData
1414
public GitBranch? CurrentGitBranch { get; set; }
1515
public ConfigRemote? CurrentConfigRemote { get; set; }
1616
public ConfigBranch? CurrentConfigBranch { get; set; }
17+
public string CurrentHead { get; set; }
1718
}
1819
}

src/GitHub.Api/Git/GitClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public interface IGitClient
3939
ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null);
4040
ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = null);
4141
ITask<GitUser> SetConfigNameAndEmail(string username, string email);
42+
ITask<string> GetHead(IOutputProcessor<string> processor = null);
4243
}
4344

4445
class GitClient : IGitClient
@@ -303,6 +304,12 @@ public ITask<string> Unlock(NPath file, bool force,
303304
.Configure(processManager);
304305
}
305306

307+
public ITask<string> GetHead(IOutputProcessor<string> processor = null)
308+
{
309+
return new FirstNonNullLineProcessTask(cancellationToken, "rev-parse --short HEAD") { Name = "Getting current head..." }
310+
.Configure(processManager);
311+
}
312+
306313
protected static ILogging Logger { get; } = LogHelper.GetLogger<GitClient>();
307314
}
308315

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
6060
string CurrentBranchName { get; }
6161
List<GitLogEntry> CurrentLog { get; }
6262
bool IsBusy { get; }
63+
string CurrentHead { get; }
6364

6465
event Action<CacheUpdateEvent> LogChanged;
6566
event Action<CacheUpdateEvent> TrackingStatusChanged;

src/GitHub.Api/Git/Repository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private void CacheHasBeenInvalidated(CacheType cacheType)
238238
}
239239
}
240240

241-
private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, ConfigRemote? remote)
241+
private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, ConfigRemote? remote, string head)
242242
{
243243
taskManager.RunInUI(() =>
244244
{
@@ -247,6 +247,7 @@ private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, Confi
247247
data.CurrentGitBranch = branch.HasValue ? (GitBranch?)GetLocalGitBranch(branch.Value.name, branch.Value) : null;
248248
data.CurrentConfigRemote = remote;
249249
data.CurrentGitRemote = remote.HasValue ? (GitRemote?)GetGitRemote(remote.Value) : null;
250+
data.CurrentHead = head;
250251
name = null;
251252
cloneUrl = null;
252253
cacheContainer.RepositoryInfoCache.UpdateData(data);
@@ -347,6 +348,7 @@ public void Dispose()
347348
public GitRemote? CurrentRemote => cacheContainer.RepositoryInfoCache.CurrentGitRemote;
348349
public List<GitLogEntry> CurrentLog => cacheContainer.GitLogCache.Log;
349350
public List<GitLock> CurrentLocks => cacheContainer.GitLocksCache.GitLocks;
351+
public string CurrentHead => cacheContainer.RepositoryInfoCache.CurrentHead;
350352

351353
public UriString CloneUrl
352354
{

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GitHub.Unity
99
public interface IRepositoryManager : IDisposable
1010
{
1111
event Action<bool> IsBusyChanged;
12-
event Action<ConfigBranch?, ConfigRemote?> CurrentBranchUpdated;
12+
event Action<ConfigBranch?, ConfigRemote?, string> CurrentBranchUpdated;
1313
event Action<GitStatus> GitStatusUpdated;
1414
event Action<List<GitLock>> GitLocksUpdated;
1515
event Action<List<GitLogEntry>> GitLogUpdated;
@@ -106,7 +106,7 @@ class RepositoryManager : IRepositoryManager
106106

107107
private bool isBusy;
108108

109-
public event Action<ConfigBranch?, ConfigRemote?> CurrentBranchUpdated;
109+
public event Action<ConfigBranch?, ConfigRemote?, string> CurrentBranchUpdated;
110110
public event Action<bool> IsBusyChanged;
111111
public event Action<GitStatus> GitStatusUpdated;
112112
public event Action<GitAheadBehindStatus> GitAheadBehindStatusUpdated;
@@ -394,9 +394,10 @@ public ITask UpdateRepositoryInfo()
394394
ConfigBranch? branch;
395395
ConfigRemote? remote;
396396
GetCurrentBranchAndRemote(out branch, out remote);
397-
CurrentBranchUpdated?.Invoke(branch, remote);
397+
var currentHead = GitClient.GetHead().RunWithReturn(true);
398+
CurrentBranchUpdated?.Invoke(branch, remote, currentHead);
398399
})
399-
{ Message = "Updating repository info..." };;
400+
{ Message = "Updating repository info..." };
400401
return HookupHandlers(task, false);
401402
}
402403

src/GitHub.Api/IO/FileSystem.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ public interface IFileSystem
4646
void WriteLines(string path, string[] contents);
4747

4848
char DirectorySeparatorChar { get; }
49+
string GetProcessDirectory();
4950
}
5051

5152

5253
public class FileSystem : IFileSystem
5354
{
5455
private string currentDirectory;
56+
private string processDirectory;
5557

5658
public FileSystem()
5759
{ }
@@ -62,7 +64,7 @@ public FileSystem()
6264
/// <param name="directory">Current directory</param>
6365
public FileSystem(string directory)
6466
{
65-
currentDirectory = directory;
67+
processDirectory = currentDirectory = directory;
6668
}
6769

6870
public void SetCurrentDirectory(string directory)
@@ -163,7 +165,7 @@ public IEnumerable<string> GetFiles(string path, string pattern, SearchOption se
163165
yield break;
164166

165167
#if ENABLE_MONO
166-
if (NPath.IsLinux)
168+
if (NPath.IsUnix)
167169
{
168170
try
169171
{
@@ -177,7 +179,7 @@ public IEnumerable<string> GetFiles(string path, string pattern, SearchOption se
177179
{
178180
var realdir = dir;
179181
#if ENABLE_MONO
180-
if (NPath.IsLinux)
182+
if (NPath.IsUnix)
181183
{
182184
try
183185
{
@@ -242,6 +244,11 @@ public string GetCurrentDirectory()
242244
return Directory.GetCurrentDirectory();
243245
}
244246

247+
public string GetProcessDirectory()
248+
{
249+
return Directory.GetCurrentDirectory();
250+
}
251+
245252
public void WriteAllText(string path, string contents)
246253
{
247254
File.WriteAllText(path, contents);

0 commit comments

Comments
 (0)