Skip to content
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

git stash #309

Closed
bmll-chris opened this issue Mar 25, 2019 · 3 comments
Closed

git stash #309

bmll-chris opened this issue Mar 25, 2019 · 3 comments

Comments

@bmll-chris
Copy link

Similarly to the History tab, it would be useful to have a tab for managing stashed changes.

@bmll-chris bmll-chris changed the title git-stash git stash Mar 25, 2019
@FMelloMascarenhas-Cohere

+1

@fcollonval
Copy link
Member

cc @shawnesquivel

Let's start simple we could add two commands:

  • Stash to stash all changes (except untracked files)
  • Pop latest stash

On the backend

you will need to create two methods in the Git class:

  • one that execute git stash
  • one that execute git stash pop

You can find more about the Git commands in the documentation.

The you will need to add a handler for those in handlers.py:

class GitStashHandler(GitHandler):
    @tornado.web.authenticated
    async def post(self, path: str = ""):
        # ... call git stash
   
    @tornado.web.authenticated
    async def delete(self, path: str = "", name: str = ""):
        # ... call git stash pop

You can look for example at

@tornado.web.authenticated
async def post(self, path: str = ""):
"""POST request handler to add a remote."""
data = self.get_json_body()
name = data.get("name", DEFAULT_REMOTE_NAME)
url = data["url"]
output = await self.git.remote_add(self.url2localpath(path), url, name)
if output["code"] == 0:
self.set_status(201)
else:
self.set_status(500)
self.finish(json.dumps(output))

and

@tornado.web.authenticated
async def delete(self, path: str = "", name: str = ""):
"""DELETE request handler to remove a remote."""
local_path = self.url2localpath(path)
output = await self.git.remote_remove(local_path, name)
if output["code"] == 0:
self.set_status(204)
else:
self.set_status(500)
self.finish(json.dumps(output))

Then you will need to bind a new endpoint with the handlers at

handlers_with_path = [

I advice you to add some tests to check your implementation - see e.g. https://github.com/jupyterlab/jupyterlab-git/blob/master/jupyterlab_git/tests/test_remote.py

On the frontend

You need to add two methods for those two actions in

export class GitExtension implements IGitExtension {

Then you will need to add two commands that call those methods; taking inspiration from

commands.addCommand(CommandIDs.gitInit, {
label: trans.__('Initialize a Repository'),
caption: trans.__(
'Create an empty Git repository or reinitialize an existing one'
),
execute: async () => {
const currentPath = fileBrowserModel.path;
const result = await showDialog({
title: trans.__('Initialize a Repository'),
body: trans.__('Do you really want to make this directory a Git Repo?'),
buttons: [
Dialog.cancelButton({ label: trans.__('Cancel') }),
Dialog.warnButton({ label: trans.__('Yes') })
]
});
if (result.button.accept) {
logger.log({
message: trans.__('Initializing…'),
level: Level.RUNNING
});
try {
await gitModel.init(currentPath);
gitModel.pathRepository = currentPath;
logger.log({
message: trans.__('Git repository initialized.'),
level: Level.SUCCESS
});
} catch (error) {
console.error(
trans.__(
'Encountered an error when initializing the repository. Error: '
),
error
);
logger.log({
message: trans.__('Failed to initialize the Git repository'),
level: Level.ERROR,
error: error as Error
});
}
}
},
isEnabled: () => gitModel.pathRepository === null
});

To test them, you could add them to the menu at

https://github.com/jupyterlab/jupyterlab-git/blob/master/src/commandsAndMenu.tsx#L1320

I let you imagine a UI for those features.

@fcollonval
Copy link
Member

Closing as resolved y #1228

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

No branches or pull requests

4 participants