Skip to content

Commit 8d87c5a

Browse files
authored
Correct repository as root case (#966)
Fixes #960
1 parent 4fd9052 commit 8d87c5a

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

jupyterlab_git/git.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import re
88
import shlex
99
import subprocess
10+
import traceback
1011
from urllib.parse import unquote
1112

1213
import nbformat
@@ -152,7 +153,8 @@ def call_subprocess(
152153
get_logger().debug(
153154
"Code: {}\nOutput: {}\nError: {}".format(code, log_output, log_error)
154155
)
155-
except BaseException:
156+
except BaseException as e:
157+
code, output, error = -1, "", traceback.format_exc()
156158
get_logger().warning("Fail to execute {!s}".format(cmdline), exc_info=True)
157159
finally:
158160
execution_lock.release()

src/components/GitPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
277277
render(): React.ReactElement {
278278
return (
279279
<div className={panelWrapperClass}>
280-
{this.state.repository ? (
280+
{this.state.repository !== null ? (
281281
<React.Fragment>
282282
{this._renderToolbar()}
283283
{this._renderMain()}

src/components/Toolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
235235
className={toolbarMenuButtonClass}
236236
title={this.props.trans.__(
237237
'Current repository: %1',
238-
this.props.repository
238+
'/' + this.props.repository
239239
)}
240240
>
241241
<desktopIcon.react className={toolbarMenuButtonIconClass} />
@@ -245,7 +245,7 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
245245
{this.props.trans.__('Current Repository')}{' '}
246246
</p>
247247
<p className={toolbarMenuButtonSubtitleClass}>
248-
{PathExt.basename(this.props.repository)}
248+
{PathExt.basename(this.props.repository) || '/'}
249249
</p>
250250
</div>
251251
</button>

src/model.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,18 @@ export class GitExtension implements IGitExtension {
147147
} else {
148148
const currentReady = this._readyPromise;
149149
this._pendingReadyPromise += 1;
150-
this._readyPromise = Promise.all([currentReady, this.showPrefix(v)])
150+
const currentFolder = v;
151+
this._readyPromise = Promise.all([
152+
currentReady,
153+
this.showPrefix(currentFolder)
154+
])
151155
.then(([_, path]) => {
152156
if (path !== null) {
153157
// Remove relative path to get the Git repository root path
154-
path = v.slice(0, v.length - path.length);
158+
path = currentFolder.slice(
159+
0,
160+
Math.max(0, currentFolder.length - path.length)
161+
);
155162
}
156163
change.newValue = this._pathRepository = path;
157164

@@ -162,7 +169,9 @@ export class GitExtension implements IGitExtension {
162169
})
163170
.catch(reason => {
164171
this._pendingReadyPromise -= 1;
165-
console.error(`Fail to find Git top level for path ${v}.\n${reason}`);
172+
console.error(
173+
`Fail to find Git top level for path ${currentFolder}.\n${reason}`
174+
);
166175
});
167176
}
168177
}

0 commit comments

Comments
 (0)