Skip to content

Commit

Permalink
Merge pull request #888 from github-for-unity/public-git-client
Browse files Browse the repository at this point in the history
Public Git Client API
  • Loading branch information
StanleyGoldman authored Aug 28, 2018
2 parents d2f898e + fa83edf commit 5833fbb
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/using/quick-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ These documents contain more details on how to use the GitHub for Unity plugin:
- **[Managing Branches](https://github.com/github-for-unity/Unity/blob/master/docs/using/managing-branches.md)**
- **[Locking Files](https://github.com/github-for-unity/Unity/blob/master/docs/using/locking-files.md)**
- **[Working with Changes](https://github.com/github-for-unity/Unity/blob/master/docs/using/working-with-changes.md)**
- **[Using the Api](https://github.com/github-for-unity/Unity/blob/master/docs/using/using-the-api.md)**

## Table of Contents

Expand Down
75 changes: 75 additions & 0 deletions docs/using/using-the-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Using the API

GitHub for Unity provides access to a git client to help users create their own tools to assist in their workflow.

Users can separate the user interface from the API by removing `GitHub.Unity.dll`. All other libraries are required by the API.

## Creating an instance of `GitClient`
```cs
var defaultEnvironment = new DefaultEnvironment();
defaultEnvironment.Initialize(null, NPath.Default, NPath.Default, NPath.Default, Application.dataPath.ToNPath());

var processEnvironment = new ProcessEnvironment(defaultEnvironment);
var processManager = new ProcessManager(defaultEnvironment, processEnvironment, TaskManager.Instance.Token);

var gitClient = new GitClient(defaultEnvironment, processManager, TaskManager.Instance.Token);
```

## Full Example
This example creates a window that has a single button which commits all changes.
```cs
using System;
using System.Globalization;
using GitHub.Unity;
using UnityEditor;
using UnityEngine;

public class CustomGitEditor : EditorWindow
{
[MenuItem("Window/Custom Git")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(CustomGitEditor));
}

[NonSerialized] private GitClient gitClient;

public void OnEnable()
{
InitGitClient();
}

private void InitGitClient()
{
if (gitClient != null) return;

Debug.Log("Init GitClient");

var defaultEnvironment = new DefaultEnvironment();
defaultEnvironment.Initialize(null, NPath.Default, NPath.Default,
NPath.Default, Application.dataPath.ToNPath());

var processEnvironment = new ProcessEnvironment(defaultEnvironment);
var processManager = new ProcessManager(defaultEnvironment, processEnvironment, TaskManager.Instance.Token);

gitClient = new GitClient(defaultEnvironment, processManager, TaskManager.Instance.Token);
}

void OnGUI()
{
GUILayout.Label("Custom Git Window", EditorStyles.boldLabel);

if (GUILayout.Button("Commit Stuff"))
{
var message = DateTime.Now.ToString(CultureInfo.InvariantCulture);
var body = string.Empty;

gitClient.AddAll()
.Then(gitClient.Commit(message, body))
.Start();
}
}
}
```


Loading

0 comments on commit 5833fbb

Please sign in to comment.