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

Improve ignored files support in filebrowser #1200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sheezaaziz
Copy link
Contributor

@sheezaaziz sheezaaziz commented Dec 8, 2022

Fixes #984

@github-actions
Copy link

github-actions bot commented Dec 8, 2022

Binder 👈 Launch a binder notebook on branch sheezaaziz/jupyterlab-git/984.v2

@fcollonval fcollonval changed the title . Improve ignored files support in filebrowser Dec 8, 2022
Comment on lines +225 to +227
def check_ignore(self, path):
# in git.py Git, add a new method check_ignore that execute git check-ignore -z <path> and parse the result to return the list of ignored files; changed_files method is a good example of a similar method.
return
Copy link
Member

Choose a reason for hiding this comment

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

What you would like to do is to execute the git check-ignore command in the repository to know if it is ignored or not. Something like this should do:

Suggested change
def check_ignore(self, path):
# in git.py Git, add a new method check_ignore that execute git check-ignore -z <path> and parse the result to return the list of ignored files; changed_files method is a good example of a similar method.
return
def check_ignore(self, repository_path, path):
"""
Check if a path is ignored or not.
Args:
repository_path: Path to the Git repository
path: Relative path to check
"""
# in git.py Git, add a new method check_ignore that execute git check-ignore -z <path> and parse the result to return the list of ignored files; changed_files method is a good example of a similar method.
cmd = ["git", "check-ignore", "-z", path]
response = {}
try:
code, output, error = await execute(cmd, cwd=repository_path)
except subprocess.CalledProcessError as e:
response["code"] = e.returncode
response["message"] = e.output.decode("utf-8")
else:
response["code"] = code
if code != 0:
response["command"] = " ".join(cmd)
response["message"] = error
else:
response["files"] = strip_and_split(output)
return response

Comment on lines +826 to +827
def check_ignore(self, path):
self.git.check_ignore(self, path)
Copy link
Member

Choose a reason for hiding this comment

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

Here you want this method to be executed on an GET request. So the method should be named get. Then you will obtain the repository path as path input argument and you could for example get the relative path to check through a query argument like this:

Suggested change
def check_ignore(self, path):
self.git.check_ignore(self, path)
async def get(self, path):
path_to_check = self.get_query_argument("path", "")
body = await self.git.check_ignore(self, self.url2localpath(path), path_to_check)
if body["code"] != 0:
self.set_status(500)
self.finish(json.dumps(body))

Comment on lines +86 to +88
get isIgnored(): Git.IBranch {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Then to call the backend with the proper argument, you will need something like that

Suggested change
get isIgnored(): Git.IBranch {
return;
}
async isIgnored(pathToCheck: string): Promise<{files: string[]}> {
const path = await this._getPathRepository();
return requestAPI<{files: string[]}>(
URLExt.join(path, 'ignore') + URLExt.objectToQueryString({path: pathToCheck}),
'GET'
);
}

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

Successfully merging this pull request may close these issues.

Improve support of ignored files for file history
2 participants