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

Commit ceabe35

Browse files
Merge pull request #804 from github-for-unity/enhancements/showing-diffs
Adding the ability to see diffs of files and folders using the configured diff viewer
2 parents 862f680 + 4ff2a3c commit ceabe35

File tree

20 files changed

+372
-94
lines changed

20 files changed

+372
-94
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
@@ -40,6 +40,7 @@ public interface IGitClient
4040
ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = null);
4141
ITask<GitCountObjects> CountObjects(IOutputProcessor<GitCountObjects> processor = null);
4242
ITask<GitUser> SetConfigNameAndEmail(string username, string email);
43+
ITask<string> GetHead(IOutputProcessor<string> processor = null);
4344
}
4445

4546
class GitClient : IGitClient
@@ -310,6 +311,12 @@ public ITask<string> Unlock(NPath file, bool force,
310311
.Configure(processManager);
311312
}
312313

314+
public ITask<string> GetHead(IOutputProcessor<string> processor = null)
315+
{
316+
return new FirstNonNullLineProcessTask(cancellationToken, "rev-parse --short HEAD") { Name = "Getting current head..." }
317+
.Configure(processManager);
318+
}
319+
313320
protected static ILogging Logger { get; } = LogHelper.GetLogger<GitClient>();
314321
}
315322

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().RunSynchronously();
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: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ public interface IFileSystem
2323
IEnumerable<string> GetDirectories(string path);
2424
IEnumerable<string> GetDirectories(string path, string pattern);
2525
IEnumerable<string> GetDirectories(string path, string pattern, SearchOption searchOption);
26-
string GetDirectoryName(string path);
2726
string GetFileNameWithoutExtension(string fileName);
2827
IEnumerable<string> GetFiles(string path);
2928
IEnumerable<string> GetFiles(string path, string pattern);
3029
IEnumerable<string> GetFiles(string path, string pattern, SearchOption searchOption);
3130
string GetFullPath(string path);
32-
string GetParentDirectory(string path);
3331
string GetRandomFileName();
3432
string GetTempPath();
3533
Stream OpenRead(string path);
@@ -46,6 +44,7 @@ public interface IFileSystem
4644
void WriteLines(string path, string[] contents);
4745

4846
char DirectorySeparatorChar { get; }
47+
string GetProcessDirectory();
4948
}
5049

5150

@@ -102,11 +101,6 @@ public string GetFullPath(string path)
102101
return Path.GetFullPath(path);
103102
}
104103

105-
public string GetDirectoryName(string path)
106-
{
107-
return Path.GetDirectoryName(path);
108-
}
109-
110104
public bool DirectoryExists(string path)
111105
{
112106
return Directory.Exists(path);
@@ -118,11 +112,6 @@ public bool ExistingPathIsDirectory(string path)
118112
return (attr & FileAttributes.Directory) == FileAttributes.Directory;
119113
}
120114

121-
public string GetParentDirectory(string path)
122-
{
123-
return Directory.GetParent(path).FullName;
124-
}
125-
126115
public IEnumerable<string> GetDirectories(string path, string pattern)
127116
{
128117
return Directory.GetDirectories(path, pattern);
@@ -163,7 +152,7 @@ public IEnumerable<string> GetFiles(string path, string pattern, SearchOption se
163152
yield break;
164153

165154
#if ENABLE_MONO
166-
if (NPath.IsLinux)
155+
if (NPath.IsUnix)
167156
{
168157
try
169158
{
@@ -177,7 +166,7 @@ public IEnumerable<string> GetFiles(string path, string pattern, SearchOption se
177166
{
178167
var realdir = dir;
179168
#if ENABLE_MONO
180-
if (NPath.IsLinux)
169+
if (NPath.IsUnix)
181170
{
182171
try
183172
{
@@ -242,6 +231,11 @@ public string GetCurrentDirectory()
242231
return Directory.GetCurrentDirectory();
243232
}
244233

234+
public string GetProcessDirectory()
235+
{
236+
return Directory.GetCurrentDirectory();
237+
}
238+
245239
public void WriteAllText(string path, string contents)
246240
{
247241
File.WriteAllText(path, contents);

0 commit comments

Comments
 (0)