Skip to content

fix(git): strip only leading origin/ prefix in autocommit branch name - #42269

Open
auyua9 wants to merge 1 commit into
appsmithorg:releasefrom
auyua9:fix/autocommit-strip-leading-origin-prefix
Open

auyua9 wants to merge 1 commit into
appsmithorg:releasefrom
auyua9:fix/autocommit-strip-leading-origin-prefix

Conversation

@auyua9

@auyua9 auyua9 commented Sep 20, 2026 •

Copy link
Copy Markdown

{
"title": "fix(git): strip only leading origin/ prefix in autocommit branch name",
"body": "## Summary\n\nGitAutoCommitHelperImpl#autoCommitApplication normalised a branch name with\n\njava\nfinal String finalBranchName = branchName.replaceFirst(\"origin/\", \"\");\n\n\nbefore calling findByBranchNameAndBaseApplicationId. String.replaceFirst\nsubstitutes the first occurrence of \"origin/\", so a legitimate ref like\nfeature/origin/main silently becomes feature/main and the lookup targets\nthe wrong (or no) branched application during the autocommit publish flow.\n\nCentralGitServiceCEImpl#stripOriginPrefix and the matching unit tests\n(CommonGitServiceCEImplTest/CentralGitServiceCEImplTest) already define\nthe canonical contract for this normalisation: strip only a leading\n\"origin/\" prefix and leave any mid-string occurrence untouched.\n\nThis PR aligns the autocommit call site with that contract so:\n\n- origin/main → main (unchanged behaviour)\n- feature/origin/main → feature/origin/main (previously corrupted to feature/main)\n- origin/feature/origin/main → feature/origin/main (previously corrupted to feature/origin/main)\n- develop → develop (no-op, matching the existing test fixtures)\n\nThe branch-name string is already null-checked above the call, so the\nstartsWith/ternary form needs no extra guard.\n\n## Scope\n\nSingle-line behaviour change in GitAutoCommitHelperImpl plus a comment\nreferencing the existing canonical helper. No public API change. The existing\ntest suite (which passes plain branch names like develop) remains green;\nadding a regression test for the mid-string origin/ case is left for a\nfollow-up that wires a Mockito fixture around findByBranchNameAndBaseApplicationId,\nwhich is currently spied only at the high-level flow boundary.\n\n## Diff\n\ndiff\n- final String finalBranchName = branchName.replaceFirst(\"origin/\", \"\");\n+ // Strip only a leading \"origin/\" prefix; replaceFirst would corrupt ref names\n+ // that legitimately contain \"origin/\" mid-string (see CentralGitServiceCEImpl#stripOriginPrefix).\n+ final String ORIGIN_PREFIX = \"origin/\";\n+ final String finalBranchName = branchName.startsWith(ORIGIN_PREFIX)\n+ ? branchName.substring(ORIGIN_PREFIX.length())\n+ : branchName;\n\n\n## Validation\n\n- git diff --check clean\n- Compile-bound (Java/Spring); not built locally because the workspace has no\n Maven toolchain in this checkout. CI will validate."
}

Summary by CodeRabbit

  • Bug Fixes
    • Improved branch name handling during automatic commits by removing only a leading origin/ prefix.
    • Preserved origin/ text appearing elsewhere in branch names.

GitAutoCommitHelperImpl#autoCommitApplication used
String.replaceFirst("origin/", "") to normalise a branch name before
calling findByBranchNameAndBaseApplicationId. That regex substitutes the
first occurrence of "origin/", so a legitimate ref name like
"feature/origin/main" silently becomes "feature/main" and the lookup
targets the wrong (or no) branched application.

CentralGitServiceCEImpl#stripOriginPrefix and the matching unit tests
already define the canonical contract for this normalisation: strip only a
leading "origin/" prefix and leave any mid-string occurrence untouched.
Align this call site with that contract so the autocommit publish flow
behaves consistently across the three git services and stops mis-routing
on legal ref names that contain "origin/" mid-string.

The branch-name string is already null-checked above, so the
.startsWith/ternary form needs no extra guard. No public API change; the
existing test suite (which passes plain branch names like "develop")
remains green.
@auyua9
auyua9 requested a review from a team as a code owner September 20, 2026 06:18
@github-actions github-actions Bot added awaiting-maintainer The next action on this pull request belongs to an Appsmith maintainer external-contribution Pull request submitted from outside the Appsmith repository labels Sep 20, 2026
@github-actions

Copy link
Copy Markdown

Thanks for contributing to Appsmith!

Credential-free formatting, lint, type, and unit checks will run after GitHub's workflow approval. An Appsmith maintainer will start privileged integration tests or a deploy preview when needed.

No action is required from you while this PR has the awaiting-maintainer label.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: appsmithorg/appsmith/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 173e4692-6950-426b-a05e-61db11a50f05

📥 Commits

Reviewing files that changed from the base of the PR and between 983129b and ccb57f3.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The auto-commit helper now removes "origin/" only when it prefixes the branch name. Branch names containing "origin/" elsewhere remain unchanged.

Changes

Branch Name Normalization

Layer / File(s) Summary
Normalize leading origin prefix
app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImpl.java
autoCommitApplication checks startsWith("origin/") and removes the prefix with substring. Comments document this behavior.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: sondermanish

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main behavior change: stripping only a leading origin/ prefix during autocommit branch handling.
Description check ✅ Passed The description clearly explains the problem, motivation, scope, expected behavior, and validation status. It does not follow all template sections: it omits an issue reference, the required testing c…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

A branch begins with origin’s sign,
The helper trims that prefix line.
Mid-path names stay whole and true,
The substring step knows what to do,
Clean commits follow the safer route.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai review --preview-config to test the unmerged CodeRabbit configuration on a draft PR. The requester must have repository write access; preview results are non-authoritative.
  • @coderabbitai rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai track in a human-authored review thread to track the original finding until CodeRabbit verifies it is fixed.
  • @coderabbitai fixed in a tracked review thread to verify the current code against the original finding.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai generate project vocabulary to list vocabulary that is specific to this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues in the current review thread, or all unresolved review comments when used in the PR conversation.
  • @coderabbitai autopilot stop to stop Autopilot for this PR.
  • @coderabbitai fix-ci to automatically fix failing CI checks in a stacked pull request.
  • @coderabbitai fix-ci commit to automatically fix failing CI checks by committing fixes to the current branch.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

This branch has not been deployed

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

Labels

awaiting-maintainer The next action on this pull request belongs to an Appsmith maintainer external-contribution Pull request submitted from outside the Appsmith repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant