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

Commit a5f8353

Browse files
Parsing just the remote branch name in BranchListOutputProcessor
1 parent 858c0c2 commit a5f8353

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/GitHub.Api/Git/GitBranch.cs

Lines changed: 5 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,8 @@ public bool Equals(GitBranch other)
6464

6565
public override string ToString()
6666
{
67-
return $"{Name} Tracking? {Tracking}";
67+
var s = Tracking ?? "[NULL]";
68+
return $"{Name} Tracking? {s}";
6869
}
6970
}
70-
}
71+
}

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/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)