-
Notifications
You must be signed in to change notification settings - Fork 319
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
base: main
Are you sure you want to change the base?
Conversation
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 |
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.
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:
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 |
def check_ignore(self, path): | ||
self.git.check_ignore(self, path) |
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.
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:
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)) |
get isIgnored(): Git.IBranch { | ||
return; | ||
} |
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.
Then to call the backend with the proper argument, you will need something like that
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' | |
); | |
} |
Fixes #984