Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 35ca7d7

Browse files
Adding git fetch button
1 parent 98fcacd commit 35ca7d7

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface IRepository : IEquatable<IRepository>
1212
ITask SetupRemote(string remoteName, string remoteUrl);
1313
ITask Pull();
1414
ITask Push();
15+
ITask Fetch();
1516
ITask ListLocks();
1617
ITask RequestLock(string file);
1718
ITask ReleaseLock(string file, bool force);

src/GitHub.Api/Git/Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public ITask Push()
8888
return repositoryManager.Push(CurrentRemote.Value.Name, CurrentBranch);
8989
}
9090

91+
public ITask Fetch()
92+
{
93+
return repositoryManager.Fetch(CurrentRemote.Value.Name);
94+
}
95+
9196
public ITask ListLocks()
9297
{
9398
return repositoryManager.ListLocks(false);

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class HistoryView : Subview
3030
private const string ClearSelectionButton = "×";
3131
private const string NoRepoTitle = "No Git repository found for this project";
3232
private const string NoRepoDescription = "Initialize a Git repository to track changes and collaborate with others.";
33+
private const string FetchActionTitle = "Fetch Changes";
34+
private const string FetchButtonText = "Fetch";
35+
private const string FetchFailureDescription = "Could not fetch changes";
36+
private const string FetchConfirmTitle = "Fetch Changes?";
37+
private const string FetchConfirmDescription = "Would you like to fetch changes from remote '{0}'?";
38+
private const string FetchConfirmYes = "Fetch";
39+
private const string FetchConfirmCancel = "Cancel";
3340
private const int HistoryExtraItemCount = 10;
3441
private const float MaxChangelistHeightRatio = .2f;
3542

@@ -321,8 +328,19 @@ public void OnEmbeddedGUI()
321328

322329
GUILayout.FlexibleSpace();
323330

331+
GUI.enabled = currentRemote != null;
332+
var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
333+
GUI.enabled = true;
334+
if (fetchClicked &&
335+
EditorUtility.DisplayDialog(FetchConfirmTitle,
336+
String.Format(FetchConfirmDescription, currentRemote),
337+
FetchConfirmYes,
338+
FetchConfirmCancel)
339+
)
340+
{
341+
Fetch();
342+
}
324343

325-
// Pull / Push buttons
326344
var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
327345
GUI.enabled = currentRemote != null;
328346
var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);
@@ -708,6 +726,21 @@ private void Push()
708726
.Start();
709727
}
710728

729+
private void Fetch()
730+
{
731+
var remote = Repository.CurrentRemote.HasValue ? Repository.CurrentRemote.Value.Name : String.Empty;
732+
Repository
733+
.Fetch()
734+
.FinallyInUI((success, e) => {
735+
if (!success)
736+
{
737+
EditorUtility.DisplayDialog(FetchActionTitle, FetchFailureDescription,
738+
Localization.Cancel);
739+
}
740+
})
741+
.Start();
742+
}
743+
711744
void drawTimelineRectAroundIconRect(Rect parentRect, Rect iconRect)
712745
{
713746
Color timelineBarColor = new Color(0.51F, 0.51F, 0.51F, 0.2F);

0 commit comments

Comments
 (0)