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

Commit 8629a70

Browse files
Merge pull request #74 from github-for-unity/features/git-fetch-button
Adding git fetch button
2 parents e659480 + d380ace commit 8629a70

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-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 Revert(string changeset);
1617
ITask ListLocks();
1718
ITask RequestLock(string file);

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 Revert(string changeset)
9297
{
9398
return repositoryManager.Revert(changeset);

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

Lines changed: 29 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

@@ -316,8 +323,14 @@ public void OnEmbeddedGUI()
316323

317324
GUILayout.FlexibleSpace();
318325

326+
GUI.enabled = currentRemote != null;
327+
var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
328+
GUI.enabled = true;
329+
if (fetchClicked)
330+
{
331+
Fetch();
332+
}
319333

320-
// Pull / Push buttons
321334
var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
322335
GUI.enabled = currentRemote != null;
323336
var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);
@@ -733,6 +746,21 @@ private void Push()
733746
.Start();
734747
}
735748

749+
private void Fetch()
750+
{
751+
var remote = Repository.CurrentRemote.HasValue ? Repository.CurrentRemote.Value.Name : String.Empty;
752+
Repository
753+
.Fetch()
754+
.FinallyInUI((success, e) => {
755+
if (!success)
756+
{
757+
EditorUtility.DisplayDialog(FetchActionTitle, FetchFailureDescription,
758+
Localization.Ok);
759+
}
760+
})
761+
.Start();
762+
}
763+
736764
void drawTimelineRectAroundIconRect(Rect parentRect, Rect iconRect)
737765
{
738766
Color timelineBarColor = new Color(0.51F, 0.51F, 0.51F, 0.2F);

0 commit comments

Comments
 (0)