Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
neogeek committed Nov 30, 2019
0 parents commit f3ce832
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CandyCoded.GitStatus.asmdef
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": []
}
7 changes: 7 additions & 0 deletions CandyCoded.GitStatus.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Scripts/CustomEditor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Scripts/CustomEditor/Git.cs
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
11 changes: 11 additions & 0 deletions Scripts/CustomEditor/Git.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions Scripts/CustomEditor/GitStatusPanel.cs
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
11 changes: 11 additions & 0 deletions Scripts/CustomEditor/GitStatusPanel.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions package.json
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"
}
}
3 changes: 3 additions & 0 deletions package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f3ce832

Please sign in to comment.