diff --git a/src/cloneCommand.tsx b/src/cloneCommand.tsx index 28484a7e9..12efa6ae1 100644 --- a/src/cloneCommand.tsx +++ b/src/cloneCommand.tsx @@ -69,7 +69,9 @@ export const gitCloneCommandPlugin: JupyterFrontEndPlugin = { Operation.Clone, trans, { - path: fileBrowserModel.path, + path: app.serviceManager.contents.localPath( + fileBrowserModel.path + ), url: result.value.url, versioning: result.value.versioning, submodules: result.value.submodules @@ -125,7 +127,13 @@ export const gitCloneCommandPlugin: JupyterFrontEndPlugin = { ); // Add the context menu items for the default file browser - addFileBrowserContextMenu(gitModel, fileBrowser, app.contextMenu, trans); + addFileBrowserContextMenu( + gitModel, + fileBrowser, + app.serviceManager.contents, + app.contextMenu, + trans + ); if (palette) { // Add the commands to the command palette diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index 61ffbeefd..dbf0c58a3 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -210,7 +210,9 @@ export function addCommands( 'Create an empty Git repository or reinitialize an existing one' ), execute: async () => { - const currentPath = fileBrowserModel.path; + const currentPath = app.serviceManager.contents.localPath( + fileBrowserModel.path + ); const result = await showDialog({ title: trans.__('Initialize a Repository'), body: trans.__('Do you really want to make this directory a Git Repo?'), @@ -1314,7 +1316,9 @@ export function addCommands( change.newValue?.last_modified ?? 0 ).valueOf(); if ( - change.newValue?.path === fullPath && + app.serviceManager.contents.localPath( + change.newValue?.path ?? '' + ) === fullPath && model.challenger.updateAt !== updateAt ) { model.challenger = { @@ -1794,6 +1798,7 @@ export function addHistoryMenuItems( export function addFileBrowserContextMenu( model: IGitExtension, filebrowser: FileBrowser, + contents: Contents.IManager, contextMenu: ContextMenuSvg, trans: TranslationBundle ): void { @@ -1809,11 +1814,12 @@ export function addFileBrowserContextMenu( const statuses = new Set( // @ts-expect-error file cannot be undefined or null items - .map(item => - model.pathRepository === null + .map(item => { + const itemPath = contents.localPath(item.path); + return model.pathRepository === null ? undefined - : model.getFile(item.path)?.status - ) + : model.getFile(itemPath)?.status; + }) .filter(status => typeof status !== 'undefined') ); diff --git a/src/index.ts b/src/index.ts index 928032747..7e0729136 100644 --- a/src/index.ts +++ b/src/index.ts @@ -147,19 +147,25 @@ async function activate( // Create the Git model const gitExtension = new GitExtension(docmanager, app.docRegistry, settings); - // Whenever we restore the application, sync the Git extension path - Promise.all([app.restored, fileBrowser.model.restored]).then(() => { - gitExtension.pathRepository = fileBrowser.model.path; - }); - const onPathChanged = ( model: FileBrowserModel, change: IChangedArgs ) => { - gitExtension.pathRepository = change.newValue; + gitExtension.pathRepository = app.serviceManager.contents.localPath( + change.newValue + ); gitExtension.refreshBranch(); }; + // Whenever we restore the application, sync the Git extension path + Promise.all([app.restored, fileBrowser.model.restored]).then(() => { + onPathChanged(fileBrowser.model, { + name: 'path', + newValue: fileBrowser.model.path, + oldValue: '' + }); + }); + // Whenever the file browser path changes, sync the Git extension path fileBrowser.model.pathChanged.connect(onPathChanged); @@ -245,6 +251,7 @@ async function activate( addFileBrowserContextMenu( gitExtension, fileBrowser, + app.serviceManager.contents, app.contextMenu, trans );