Improve ignored files support in filebrowser#1200
Open
sheezaaziz wants to merge 1 commit into
Open
Conversation
fcollonval
reviewed
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 |
Member
There was a problem hiding this comment.
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) |
Member
There was a problem hiding this comment.
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; | ||
| } |
Member
There was a problem hiding this comment.
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' | |
| ); | |
| } |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #984