-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "CandyCoded.GitStatus", | ||
"references": [ | ||
"GUID:478a2357cc57436488a56e564b08d223" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
#if UNITY_EDITOR | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace CandyCoded.GitStatus | ||
{ | ||
|
||
public static class Git | ||
{ | ||
|
||
public static string Branch() | ||
{ | ||
|
||
var process = Process.Start(new ProcessStartInfo | ||
{ | ||
FileName = "/usr/local/bin/git", | ||
Arguments = "rev-parse --abbrev-ref HEAD", | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
CreateNoWindow = true | ||
}); | ||
|
||
return process?.StandardOutput.ReadLine(); | ||
|
||
} | ||
|
||
public static string[] AllChanges() | ||
{ | ||
|
||
var process = Process.Start(new ProcessStartInfo | ||
{ | ||
FileName = "/usr/local/bin/git", | ||
Arguments = "status --short --untracked-files --porcelain", | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
CreateNoWindow = true | ||
}); | ||
|
||
return process?.StandardOutput | ||
.ReadToEnd() | ||
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) | ||
.ToArray(); | ||
|
||
} | ||
|
||
public static string[] ChangedFiles() | ||
{ | ||
|
||
return AllChanges().Except(UntrackedFiles()).ToArray(); | ||
|
||
} | ||
|
||
public static string[] UntrackedFiles() | ||
{ | ||
|
||
return AllChanges().Where(file => file.StartsWith("??")).ToArray(); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
#if UNITY_EDITOR | ||
using System; | ||
using System.Collections; | ||
using UnityEditorInternal; | ||
using UnityEngine; | ||
using Unity.EditorCoroutines.Editor; | ||
using UnityEditor; | ||
|
||
namespace CandyCoded.GitStatus | ||
{ | ||
|
||
public class GitStatusPanel : EditorWindow | ||
{ | ||
|
||
private readonly EditorWaitForSeconds _delayBetweenUpdates = new EditorWaitForSeconds(60); | ||
|
||
private string _branch; | ||
|
||
private string[] _changedFiles; | ||
|
||
private string[] _untrackedFiles; | ||
|
||
private DateTime _lastUpdated; | ||
|
||
private EditorCoroutine _coroutine; | ||
|
||
private bool _isEditorFocused; | ||
|
||
[MenuItem("Window/CandyCoded/Git Status")] | ||
public static void ShowWindow() | ||
{ | ||
|
||
GetWindow(typeof(GitStatusPanel), false, "Git Status", true); | ||
|
||
} | ||
|
||
private void Update() | ||
{ | ||
|
||
if (InternalEditorUtility.isApplicationActive && !_isEditorFocused) | ||
{ | ||
|
||
UpdateData(); | ||
|
||
} | ||
|
||
_isEditorFocused = InternalEditorUtility.isApplicationActive; | ||
|
||
} | ||
|
||
private void OnGUI() | ||
{ | ||
|
||
GUILayout.Label($"Current Branch: {_branch}"); | ||
GUILayout.Label($"Number of Changes: {_changedFiles?.Length}"); | ||
GUILayout.Label($"Untracked Files: {_untrackedFiles?.Length}"); | ||
GUILayout.Label($"Last Updated: {_lastUpdated}"); | ||
|
||
if (GUILayout.Button("Force Update")) | ||
{ | ||
|
||
UpdateData(); | ||
|
||
} | ||
|
||
} | ||
|
||
private void UpdateData() | ||
{ | ||
|
||
_branch = Git.Branch(); | ||
|
||
_changedFiles = Git.ChangedFiles(); | ||
|
||
_untrackedFiles = Git.UntrackedFiles(); | ||
|
||
_lastUpdated = DateTime.Now; | ||
|
||
Repaint(); | ||
|
||
} | ||
|
||
private IEnumerator UpdateCoroutine() | ||
{ | ||
|
||
while (true) | ||
{ | ||
|
||
UpdateData(); | ||
|
||
yield return _delayBetweenUpdates; | ||
|
||
} | ||
|
||
} | ||
|
||
private void OnEnable() | ||
{ | ||
|
||
_coroutine = EditorCoroutineUtility.StartCoroutine(UpdateCoroutine(), this); | ||
|
||
} | ||
|
||
private void OnDisable() | ||
{ | ||
|
||
EditorCoroutineUtility.StopCoroutine(_coroutine); | ||
|
||
_coroutine = null; | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "xyz.candycoded.gitstatus", | ||
"displayName": "GitStatus", | ||
"version": "1.0.0", | ||
"unity": "2019.2", | ||
"unityRelease": "13f1", | ||
"description": "Editor panel that displays the current git status.", | ||
"license": "MIT", | ||
"dependencies": { | ||
"com.unity.editorcoroutines": "0.0.2-preview.1" | ||
}, | ||
"keywords": [ | ||
"unity", | ||
"editor", | ||
"git" | ||
], | ||
"author": { | ||
"name": "Scott Doxey", | ||
"email": "hello@scottdoxey.com", | ||
"homepage": "http://scottdoxey.com/" | ||
}, | ||
"homepage": "https://github.com/CandyCoded/GitStatus", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:CandyCoded/GitStatus.git" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.