@@ -77,10 +77,12 @@ class GitCommandManager {
7777 async branchList ( remote : boolean ) : Promise < string [ ] > {
7878 const result : string [ ] = [ ]
7979
80- // Note, this implementation uses "rev-parse --symbolic" because the output from
80+ // Note, this implementation uses "rev-parse --symbolic-full-name " because the output from
8181 // "branch --list" is more difficult when in a detached HEAD state.
82+ // Note, this implementation uses "rev-parse --symbolic-full-name" because there is a bug
83+ // in Git 2.18 that causes "rev-parse --symbolic" to output symbolic full names.
8284
83- const args = [ 'rev-parse' , '--symbolic' ]
85+ const args = [ 'rev-parse' , '--symbolic-full-name ' ]
8486 if ( remote ) {
8587 args . push ( '--remotes=origin' )
8688 } else {
@@ -92,6 +94,12 @@ class GitCommandManager {
9294 for ( let branch of output . stdout . trim ( ) . split ( '\n' ) ) {
9395 branch = branch . trim ( )
9496 if ( branch ) {
97+ if ( branch . startsWith ( 'refs/heads/' ) ) {
98+ branch = branch . substr ( 'refs/heads/' . length )
99+ } else if ( branch . startsWith ( 'refs/remotes/' ) ) {
100+ branch = branch . substr ( 'refs/remotes/' . length )
101+ }
102+
95103 result . push ( branch )
96104 }
97105 }
@@ -170,12 +178,12 @@ class GitCommandManager {
170178 }
171179
172180 async isDetached ( ) : Promise < boolean > {
173- // Note, this implementation uses "branch --show-current" because
174- // "rev-parse --symbolic-full-name HEAD" can fail on a new repo
175- // with nothing checked out.
176-
177- const output = await this . execGit ( [ 'branch' , '--show-current' ] )
178- return output . stdout . trim ( ) === ''
181+ // Note, "branch --show-current" would be simpler but isn't available until Git 2.22
182+ const output = await this . execGit (
183+ [ 'rev-parse' , '--symbolic-full-name' , '--verify' , '--quiet' , 'HEAD' ] ,
184+ true
185+ )
186+ return ! output . stdout . trim ( ) . startsWith ( 'refs/heads/' )
179187 }
180188
181189 async lfsFetch ( ref : string ) : Promise < void > {
0 commit comments