Skip to content

Conversation

BernardXiong
Copy link
Member

  • 修正有的时候会把.git/config改乱成下载链接的bug
  • 当 cmds/.config 不存在时不再输出错误信息

@BernardXiong BernardXiong requested a review from Copilot October 11, 2025 02:41
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes two issues related to package management: a bug where .git/config could be corrupted with download links instead of proper git URLs, and elimination of error messages when cmds/.config doesn't exist.

  • Adds proper validation for git URLs before attempting to restore origin remotes
  • Implements graceful handling when the environment config file is missing
  • Introduces a helper function to safely determine appropriate git URLs for restoration

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmds/cmd_package/cmd_package_upgrade.py Adds file existence check before reading config to prevent errors
cmds/cmd_package/cmd_package_update.py Adds git URL validation, helper function for safe URL restoration, and improved config handling

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +51 to +55
"""Return a suitable git URL to restore remote.origin.url.
Prefer the per-version URL if it ends with '.git'. Otherwise, fall back to
the 'repository' field (appending '.git' when necessary). Return None when
no suitable git URL can be determined.
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring should specify the parameter types and return type for better clarity. Consider adding Args and Returns sections to document package_obj and ver parameters.

Suggested change
"""Return a suitable git URL to restore remote.origin.url.
Prefer the per-version URL if it ends with '.git'. Otherwise, fall back to
the 'repository' field (appending '.git' when necessary). Return None when
no suitable git URL can be determined.
"""
Return a suitable git URL to restore remote.origin.url.
Prefer the per-version URL if it ends with '.git'. Otherwise, fall back to
the 'repository' field (appending '.git' when necessary). Return None when
no suitable git URL can be determined.
Args:
package_obj (object): The package object that provides the `get_url` method and a `pkg` attribute.
ver (str): The version identifier to query for a specific URL.
Returns:
str or None: The git URL as a string if found, otherwise None.

Copilot uses AI. Check for mistakes.

Comment on lines +57 to +60
try:
url = package_obj.get_url(ver)
except Exception:
url = None
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching bare Exception is too broad. Consider catching more specific exceptions that get_url might raise to avoid masking unexpected errors.

Copilot uses AI. Check for mistakes.

repo = None
try:
repo = package_obj.pkg.get('repository') if package_obj and package_obj.pkg else None
except Exception:
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching bare Exception is too broad. Consider catching more specific exceptions that might be raised when accessing package_obj.pkg to avoid masking unexpected errors.

Suggested change
except Exception:
except (AttributeError, TypeError):

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant