diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index b39052e03..f37426251 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -12,6 +12,7 @@ interface IRepository : IEquatable ITask SetupRemote(string remoteName, string remoteUrl); ITask Pull(); ITask Push(); + ITask Fetch(); ITask Revert(string changeset); ITask ListLocks(); ITask RequestLock(string file); diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 03e1851f4..382106c31 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -88,6 +88,11 @@ public ITask Push() return repositoryManager.Push(CurrentRemote.Value.Name, CurrentBranch); } + public ITask Fetch() + { + return repositoryManager.Fetch(CurrentRemote.Value.Name); + } + public ITask Revert(string changeset) { return repositoryManager.Revert(changeset); diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 57d801d60..cbac11cce 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -30,6 +30,13 @@ class HistoryView : Subview private const string ClearSelectionButton = "×"; private const string NoRepoTitle = "No Git repository found for this project"; private const string NoRepoDescription = "Initialize a Git repository to track changes and collaborate with others."; + private const string FetchActionTitle = "Fetch Changes"; + private const string FetchButtonText = "Fetch"; + private const string FetchFailureDescription = "Could not fetch changes"; + private const string FetchConfirmTitle = "Fetch Changes?"; + private const string FetchConfirmDescription = "Would you like to fetch changes from remote '{0}'?"; + private const string FetchConfirmYes = "Fetch"; + private const string FetchConfirmCancel = "Cancel"; private const int HistoryExtraItemCount = 10; private const float MaxChangelistHeightRatio = .2f; @@ -316,8 +323,14 @@ public void OnEmbeddedGUI() GUILayout.FlexibleSpace(); + GUI.enabled = currentRemote != null; + var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle); + GUI.enabled = true; + if (fetchClicked) + { + Fetch(); + } - // Pull / Push buttons var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton; GUI.enabled = currentRemote != null; var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle); @@ -733,6 +746,21 @@ private void Push() .Start(); } + private void Fetch() + { + var remote = Repository.CurrentRemote.HasValue ? Repository.CurrentRemote.Value.Name : String.Empty; + Repository + .Fetch() + .FinallyInUI((success, e) => { + if (!success) + { + EditorUtility.DisplayDialog(FetchActionTitle, FetchFailureDescription, + Localization.Ok); + } + }) + .Start(); + } + void drawTimelineRectAroundIconRect(Rect parentRect, Rect iconRect) { Color timelineBarColor = new Color(0.51F, 0.51F, 0.51F, 0.2F);