Skip to content

fix(tekton): map last line git-instead-of#4844

Open
timzxz wants to merge 1 commit into
mainfrom
fix_git_instead
Open

fix(tekton): map last line git-instead-of#4844
timzxz wants to merge 1 commit into
mainfrom
fix_git_instead

Conversation

@timzxz

@timzxz timzxz commented Jul 21, 2026

Copy link
Copy Markdown

No description provided.

@ti-chi-bot ti-chi-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I have already done a preliminary review for you, and I hope to help you do a better job.

Summary:
This PR fixes an issue in the Tekton git clone task where the last mapping in the PARAM_GIT_INSTEAD_OF parameter may be skipped due to how the shell while read loop processes input lines. The fix adds an additional condition to the loop to ensure the last line is processed even if it does not end with a newline. The change is minimal and focused, improving robustness of the git URL rewriting functionality.

Critical Issues:

  • None found.

Code Improvements:

  • Shell Parsing Robustness (tekton/v1/tasks/pingcap-git-clone.yaml line 260):

    • The addition of || [ -n "${mapping}" ] is a good fix to handle the last line without trailing newline.
    • However, the use of echo -n combined with tr ',' '\n' can fail if PARAM_GIT_INSTEAD_OF contains trailing commas or empty mappings.
    • Suggest trimming or sanitizing input before processing:
      echo "${PARAM_GIT_INSTEAD_OF}" | tr ',' '\n' | sed '/^\s*$/d' | while IFS= read -r mapping || [ -n "$mapping" ]; do
        # ...
      done
    • This removes empty lines caused by trailing commas and avoids unexpected empty mappings.
  • Parsing URL Mappings:

    • The parsing uses cut -d '=' -f 1 and cut -d '>' -f 2. This assumes mappings in the form something=...>....
    • Confirm and document the expected format of PARAM_GIT_INSTEAD_OF. If the format is src=dest, the use of > might be incorrect/confusing.
    • Clarify or add comments explaining the format and parsing logic to avoid future confusion.

Best Practices:

  • Documentation:
    • Add a comment above this block explaining what PARAM_GIT_INSTEAD_OF is expected to contain and the purpose of this loop.
    • Example:
      # Parse PARAM_GIT_INSTEAD_OF mappings of the form "src=dest" separated by commas,
      # and configure git url rewriting accordingly.
  • Testing:
    • If possible, add or update unit or integration tests covering edge cases such as:
      • Single mapping without trailing newline
      • Multiple mappings with trailing commas
      • Empty or malformed mappings
  • Style:
    • Prefer quoting variables inside the loop to avoid word splitting, e.g.:
      instead_of_url=$(echo "${mapping}" | cut -d '=' -f 1 | tr -d ' ' | tr -d '"')
      is fine, but ensure mapping is always quoted on reading and usage.

Summary: The fix correctly addresses the last line processing bug. Adding input sanitization, clarifying the mapping format, and improving documentation will make this more robust and maintainable.

@pingcap-cla-assistant

pingcap-cla-assistant Bot commented Jul 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot Bot added the size/XS label Jul 21, 2026
@timzxz

timzxz commented Jul 21, 2026

Copy link
Copy Markdown
Author

/approve

@ti-chi-bot

ti-chi-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: timzxz
Once this PR has been reviewed and has the lgtm label, please assign dillon-zheng for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant