Skip to content

Commit 81c258f

Browse files
authored
Remove drive from browser path. (#1285)
1 parent 805a27f commit 81c258f

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

src/cloneCommand.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export const gitCloneCommandPlugin: JupyterFrontEndPlugin<void> = {
6969
Operation.Clone,
7070
trans,
7171
{
72-
path: fileBrowserModel.path,
72+
path: app.serviceManager.contents.localPath(
73+
fileBrowserModel.path
74+
),
7375
url: result.value.url,
7476
versioning: result.value.versioning,
7577
submodules: result.value.submodules
@@ -125,7 +127,13 @@ export const gitCloneCommandPlugin: JupyterFrontEndPlugin<void> = {
125127
);
126128

127129
// Add the context menu items for the default file browser
128-
addFileBrowserContextMenu(gitModel, fileBrowser, app.contextMenu, trans);
130+
addFileBrowserContextMenu(
131+
gitModel,
132+
fileBrowser,
133+
app.serviceManager.contents,
134+
app.contextMenu,
135+
trans
136+
);
129137

130138
if (palette) {
131139
// Add the commands to the command palette

src/commandsAndMenu.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ export function addCommands(
210210
'Create an empty Git repository or reinitialize an existing one'
211211
),
212212
execute: async () => {
213-
const currentPath = fileBrowserModel.path;
213+
const currentPath = app.serviceManager.contents.localPath(
214+
fileBrowserModel.path
215+
);
214216
const result = await showDialog({
215217
title: trans.__('Initialize a Repository'),
216218
body: trans.__('Do you really want to make this directory a Git Repo?'),
@@ -1314,7 +1316,9 @@ export function addCommands(
13141316
change.newValue?.last_modified ?? 0
13151317
).valueOf();
13161318
if (
1317-
change.newValue?.path === fullPath &&
1319+
app.serviceManager.contents.localPath(
1320+
change.newValue?.path ?? ''
1321+
) === fullPath &&
13181322
model.challenger.updateAt !== updateAt
13191323
) {
13201324
model.challenger = {
@@ -1794,6 +1798,7 @@ export function addHistoryMenuItems(
17941798
export function addFileBrowserContextMenu(
17951799
model: IGitExtension,
17961800
filebrowser: FileBrowser,
1801+
contents: Contents.IManager,
17971802
contextMenu: ContextMenuSvg,
17981803
trans: TranslationBundle
17991804
): void {
@@ -1809,11 +1814,12 @@ export function addFileBrowserContextMenu(
18091814
const statuses = new Set<Git.Status>(
18101815
// @ts-expect-error file cannot be undefined or null
18111816
items
1812-
.map(item =>
1813-
model.pathRepository === null
1817+
.map(item => {
1818+
const itemPath = contents.localPath(item.path);
1819+
return model.pathRepository === null
18141820
? undefined
1815-
: model.getFile(item.path)?.status
1816-
)
1821+
: model.getFile(itemPath)?.status;
1822+
})
18171823
.filter(status => typeof status !== 'undefined')
18181824
);
18191825

src/index.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,25 @@ async function activate(
147147
// Create the Git model
148148
const gitExtension = new GitExtension(docmanager, app.docRegistry, settings);
149149

150-
// Whenever we restore the application, sync the Git extension path
151-
Promise.all([app.restored, fileBrowser.model.restored]).then(() => {
152-
gitExtension.pathRepository = fileBrowser.model.path;
153-
});
154-
155150
const onPathChanged = (
156151
model: FileBrowserModel,
157152
change: IChangedArgs<string>
158153
) => {
159-
gitExtension.pathRepository = change.newValue;
154+
gitExtension.pathRepository = app.serviceManager.contents.localPath(
155+
change.newValue
156+
);
160157
gitExtension.refreshBranch();
161158
};
162159

160+
// Whenever we restore the application, sync the Git extension path
161+
Promise.all([app.restored, fileBrowser.model.restored]).then(() => {
162+
onPathChanged(fileBrowser.model, {
163+
name: 'path',
164+
newValue: fileBrowser.model.path,
165+
oldValue: ''
166+
});
167+
});
168+
163169
// Whenever the file browser path changes, sync the Git extension path
164170
fileBrowser.model.pathChanged.connect(onPathChanged);
165171

@@ -245,6 +251,7 @@ async function activate(
245251
addFileBrowserContextMenu(
246252
gitExtension,
247253
fileBrowser,
254+
app.serviceManager.contents,
248255
app.contextMenu,
249256
trans
250257
);

0 commit comments

Comments
 (0)