Skip to content

Conversation

@Meriem-BenIsmail
Copy link
Member

@Meriem-BenIsmail Meriem-BenIsmail commented Nov 27, 2025

Fixes #392.
This PR introduces an optional workflow to help users keep cleaner Git histories when working with Jupyter notebooks.

  1. Clear-Outputs Prompt Before Commit
    When committing, if staged notebooks contain cell outputs, a dialog now appears offering two choices:
Screencast.from.2025-11-27.09-39-48.webm
  1. Git Setting: Always Clear Outputs
    A new configuration option has been added to the Git extension settings:
    When enabled, notebook outputs are automatically stripped before every commit, skipping the dialog entirely.
image

Implementation Details
Backend endpoints were added to:

  • detect staged notebooks with outputs.
  • clear outputs using jupyter nbconvert.

@github-actions
Copy link

Binder 👈 Launch a Binder on branch Meriem-BenIsmail/jupyterlab-git/clean-outputs

Copy link
Member

@afshin afshin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Meriem!

@SylvainCorlay
Copy link
Member

Should we merge this? @Meriem-BenIsmail

@Meriem-BenIsmail
Copy link
Member Author

Should we merge this? @Meriem-BenIsmail

Yes no problem on my end.

full_cmd = cmd + options + [full_path]

# Run the cleaning command
subprocess.run(full_cmd, check=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be using the existing self.__execute() instead of the blocking subprocess.run()?

return {"code": code, "message": output.strip()}

async def check_notebooks_with_outputs(self, path):
import nbformat, os
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports already seem to be listed at the top of the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes thanks for noticing.

const result = await dialog.launch();
dialog.dispose();

if (result.button.label === this.props.trans.__('Cancel')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use result.button.accept here for the check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleaning Notebook cell outputs

5 participants