@@ -77,28 +77,35 @@ export interface IGithubinatorConfig {
7777 }
7878}
7979
80+ export let outputChannel : vscode . LogOutputChannel
81+
8082export function activate ( context : vscode . ExtensionContext ) {
81- console . log ( "githubinator.active.start" )
83+ outputChannel = vscode . window . createOutputChannel ( "GitHubinator" , {
84+ log : true ,
85+ } )
86+ outputChannel . debug ( "githubinator.active.start" )
87+ context . subscriptions . push ( outputChannel )
8288 COMMANDS . forEach ( ( [ cmd , args ] ) => {
8389 const disposable = vscode . commands . registerCommand ( cmd , ( ) =>
8490 githubinator ( args ) ,
8591 )
8692 context . subscriptions . push ( disposable )
8793 } )
88- vscode . commands . registerCommand (
94+ const openFromUrlDisposable = vscode . commands . registerCommand (
8995 "githubinator.githubinatorOpenFromUrl" ,
9096 openFileFromGitHubUrl ,
9197 )
98+ context . subscriptions . push ( openFromUrlDisposable )
9299
93- console . log ( "githubinator.active.complete" )
100+ outputChannel . debug ( "githubinator.active.complete" )
94101}
95102
96103export function deactivate ( ) {
97- console . log ( "githubinator.deactivate" )
104+ outputChannel . debug ( "githubinator.deactivate" )
98105}
99106
100107function err ( message : string ) {
101- console . error ( message )
108+ outputChannel . error ( message )
102109 vscode . window . showErrorMessage ( message )
103110}
104111
@@ -127,11 +134,15 @@ function mainBranches() {
127134 . get < string [ ] > ( "mainBranches" , [ "main" ] )
128135}
129136
137+ /**
138+ * Search default main branch names for the first one that exists.
139+ */
130140async function findShaForBranches (
131- gitDir : string ,
141+ gitRepository : git . Repo ,
142+ fileUri : vscode . Uri ,
132143) : Promise < [ string , string ] | null > {
133144 for ( let branch of mainBranches ( ) ) {
134- const sha = await git . getSHAForBranch ( gitDir , branch )
145+ const sha = await git . getSHAForBranch ( gitRepository , branch )
135146 if ( sha == null ) {
136147 continue
137148 }
@@ -151,41 +162,41 @@ interface IGithubinator {
151162 openPR ?: boolean
152163 compare ?: boolean
153164}
154- async function githubinator ( {
155- openUrl,
156- copyToClipboard,
157- blame,
158- mainBranch,
159- openRepo,
160- permalink,
161- history,
162- openPR,
163- compare,
164- } : IGithubinator ) {
165- console . log ( "githubinator.call" )
165+ async function githubinator ( options : IGithubinator ) {
166+ const {
167+ openUrl,
168+ copyToClipboard,
169+ blame,
170+ mainBranch,
171+ openRepo,
172+ permalink,
173+ history,
174+ openPR,
175+ compare,
176+ } = options
177+ outputChannel . info (
178+ "githubinator called with options: " + JSON . stringify ( options ) ,
179+ )
166180 const editorConfig = getEditorInfo ( )
167181 if ( ! editorConfig . uri ) {
168- return err ( "could not find file" )
182+ return err ( "Could not find file for current editor. " )
169183 }
184+ const fileUri = editorConfig . uri
170185
171- const gitDirectories = git . dir ( editorConfig . uri . fsPath )
172-
173- if ( gitDirectories == null ) {
174- return err ( "Could not find .git directory." )
186+ const gitRepository = await git . getRepo ( fileUri )
187+ if ( ! gitRepository ) {
188+ return err ( "Could not find git repository for file." )
175189 }
176190
177- const gitDir = gitDirectories . git
178- const repoDir = gitDirectories . repository
179-
180191 let headBranch : [ string , string | null ] | null = null
181192 if ( mainBranch ) {
182- const res = await findShaForBranches ( gitDir )
193+ const res = await findShaForBranches ( gitRepository , fileUri )
183194 if ( res == null ) {
184195 return err ( `Could not find SHA for branch in ${ mainBranches ( ) } ` )
185196 }
186197 headBranch = res
187198 } else {
188- headBranch = await git . head ( gitDir )
199+ headBranch = await git . head ( gitRepository )
189200 }
190201 if ( headBranch == null ) {
191202 return err ( "Could not find HEAD." )
@@ -209,7 +220,7 @@ async function githubinator({
209220 const parsedUrl = await new provider (
210221 providersConfig ,
211222 globalDefaultRemote ,
212- ( remote ) => git . origin ( gitDir , remote ) ,
223+ ( remote ) => git . origin ( gitRepository , remote ) ,
213224 ) . getUrls ( {
214225 selection,
215226 // priority: permalink > branch > branch from HEAD
@@ -220,19 +231,19 @@ async function githubinator({
220231 ? createSha ( head )
221232 : createBranch ( branchName ) ,
222233 relativeFilePath : editorConfig . fileName
223- ? getRelativeFilePath ( repoDir , editorConfig . fileName )
234+ ? getRelativeFilePath ( gitRepository . rootUri , editorConfig . fileName )
224235 : null ,
225236 } )
226237 if ( parsedUrl != null ) {
227- console . log ( "Found provider" , provider . name )
238+ outputChannel . debug ( "Found provider" , provider . name )
228239 urls = parsedUrl
229240 break
230241 }
231- console . log ( "Skipping provider" , provider . name )
242+ outputChannel . debug ( "Skipping provider" , provider . name )
232243 }
233244
234245 if ( urls == null ) {
235- return err ( "Could not find provider for repo ." )
246+ return err ( "Could not find remote for repository ." )
236247 }
237248
238249 let url = compare
0 commit comments