From 35ca7d7c4537ceda5e38b7b46b4238a55b3ee55d Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 30 Jun 2017 17:28:16 -0400 Subject: [PATCH 1/3] Adding git fetch button --- src/GitHub.Api/Git/IRepository.cs | 1 + src/GitHub.Api/Git/Repository.cs | 5 +++ .../Editor/GitHub.Unity/UI/HistoryView.cs | 35 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index 0dce12a05..f09deeff7 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 ListLocks(); ITask RequestLock(string file); ITask ReleaseLock(string file, bool force); diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 77cfad273..742acbe0d 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 ListLocks() { return repositoryManager.ListLocks(false); diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index c0a2da7c3..0beff7e8d 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; @@ -321,8 +328,19 @@ public void OnEmbeddedGUI() GUILayout.FlexibleSpace(); + GUI.enabled = currentRemote != null; + var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle); + GUI.enabled = true; + if (fetchClicked && + EditorUtility.DisplayDialog(FetchConfirmTitle, + String.Format(FetchConfirmDescription, currentRemote), + FetchConfirmYes, + FetchConfirmCancel) + ) + { + Fetch(); + } - // Pull / Push buttons var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton; GUI.enabled = currentRemote != null; var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle); @@ -708,6 +726,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.Cancel); + } + }) + .Start(); + } + void drawTimelineRectAroundIconRect(Rect parentRect, Rect iconRect) { Color timelineBarColor = new Color(0.51F, 0.51F, 0.51F, 0.2F); From 8f6db8066a8f4eff3f687fc47e71ca74a3f5da63 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 30 Jun 2017 17:29:22 -0400 Subject: [PATCH 2/3] Changing button label --- src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 0beff7e8d..1588f6c15 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -735,7 +735,7 @@ private void Fetch() if (!success) { EditorUtility.DisplayDialog(FetchActionTitle, FetchFailureDescription, - Localization.Cancel); + Localization.Ok); } }) .Start(); From ed2128057c7473adf795d0e5ca8ffd48f67bb80c Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 5 Jul 2017 15:58:38 -0400 Subject: [PATCH 3/3] Removing confirmation for git fetch operation --- .../Assets/Editor/GitHub.Unity/UI/HistoryView.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 003c5c239..a2a30fb26 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -331,12 +331,7 @@ public void OnEmbeddedGUI() GUI.enabled = currentRemote != null; var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle); GUI.enabled = true; - if (fetchClicked && - EditorUtility.DisplayDialog(FetchConfirmTitle, - String.Format(FetchConfirmDescription, currentRemote), - FetchConfirmYes, - FetchConfirmCancel) - ) + if (fetchClicked) { Fetch(); }