@@ -34,58 +34,58 @@ function getGitProviderLink(cb, fileFsPath, lines, pr) {
3434 provider = null ,
3535 remoteName ;
3636
37- var branch = 'master' ;
38-
39- // Check to see if the branch has a configured remote
40- configuredBranch = config [ `branch " ${ branch } "` ] ;
41-
42- if ( configuredBranch ) {
43- // Use the current branch's configured remote
44- remoteName = configuredBranch . remote ;
45- rawUri = config [ `remote " ${ remoteName } "` ] . url ;
46- } else {
47- const remotes = Object . keys ( config ) . filter ( k => k . startsWith ( 'remote ' ) ) ;
48- if ( remotes . length > 0 ) {
49- rawUri = config [ remotes [ 0 ] ] . url ;
37+ gitRev . branch ( repoDir , function ( branchErr , branch ) {
38+ // Check to see if the branch has a configured remote
39+ configuredBranch = config [ ` branch " ${ branch } "` ] ;
40+
41+ if ( configuredBranch ) {
42+ // Use the current branch's configured remote
43+ remoteName = configuredBranch . remote ;
44+ rawUri = config [ ` remote " ${ remoteName } "` ] . url ;
45+ } else {
46+ const remotes = Object . keys ( config ) . filter ( k => k . startsWith ( 'remote ' ) ) ;
47+ if ( remotes . length > 0 ) {
48+ rawUri = config [ remotes [ 0 ] ] . url ;
49+ }
5050 }
51- }
52-
53- if ( ! rawUri ) {
54- Window . showWarningMessage ( `No remote found on branch.` ) ;
55- return ;
56- }
57-
58- try {
59- provider = gitProvider ( rawUri , sha ) ;
60- } catch ( e ) {
61- let errmsg = e . toString ( ) ;
62- Window . showWarningMessage ( `Unknown Git provider. ${ errmsg } ` ) ;
63- return ;
64- }
6551
66- let formattedFilePath = path . relative ( repoDir , fileFsPath ) . replace ( / \\ / g , '/' ) ;
67- formattedFilePath = formattedFilePath . replace ( / \s { 1 } / g , '%20' ) ;
68-
69- let subdir = repoDir !== fileFsPath ? '/' + formattedFilePath : '' ;
52+ if ( ! rawUri ) {
53+ Window . showWarningMessage ( `No remote found on branch.` ) ;
54+ return ;
55+ }
7056
71- if ( pr ) {
7257 try {
73- cb ( provider . prUrl ( branch ) ) ;
58+ provider = gitProvider ( rawUri , sha ) ;
7459 } catch ( e ) {
75- Window . showWarningMessage ( e . toString ( ) ) ;
60+ let errmsg = e . toString ( ) ;
61+ Window . showWarningMessage ( `Unknown Git provider. ${ errmsg } ` ) ;
7662 return ;
7763 }
78- } else {
79- if ( lines ) {
80- if ( lines [ 0 ] == lines [ 1 ] ) {
81- cb ( provider . webUrl ( sha , subdir , lines [ 0 ] ) ) ;
82- } else {
83- cb ( provider . webUrl ( sha , subdir , lines [ 0 ] , lines [ 1 ] ) ) ;
64+
65+ let formattedFilePath = path . relative ( repoDir , fileFsPath ) . replace ( / \\ / g, '/' ) ;
66+ formattedFilePath = formattedFilePath . replace ( / \s { 1 } / g, '%20' ) ;
67+
68+ let subdir = repoDir !== fileFsPath ? '/' + formattedFilePath : '' ;
69+
70+ if ( pr ) {
71+ try {
72+ cb ( provider . prUrl ( branch ) ) ;
73+ } catch ( e ) {
74+ Window . showWarningMessage ( e . toString ( ) ) ;
75+ return ;
8476 }
8577 } else {
86- cb ( provider . webUrl ( sha , subdir ) ) ;
78+ if ( lines ) {
79+ if ( lines [ 0 ] == lines [ 1 ] ) {
80+ cb ( provider . webUrl ( sha , subdir , lines [ 0 ] ) ) ;
81+ } else {
82+ cb ( provider . webUrl ( sha , subdir , lines [ 0 ] , lines [ 1 ] ) ) ;
83+ }
84+ } else {
85+ cb ( provider . webUrl ( sha , subdir ) ) ;
86+ }
8787 }
88- }
88+ } ) ;
8989 } ) ;
9090 } ) ;
9191}
0 commit comments