akonwi/git-plus

[BUG] Error when opening non git repo

Closed this issue · 1 comments

With 8.6.0 a new feature has been introduced: show the current branch in the tree view.

Unfortunately, it throws an error in the developer tools when you open atom in a folder that is not a git repo.

Steps to reproduce:

  1. Open a folder that is not a git repo, e.g. a folder that contains multiple git repos (like the ~/github folder on mac)
  2. Wait for the error to appear in the developer tools
Uncaught (in promise) TypeError: Cannot read property 'getShortHead' of undefined
    at TreeViewBranchManager.renderBranch (C:\Users\lloiser\.atom\packages\git-plus\lib\views\tree-view-branches.ts:15:41)
    at <anonymous>

tree-view-branchs.ts:15 actually points to:

const branchName = `[${repo!.getShortHead()}]`;

Also, I can see the following warning in atom when it tries to find the source map for the tree-view-branches.ts file (probably that's the reason why it shows line 15 instead of line 43 in the error)

Error parsing source map SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)
    at retrieveSourceMap (C:\Users\lloiser\AppData\Local\atom\app-1.34.0\resources\app.asar\src\compile-cache.js:180:30)
    at mapSourcePosition (C:\Users\lloiser\AppData\Local\atom\app-1.34.0\resources\app.asar\node_modules\@atom\source-map-support\source-map-support.js:140:21)
    at wrapCallSite (C:\Users\lloiser\AppData\Local\atom\app-1.34.0\resources\app.asar\node_modules\@atom\source-map-support\source-map-support.js:312:20)
    at C:\Users\lloiser\AppData\Local\atom\app-1.34.0\resources\app.asar\node_modules\@atom\source-map-support\source-map-support.js:347:26
    at Array.map (<anonymous>)
    at prepareStackTrace (C:\Users\lloiser\AppData\Local\atom\app-1.34.0\resources\app.asar\node_modules\@atom\source-map-support\source-map-support.js:346:24)
    at Function.prepareStackTraceWithRawStackAssignment (C:\Users\lloiser\AppData\Local\atom\app-1.34.0\resources\app.asar\src\compile-cache.js:201:14)

Note: there is no error shown in the UI, just in the developer tools.

Thanks, I'll push a fix shortly