-
Notifications
You must be signed in to change notification settings - Fork 4
fix: Add functions to clean Git lock files locally and remotely #152
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
Changes from 1 commit
d8be706
42f859c
5e5d711
0193fb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||||
| import concurrent.futures | ||||||||||||||||||||||||||||||||||
| import glob | ||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||
|
|
@@ -127,7 +128,53 @@ def _set_branch_variables(self): | |||||||||||||||||||||||||||||||||
| self.utils.set_env_var( | ||||||||||||||||||||||||||||||||||
| "GITHUB_RUN_ATTEMPT", self.run_attempt, os.getenv("GITHUB_ENV", "") | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def clean_git_locks(repo_path): | ||||||||||||||||||||||||||||||||||
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
| """清理 Git 锁文件""" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| git_dir = os.path.join(repo_path, '.git') | ||||||||||||||||||||||||||||||||||
| if not os.path.exists(git_dir): | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| lock_files = glob.glob(os.path.join(git_dir, '*.lock')) | ||||||||||||||||||||||||||||||||||
| for lock_file in lock_files: | ||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||
| os.remove(lock_file) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+136
to
+143
|
||||||||||||||||||||||||||||||||||
| git_dir = os.path.join(repo_path, '.git') | |
| if not os.path.exists(git_dir): | |
| return | |
| lock_files = glob.glob(os.path.join(git_dir, '*.lock')) | |
| for lock_file in lock_files: | |
| try: | |
| os.remove(lock_file) | |
| git_dir = Path(repo_path) / ".git" | |
| if not git_dir.exists(): | |
| return | |
| lock_files = git_dir.glob("*.lock") | |
| for lock_file in lock_files: | |
| try: | |
| lock_file.unlink() |
Outdated
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.
Outdated
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.
Outdated
Copilot
AI
Feb 4, 2026
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.
The code uses print() for logging messages, which is inconsistent with the logging convention used throughout the rest of the codebase. Other methods in this class use the logger object (e.g., logger.info(), logger.error()) for logging. This should be updated to use logger.info() for informational messages and logger.error() or logger.warning() for error messages to maintain consistency.
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 4, 2026
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.
The AutoAddPolicy allows any SSH host key without verification, which is a security risk. This could make the connection vulnerable to man-in-the-middle attacks. However, I note that the existing _execute_remote_command method (line 346) also uses AutoAddPolicy, so this is consistent with the current codebase pattern. If this pattern is acceptable for your infrastructure (e.g., trusted internal network), this is fine. Otherwise, consider using a more secure approach like RejectPolicy with properly configured known_hosts.
| ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
| # Load known host keys and reject unknown hosts to avoid MITM vulnerabilities | |
| ssh.load_system_host_keys() | |
| user_known_hosts = os.path.expanduser("~/.ssh/known_hosts") | |
| if os.path.exists(user_known_hosts): | |
| ssh.load_host_keys(user_known_hosts) | |
| ssh.set_missing_host_key_policy(paramiko.RejectPolicy()) |
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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.
tomchon marked this conversation as resolved.
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Show resolved
Hide resolved
tomchon marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 4, 2026
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.
The function calls self.clean_git_locks_remote(host, username, ...) but doesn't provide the required password or key_filename parameters that are needed for SSH authentication. Looking at the host_config structure used elsewhere in the code (e.g., line 349-352), these parameters should be extracted from host_config if available, or the function should handle authentication properly. Without proper authentication parameters, the SSH connection will fail.
Copilot
AI
Feb 4, 2026
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.
The function calls self.clean_git_locks_remote(host, username, ...) but doesn't provide the required password or key_filename parameters that are needed for SSH authentication. Looking at the host_config structure used elsewhere in the code (e.g., line 349-352), these parameters should be extracted from host_config if available, or the function should handle authentication properly. Without proper authentication parameters, the SSH connection will fail.
Uh oh!
There was an error while loading. Please reload this page.