Conversation
Signed-off-by: Piyush Sachdeva <psachdeva@microsoft.com> Signed-off-by: Piyush Sachdeva <s.piyush1024@gmail.com>
Signed-off-by: Piyush Sachdeva <psachdeva@microsoft.com> Signed-off-by: Piyush Sachdeva <s.piyush1024@gmail.com>
Signed-off-by: Piyush Sachdeva <psachdeva@microsoft.com> Signed-off-by: Piyush Sachdeva <s.piyush1024@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds git remote management and worktree functionality to the Git tool class, enabling operations such as adding/removing remotes, creating/managing worktrees, and fetching from specific remotes. These features are designed to optimize repeated kernel builds by allowing multiple working directories from a single repository.
Changes:
- Enhanced the
fetchmethod to support fetching from specific remotes - Added remote management methods (list, exists, add, remove, set-url, get-url) for managing git remotes
- Added worktree management methods (add, list, remove, prune, exists, is_branch_checked_out) for creating and managing git worktrees
lisa/tools/git.py
Outdated
There was a problem hiding this comment.
Trailing space in the command string may result in unexpected formatting. The command is built as "worktree add ... {path} " with a trailing space, which could cause issues or look inconsistent in logs. Consider removing the trailing space or ensuring it's intentional for the git command syntax.
| cmd += f" {path} " | |
| cmd += f" {path}" |
lisa/tools/git.py
Outdated
There was a problem hiding this comment.
The error message "Even the origin remote doesn't exist?" is misleading and doesn't match the context. This method lists all remotes and can succeed even with no remotes (empty output), so the assertion should not assume that the origin remote must exist. Consider removing this redundant assertion or updating the message to be more accurate.
| result.assert_exit_code( | |
| message=f"Even the origin remote doesn't exist?", include_output=True | |
| ) |
lisa/tools/git.py
Outdated
There was a problem hiding this comment.
Inconsistent use of logging flags. The method uses no_info_log=False while most other methods in this class use no_info_log=True for similar git remote operations (see remote_add, remote_remove, remote_get_url). For consistency, this should likely be no_info_log=True.
| no_info_log=False, | |
| no_info_log=True, |
lisa/tools/git.py
Outdated
There was a problem hiding this comment.
This commented-out code should either be removed or implemented. The comment suggests an alternative approach to handle branch name conflicts by appending the RUN_ID, but the current implementation simply detaches instead. Either remove this line if detaching is the intended behavior, or implement the commented logic if that's the desired approach.
| # new_branch = f"{new_branch}_{constants.RUN_ID}" |
lisa/tools/git.py
Outdated
There was a problem hiding this comment.
Potential KeyError if a worktree doesn't have a "path" key. The worktree_list parsing logic can create worktrees with missing keys depending on the git output. Add proper error handling or ensure all worktrees have a "path" key before accessing it. Consider using wt.get("path") instead.
lisa/tools/git.py
Outdated
There was a problem hiding this comment.
Potential KeyError if a worktree doesn't have a "branch" key. The worktree_list parsing logic may create worktrees with missing keys depending on the git output format. Add proper error handling or ensure all worktrees have a "branch" key before accessing it. Consider using wt.get("branch", "") and handling the empty case appropriately.
| wt_branch = wt["branch"] | |
| wt_branch = wt.get("branch") | |
| if not wt_branch: | |
| continue |
lisa/tools/git.py
Outdated
There was a problem hiding this comment.
Variable detach is not used.
| detach = True |
| ) | ||
| result.assert_exit_code( | ||
| message=f"Even the origin remote doesn't exist?", include_output=True | ||
| ) |
There was a problem hiding this comment.
The code will never be executed since previous step already contains the judgement of expected_exit_code
This adds the functionality in the git tool to add new remotes and create worktrees from existing repositories.
This helps in saving time when repeated kernel builds happen with minor changes.