Skip to content

Improve ignored files support in filebrowser #1200

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jupyterlab_git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ async def config(self, path, **kwargs):

return response

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
Comment on lines +225 to +227
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


async def changed_files(self, path, base=None, remote=None, single_commit=None):
"""Gets the list of changed files between two Git refs, or the files changed in a single commit

Expand Down
4 changes: 4 additions & 0 deletions jupyterlab_git/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ async def post(self, path: str = ""):
self.set_status(500)
self.finish(json.dumps(body))

@tornado.web.authenticated
def check_ignore(self, path):
self.git.check_ignore(self, path)
Comment on lines +826 to +827
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))



class GitSettingsHandler(GitHandler):
@tornado.web.authenticated
Expand Down
1 change: 1 addition & 0 deletions src/commandsAndMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,7 @@ export function addFileBrowserContextMenu(
const wasShown = menu.isVisible;
const parent = menu.parentMenu;

// need to rmv the ignored files from this
const items = toArray(filebrowser.selectedItems());
const statuses = new Set<Git.Status>(
items
Expand Down
7 changes: 7 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export class GitExtension implements IGitExtension {
}
}

/**
* Requests the new GET endpoint.
*/
get isIgnored(): Git.IBranch {
return;
}
Comment on lines +86 to +88
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'
);
}


/**
* Branch list for the current repository.
*/
Expand Down