@@ -27,15 +27,15 @@ public QueryBranches(string repo)
2727 return branches ;
2828
2929 var lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
30- var remoteBranches = new HashSet < string > ( ) ;
30+ var remoteHeads = new Dictionary < string , string > ( ) ;
3131 foreach ( var line in lines )
3232 {
3333 var b = ParseLine ( line ) ;
3434 if ( b != null )
3535 {
3636 branches . Add ( b ) ;
3737 if ( ! b . IsLocal )
38- remoteBranches . Add ( b . FullName ) ;
38+ remoteHeads . Add ( b . FullName , b . Head ) ;
3939 else
4040 localBranchesCount ++ ;
4141 }
@@ -44,7 +44,22 @@ public QueryBranches(string repo)
4444 foreach ( var b in branches )
4545 {
4646 if ( b . IsLocal && ! string . IsNullOrEmpty ( b . Upstream ) )
47- b . IsUpstreamGone = ! remoteBranches . Contains ( b . Upstream ) ;
47+ {
48+ if ( remoteHeads . TryGetValue ( b . Upstream , out var upstreamHead ) )
49+ {
50+ b . IsUpstreamGone = false ;
51+
52+ if ( b . TrackStatus == null )
53+ b . TrackStatus = new QueryTrackStatus ( WorkingDirectory , b . Head , upstreamHead ) . Result ( ) ;
54+ }
55+ else
56+ {
57+ b . IsUpstreamGone = true ;
58+
59+ if ( b . TrackStatus == null )
60+ b . TrackStatus = new Models . BranchTrackStatus ( ) ;
61+ }
62+ }
4863 }
4964
5065 return branches ;
@@ -93,9 +108,10 @@ private Models.Branch ParseLine(string line)
93108 branch . Upstream = parts [ 4 ] ;
94109 branch . IsUpstreamGone = false ;
95110
96- if ( branch . IsLocal && ! string . IsNullOrEmpty ( parts [ 5 ] ) && ! parts [ 5 ] . Equals ( "=" , StringComparison . Ordinal ) )
97- branch . TrackStatus = new QueryTrackStatus ( WorkingDirectory , branch . Name , branch . Upstream ) . Result ( ) ;
98- else
111+ if ( ! branch . IsLocal ||
112+ string . IsNullOrEmpty ( branch . Upstream ) ||
113+ string . IsNullOrEmpty ( parts [ 5 ] ) ||
114+ parts [ 5 ] . Equals ( "=" , StringComparison . Ordinal ) )
99115 branch . TrackStatus = new Models . BranchTrackStatus ( ) ;
100116
101117 return branch ;
0 commit comments