-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load gitignore file #1273
Merged
fcollonval
merged 16 commits into
jupyterlab:jlab-3
from
kentarolim10:gitignore-wont-open-if-file-hidden
Nov 15, 2023
Merged
Load gitignore file #1273
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ed1c9d2
Throw 403 if file is hidden
kentarolim10 972e6dc
Add Helpful GUI message for hidden files
kentarolim10 939e9cb
Fetch file contents if hidden file
kentarolim10 37e6ee3
Show hidden file in widget
kentarolim10 335a43a
Format gitignore file
kentarolim10 adc74aa
Show hidden file message when adding file to .gitignore
kentarolim10 eb6abf2
Add ability to save .gitignore
kentarolim10 8eb7021
Fix bug where you can open two .gitignore files
kentarolim10 6eac31d
Add option to hide hidden file warning
kentarolim10 a09953d
Fix PR requests for gitignore bug
kentarolim10 8a51328
Fix prettier styles for gitignore
kentarolim10 e6c1e9b
Improve translation
fcollonval 7c73b8c
Improve gitignore model and add hiddenFile option to schema
kentarolim10 df62ed6
Merge branch 'gitignore-wont-open-if-file-hidden' of https://github.c…
kentarolim10 14950b7
Fix eslint
kentarolim10 78fe0c5
Fix .gitignore content sending
kentarolim10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import { Contents, ContentsManager } from '@jupyterlab/services'; | |
import { ISettingRegistry } from '@jupyterlab/settingregistry'; | ||
import { ITerminal } from '@jupyterlab/terminal'; | ||
import { ITranslator, TranslationBundle } from '@jupyterlab/translation'; | ||
import { closeIcon, ContextMenuSvg } from '@jupyterlab/ui-components'; | ||
import { closeIcon, ContextMenuSvg, saveIcon } from '@jupyterlab/ui-components'; | ||
import { ArrayExt, find, toArray } from '@lumino/algorithm'; | ||
import { CommandRegistry } from '@lumino/commands'; | ||
import { PromiseDelegate } from '@lumino/coreutils'; | ||
|
@@ -52,6 +52,9 @@ import { AdvancedPushForm } from './widgets/AdvancedPushForm'; | |
import { GitCredentialsForm } from './widgets/CredentialsBox'; | ||
import { discardAllChanges } from './widgets/discardAllChanges'; | ||
import { CheckboxForm } from './widgets/GitResetToRemoteForm'; | ||
import { CodeEditor } from '@jupyterlab/codeeditor/lib/editor'; | ||
import { CodeEditorWrapper } from '@jupyterlab/codeeditor/lib/widget'; | ||
import { editorServices } from '@jupyterlab/codemirror'; | ||
|
||
export interface IGitCloneArgs { | ||
/** | ||
|
@@ -303,13 +306,130 @@ export function addCommands( | |
} | ||
}); | ||
|
||
async function showGitignore(error: any) { | ||
const model = new CodeEditor.Model({}); | ||
const repoPath = gitModel.getRelativeFilePath(); | ||
const id = repoPath + '/.git-ignore'; | ||
const contentData = await gitModel.readGitIgnore(); | ||
|
||
const gitIgnoreWidget = find(shell.widgets(), shellWidget => { | ||
if (shellWidget.id === id) { | ||
return true; | ||
} | ||
}); | ||
if (gitIgnoreWidget) { | ||
shell.activateById(id); | ||
return; | ||
} | ||
model.sharedModel.setSource(contentData ? contentData : ''); | ||
const editor = new CodeEditorWrapper({ | ||
factory: editorServices.factoryService.newDocumentEditor, | ||
model: model | ||
}); | ||
const modelChangedSignal = model.sharedModel.changed; | ||
editor.disposed.connect(() => { | ||
model.dispose(); | ||
}); | ||
const preview = new MainAreaWidget({ | ||
content: editor | ||
}); | ||
|
||
preview.title.label = '.gitignore'; | ||
preview.id = id; | ||
preview.title.icon = gitIcon; | ||
preview.title.closable = true; | ||
preview.title.caption = repoPath + '/.gitignore'; | ||
const saveButton = new ToolbarButton({ | ||
icon: saveIcon, | ||
onClick: async () => { | ||
if (saved) { | ||
return; | ||
} | ||
const newContent = model.sharedModel.getSource(); | ||
try { | ||
await gitModel.writeGitIgnore(newContent); | ||
preview.title.className = ''; | ||
saved = true; | ||
} catch (error) { | ||
console.log('Could not save .gitignore'); | ||
} | ||
}, | ||
tooltip: trans.__('Saves .gitignore') | ||
}); | ||
let saved = true; | ||
preview.toolbar.addItem('save', saveButton); | ||
shell.add(preview); | ||
modelChangedSignal.connect(() => { | ||
if (saved) { | ||
saved = false; | ||
preview.title.className = 'not-saved'; | ||
} | ||
}); | ||
} | ||
|
||
/* Helper: Show gitignore hidden file */ | ||
async function showGitignoreHiddenFile(error: any, hidePrompt: boolean) { | ||
if (hidePrompt) { | ||
return showGitignore(error); | ||
} | ||
const result = await showDialog({ | ||
title: trans.__('Warning: The .gitignore file is a hidden file.'), | ||
body: ( | ||
<div> | ||
{trans.__( | ||
'Hidden files by default cannot be accessed with the regular code editor. In order to open the .gitignore file you must:' | ||
)} | ||
<ol> | ||
<li> | ||
{trans.__( | ||
'Print the command below to create a jupyter_server_config.py file with defaults commented out. If you already have the file located in .jupyter, skip this step.' | ||
)} | ||
<div style={{ padding: '0.5rem' }}> | ||
{'jupyter server --generate-config'} | ||
</div> | ||
</li> | ||
<li> | ||
{trans.__( | ||
'Open jupyter_server_config.py, uncomment out the following line and set it to True:' | ||
)} | ||
<div style={{ padding: '0.5rem' }}> | ||
{'c.ContentsManager.allow_hidden = False'} | ||
</div> | ||
</li> | ||
</ol> | ||
</div> | ||
), | ||
buttons: [ | ||
Dialog.cancelButton({ label: trans.__('Cancel') }), | ||
Dialog.okButton({ label: trans.__('Show .gitignore file anyways') }) | ||
], | ||
checkbox: { | ||
label: trans.__('Do not show this warning again'), | ||
checked: false | ||
} | ||
}); | ||
if (result.button.accept) { | ||
settings.set('hideHiddenFileWarning', result.isChecked); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 You are only missing one element for dealing with settings; they require to be defined in a JSON schema. For this extension, the schema is defined in |
||
showGitignore(error); | ||
} | ||
} | ||
|
||
/** Add git open gitignore command */ | ||
commands.addCommand(CommandIDs.gitOpenGitignore, { | ||
label: trans.__('Open .gitignore'), | ||
caption: trans.__('Open .gitignore'), | ||
isEnabled: () => gitModel.pathRepository !== null, | ||
execute: async () => { | ||
await gitModel.ensureGitignore(); | ||
try { | ||
await gitModel.ensureGitignore(); | ||
} catch (error: any) { | ||
if (error?.name === 'hiddenFile') { | ||
await showGitignoreHiddenFile( | ||
error, | ||
settings.composite['hideHiddenFileWarning'] as boolean | ||
); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
|
@@ -1456,7 +1576,16 @@ export function addCommands( | |
const { files } = args as any as CommandArguments.IGitContextAction; | ||
for (const file of files) { | ||
if (file) { | ||
await gitModel.ignore(file.to, false); | ||
try { | ||
await gitModel.ignore(file.to, false); | ||
} catch (error: any) { | ||
if (error?.name === 'hiddenFile') { | ||
await showGitignoreHiddenFile( | ||
error, | ||
settings.composite['hideHiddenFileWarning'] as boolean | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can skip passing an empty object. And this is probably better after the logic for looking if a widget already exists.