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

Commit 5c5b338

Browse files
author
Andreia Gaita
authored
Merge branch 'master' into fixes/changes-tree-ordering
2 parents b6a74c5 + c52ba0a commit 5c5b338

File tree

6 files changed

+39
-15
lines changed

6 files changed

+39
-15
lines changed

src/GitHub.Api/Git/GitBranch.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public struct GitBranch
1010
public string name;
1111
public string tracking;
1212

13-
public GitBranch(string name, string tracking)
13+
public GitBranch(string name, string tracking = null)
1414
{
1515
Guard.ArgumentNotNullOrWhiteSpace(name, "name");
1616

1717
this.name = name;
18-
this.tracking = tracking;
18+
this.tracking = tracking ?? string.Empty;
1919
}
2020

2121
public override int GetHashCode()
@@ -64,7 +64,7 @@ public bool Equals(GitBranch other)
6464

6565
public override string ToString()
6666
{
67-
return $"{Name} Tracking? {Tracking}";
67+
return $"{Name} Tracking? {Tracking ?? "[NULL]"}";
6868
}
6969
}
70-
}
70+
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, Confi
247247
{
248248
var data = new RepositoryInfoCacheData();
249249
data.CurrentConfigBranch = branch;
250-
data.CurrentGitBranch = branch.HasValue ? (GitBranch?)GetLocalGitBranch(branch.Value.name, branch.Value) : null;
250+
data.CurrentGitBranch = branch.HasValue ? (GitBranch?)GetLocalGitBranch(branch.Value) : null;
251251
data.CurrentConfigRemote = remote;
252252
data.CurrentGitRemote = remote.HasValue ? (GitRemote?)GetGitRemote(remote.Value) : null;
253253
data.CurrentHead = head;
@@ -303,15 +303,15 @@ private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigR
303303
private void RepositoryManagerOnLocalBranchesUpdated(Dictionary<string, ConfigBranch> localConfigBranchDictionary)
304304
{
305305
taskManager.RunInUI(() => {
306-
var gitLocalBranches = localConfigBranchDictionary.Values.Select(x => GetLocalGitBranch(CurrentBranchName, x)).ToArray();
306+
var gitLocalBranches = localConfigBranchDictionary.Values.Select(x => GetLocalGitBranch(x)).ToArray();
307307
cacheContainer.BranchCache.SetLocals(localConfigBranchDictionary, gitLocalBranches);
308308
});
309309
}
310310

311-
private static GitBranch GetLocalGitBranch(string currentBranchName, ConfigBranch x)
311+
private static GitBranch GetLocalGitBranch(ConfigBranch x)
312312
{
313313
var branchName = x.Name;
314-
var trackingName = x.IsTracking ? x.Remote.Value.Name + "/" + branchName : "[None]";
314+
var trackingName = x.IsTracking ? x.Remote.Value.Name + "/" + branchName : null;
315315
return new GitBranch(branchName, trackingName);
316316
}
317317

src/GitHub.Api/OutputProcessors/BranchListOutputProcessor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public override void LineReceived(string line)
3737
if (tracking)
3838
{
3939
trackingName = proc.ReadChunk('[', ']');
40+
var indexOf = trackingName.IndexOf(':');
41+
if (indexOf != -1)
42+
{
43+
trackingName = trackingName.Substring(0, indexOf);
44+
}
4045
}
4146

4247
var branch = new GitBranch(name, trackingName);

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Window : BaseWindow
4040
[SerializeField] private int statusAhead;
4141
[SerializeField] private int statusBehind;
4242
[SerializeField] private bool hasItemsToCommit;
43+
[SerializeField] private bool isTrackingRemoteBranch;
4344
[SerializeField] private GUIContent currentBranchContent;
4445
[SerializeField] private GUIContent currentRemoteUrlContent;
4546
[SerializeField] private CacheUpdateEvent lastCurrentBranchAndRemoteChangedEvent;
@@ -279,7 +280,17 @@ private void MaybeUpdateData()
279280
currentBranchAndRemoteHasUpdate = false;
280281

281282
var repositoryCurrentBranch = Repository.CurrentBranch;
282-
var updatedRepoBranch = repositoryCurrentBranch.HasValue ? repositoryCurrentBranch.Value.Name : null;
283+
string updatedRepoBranch;
284+
if (repositoryCurrentBranch.HasValue)
285+
{
286+
updatedRepoBranch = repositoryCurrentBranch.Value.Name;
287+
isTrackingRemoteBranch = !string.IsNullOrEmpty(repositoryCurrentBranch.Value.Tracking);
288+
}
289+
else
290+
{
291+
updatedRepoBranch = null;
292+
isTrackingRemoteBranch = false;
293+
}
283294

284295
var repositoryCurrentRemote = Repository.CurrentRemote;
285296
if (repositoryCurrentRemote.HasValue)
@@ -294,7 +305,7 @@ private void MaybeUpdateData()
294305

295306
if (currentRemoteName != updatedRepoRemote)
296307
{
297-
currentRemoteName = updatedRepoBranch;
308+
currentRemoteName = updatedRepoRemote;
298309
shouldUpdateContentFields = true;
299310
}
300311

@@ -313,6 +324,8 @@ private void MaybeUpdateData()
313324
}
314325
else
315326
{
327+
isTrackingRemoteBranch = false;
328+
316329
if (currentRemoteName != null)
317330
{
318331
currentRemoteName = null;
@@ -591,7 +604,7 @@ private void DoActionbarGUI()
591604
EditorGUI.EndDisabledGroup();
592605

593606
// Push button
594-
EditorGUI.BeginDisabledGroup(currentRemoteName == null || statusAhead == 0);
607+
EditorGUI.BeginDisabledGroup(currentRemoteName == null || isTrackingRemoteBranch && statusAhead == 0);
595608
{
596609
var pushButtonText = statusAhead > 0 ? new GUIContent(String.Format(Localization.PushButtonCount, statusAhead)) : pushButtonContent;
597610
var pushClicked = GUILayout.Button(pushButtonText, Styles.ToolbarButtonStyle);

src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task BranchListTest()
2323
.StartAsAsync();
2424

2525
gitBranches.Should().BeEquivalentTo(
26-
new GitBranch("master", "origin/master: behind 1"),
26+
new GitBranch("master", "origin/master"),
2727
new GitBranch("feature/document", "origin/feature/document"));
2828
}
2929

src/tests/UnitTests/IO/BranchListOutputProcessorTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ public void ShouldProcessOutput()
1515
{
1616
"* master ef7ecf9 [origin/master] Some project master",
1717
" feature/feature-1 f47d41b Untracked Feature 1",
18-
" bugfixes/bugfix-1 e1b7f22 [origin/bugfixes/bugfix-1] Tracked Local Bugfix"
18+
" bugfixes/bugfix-1 e1b7f22 [origin/bugfixes/bugfix-1] Tracked Local Bugfix",
19+
" bugfixes/bugfix-2 e1b7f22 [origin/bugfixes/bugfix-2: ahead 3] Ahead with some changes",
20+
" bugfixes/bugfix-3 e1b7f22 [origin/bugfixes/bugfix-3: ahead 3, behind 116] Ahead and Behind",
21+
" bugfixes/bugfix-4 e1b7f22 [origin/bugfixes/bugfix-4: gone] No longer on server",
1922
};
2023

2124
AssertProcessOutput(output, new[]
2225
{
2326
new GitBranch("master", "origin/master"),
24-
new GitBranch("feature/feature-1", ""),
27+
new GitBranch("feature/feature-1"),
2528
new GitBranch("bugfixes/bugfix-1", "origin/bugfixes/bugfix-1"),
29+
new GitBranch("bugfixes/bugfix-2", "origin/bugfixes/bugfix-2"),
30+
new GitBranch("bugfixes/bugfix-3", "origin/bugfixes/bugfix-3"),
31+
new GitBranch("bugfixes/bugfix-4", "origin/bugfixes/bugfix-4"),
2632
});
2733
}
2834

@@ -44,4 +50,4 @@ private void AssertProcessOutput(IEnumerable<string> lines, GitBranch[] expected
4450
results.ShouldAllBeEquivalentTo(expected);
4551
}
4652
}
47-
}
53+
}

0 commit comments

Comments
 (0)