@@ -377,7 +377,7 @@ def branch(self, current_path):
377377 return remotes
378378
379379 # all's good; concatenate results and return
380- return {"code" : 0 , "branches" : heads ["branches" ] + remotes ["branches" ]}
380+ return {"code" : 0 , "branches" : heads ["branches" ] + remotes ["branches" ], "current_branch" : heads [ "current_branch" ] }
381381
382382 def branch_heads (self , current_path ):
383383 """
@@ -393,37 +393,39 @@ def branch_heads(self, current_path):
393393 )
394394 output , error = p .communicate ()
395395 if p .returncode == 0 :
396- current_branch_seen = False
396+ current_branch = None
397397 results = []
398398 try :
399399 for name ,commit_sha ,upstream_name ,is_current_branch in (line .split ('\t ' ) for line in output .decode ("utf-8" ).splitlines ()):
400400 # Format reference : https://git-scm.com/docs/git-for-each-ref#_field_names
401- is_current_branch = bool (is_current_branch .strip ())
402- current_branch_seen |= is_current_branch
403-
404- results .append ({
405- "is_current_branch" : is_current_branch ,
401+ branch = {
406402 "is_remote_branch" : False ,
407403 "name" : name ,
408404 "upstream" : upstream_name if upstream_name else None ,
409405 "top_commit" : commit_sha ,
410406 "tag" : None ,
411- })
407+ }
408+ results .append (branch )
409+ if is_current_branch .strip ():
410+ current_branch = branch
412411
413412 # Remote branch is seleted use 'git branch -a' as fallback machanism
414413 # to get add detached head on remote branch to preserve older functionality
415414 # TODO : Revisit this to checkout new local branch with same name as remote
416415 # when the remote branch is seleted, VS Code git does the same thing.
417- if not current_branch_seen and self .get_current_branch (current_path ) == "HEAD" :
418- results .append ({
419- "is_current_branch" : True ,
416+ if not current_branch and self .get_current_branch (current_path ) == "HEAD" :
417+ branch = {
420418 "is_remote_branch" : False ,
421419 "name" : self ._get_detached_head_name (current_path ),
422420 "upstream" : None ,
423421 "top_commit" : None ,
424422 "tag" : None ,
425- })
426- return {"code" : p .returncode , "branches" : results }
423+ }
424+ results .append (branch )
425+ current_branch = branch
426+
427+ return {"code" : p .returncode , "branches" : results , "current_branch" : current_branch }
428+
427429 except Exception as downstream_error :
428430 return {
429431 "code" : - 1 ,
@@ -456,7 +458,6 @@ def branch_remotes(self, current_path):
456458 for name ,commit_sha in (line .split ('\t ' ) for line in output .decode ("utf-8" ).splitlines ()):
457459 # Format reference : https://git-scm.com/docs/git-for-each-ref#_field_names
458460 results .append ({
459- "is_current_branch" : False ,
460461 "is_remote_branch" : True ,
461462 "name" : name ,
462463 "upstream" : None ,
0 commit comments