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

Commit 20d4a95

Browse files
committed
Fix pull button behaviour
We need to track git status data changes in order to allow/disallow a pull, since the filesystem may have uncommited changes at any time
1 parent 64966b8 commit 20d4a95

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class ChangesView : Subview
1818
private const string OneChangedFileLabel = "1 changed file";
1919
private const string NoChangedFilesLabel = "No changed files";
2020

21-
[NonSerialized] private bool currentBranchHasUpdate;
22-
[NonSerialized] private bool currentStatusEntriesHasUpdate;
23-
[NonSerialized] private bool currentLocksHasUpdate;
21+
[SerializeField] private bool currentBranchHasUpdate;
22+
[SerializeField] private bool currentStatusEntriesHasUpdate;
23+
[SerializeField] private bool currentLocksHasUpdate;
2424

2525
[NonSerialized] private GUIContent discardGuiContent;
2626

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ class HistoryView : Subview
308308
private const string CommitDetailsTitle = "Commit details";
309309
private const string ClearSelectionButton = "×";
310310

311-
[NonSerialized] private bool currentLogHasUpdate;
312-
[NonSerialized] private bool currentTrackingStatusHasUpdate;
311+
[SerializeField] private bool currentLogHasUpdate;
312+
[SerializeField] private bool currentTrackingStatusHasUpdate;
313313

314314
[SerializeField] private HistoryControl historyControl;
315315
[SerializeField] private GitLogEntry selectedEntry = GitLogEntry.Default;

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ class Window : BaseWindow
1313
private const string Menu_Window_GitHub = "Window/GitHub";
1414
private const string Menu_Window_GitHub_Command_Line = "Window/GitHub Command Line";
1515

16-
[NonSerialized] private bool currentBranchAndRemoteHasUpdate;
17-
[NonSerialized] private bool currentTrackingStatusHasUpdate;
1816
[NonSerialized] private double notificationClearTime = -1;
1917
[NonSerialized] private double timeSinceLastRotation = -1f;
2018
[NonSerialized] private Spinner spinner;
2119
[NonSerialized] private IProgress progress;
2220
[NonSerialized] private float progressValue;
2321
[NonSerialized] private string progressMessage;
2422

23+
[SerializeField] private bool currentBranchAndRemoteHasUpdate;
24+
[SerializeField] private bool currentTrackingStatusHasUpdate;
25+
[SerializeField] private bool currentStatusEntriesHasUpdate;
2526
[SerializeField] private SubTab changeTab = SubTab.InitProject;
2627
[SerializeField] private SubTab activeTab = SubTab.InitProject;
2728
[SerializeField] private InitProjectView initProjectView = new InitProjectView();
@@ -40,6 +41,7 @@ class Window : BaseWindow
4041
[SerializeField] private GUIContent currentRemoteUrlContent;
4142
[SerializeField] private CacheUpdateEvent lastCurrentBranchAndRemoteChangedEvent;
4243
[SerializeField] private CacheUpdateEvent lastTrackingStatusChangedEvent;
44+
[SerializeField] private CacheUpdateEvent lastStatusEntriesChangedEvent;
4345

4446
[MenuItem(Menu_Window_GitHub)]
4547
public static void Window_GitHub()
@@ -271,13 +273,16 @@ private void MaybeUpdateData()
271273
if (currentTrackingStatusHasUpdate)
272274
{
273275
currentTrackingStatusHasUpdate = false;
274-
275276
statusAhead = Repository.CurrentAhead;
276277
statusBehind = Repository.CurrentBehind;
278+
}
277279

280+
if (currentStatusEntriesHasUpdate)
281+
{
282+
currentStatusEntriesHasUpdate = false;
278283
var currentChanges = Repository.CurrentChanges;
279-
hasItemsToCommit = currentChanges != null
280-
&& currentChanges.Any(entry => entry.Status != GitFileStatus.Ignored && !entry.Staged);
284+
hasItemsToCommit = currentChanges != null &&
285+
currentChanges.Any(entry => entry.Status != GitFileStatus.Ignored && !entry.Staged);
281286
}
282287

283288
if (currentBranchAndRemoteHasUpdate)
@@ -366,6 +371,7 @@ private void AttachHandlers(IRepository repository)
366371
return;
367372
repository.CurrentBranchAndRemoteChanged += RepositoryOnCurrentBranchAndRemoteChanged;
368373
repository.TrackingStatusChanged += RepositoryOnTrackingStatusChanged;
374+
repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
369375
}
370376

371377
private void RepositoryOnCurrentBranchAndRemoteChanged(CacheUpdateEvent cacheUpdateEvent)
@@ -388,6 +394,16 @@ private void RepositoryOnTrackingStatusChanged(CacheUpdateEvent cacheUpdateEvent
388394
}
389395
}
390396

397+
private void RepositoryOnStatusEntriesChanged(CacheUpdateEvent cacheUpdateEvent)
398+
{
399+
if (!lastStatusEntriesChangedEvent.Equals(cacheUpdateEvent))
400+
{
401+
lastStatusEntriesChangedEvent = cacheUpdateEvent;
402+
currentStatusEntriesHasUpdate = true;
403+
Redraw();
404+
}
405+
}
406+
391407
private void OnProgress(IProgress progr)
392408
{
393409
progress = progr;
@@ -399,6 +415,7 @@ private void DetachHandlers(IRepository repository)
399415
return;
400416
repository.CurrentBranchAndRemoteChanged -= RepositoryOnCurrentBranchAndRemoteChanged;
401417
repository.TrackingStatusChanged -= RepositoryOnTrackingStatusChanged;
418+
repository.StatusEntriesChanged -= RepositoryOnStatusEntriesChanged;
402419
}
403420

404421
private void DoHeaderGUI()

0 commit comments

Comments
 (0)