Skip to content

fix(git): strip only leading origin prefix#41793

Open
haimingZZ wants to merge 2 commits into
appsmithorg:releasefrom
haimingZZ:fix/origin-prefix-strip-haimingzz
Open

fix(git): strip only leading origin prefix#41793
haimingZZ wants to merge 2 commits into
appsmithorg:releasefrom
haimingZZ:fix/origin-prefix-strip-haimingzz

Conversation

@haimingZZ
Copy link
Copy Markdown

@haimingZZ haimingZZ commented May 12, 2026

Description

Tip

TL;DR — Completes the origin/ prefix-normalization follow-up from #41758 so branch names that contain origin/ after the prefix are not corrupted.

Related to #41758.

#41758 introduced stripOriginPrefix(...) in CentralGitServiceCEImpl because replaceFirst(ORIGIN, "") can remove origin/ from the middle of a ref name. Its follow-up notes called out the remaining Central/Common service sites for a separate sweep.

This PR applies the same anchored-prefix behavior to the remaining CentralGitServiceCEImpl and CommonGitServiceCEImpl paths that were still using replaceFirst(ORIGIN, "") or replace(ORIGIN, ""). For example:

  • origin/feature/origin/main still normalizes to feature/origin/main
  • feature/origin/main stays feature/origin/main

It also adds focused unit coverage for the shared helper behavior in both service packages.

Automation

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Tests

  • git diff --check
  • Not run locally: mvn -pl appsmith-server -Dtest=CentralGitServiceCEImplTest,CommonGitServiceCEImplTest -DskipITs test because this environment does not have mvn installed.

Summary by CodeRabbit

  • Refactor

    • Consolidated git branch reference normalization for consistent handling across checkouts, branch creation, repository re-cloning/enumeration, and merges; normalization now robustly handles nulls and only removes leading remote prefixes.
  • Tests

    • Added unit tests covering reference name normalization, including leading-remote removal, non-leading occurrences, and null inputs.

Review Change Stack

@haimingZZ haimingZZ requested a review from a team as a code owner May 12, 2026 04:47
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c1408700-f0fb-4fb0-821a-4b0d631452a7

📥 Commits

Reviewing files that changed from the base of the PR and between 571486d and 2fe167c.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java

Walkthrough

Consolidates origin/ prefix stripping into a package-private static stripOriginPrefix() helper and replaces inline replaceFirst(...) calls in both CentralGitServiceCEImpl and CommonGitServiceCEImpl; adds unit tests validating the helper.

Changes

Git Reference Normalization Consolidation

Layer / File(s) Summary
Helper method definition and constant cleanup
src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java, src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java
Introduces stripOriginPrefix(String) as a static package-private helper (returns "" for null) and removes the REMOTE_NAME_REPLACEMENT constant from the central service.
CentralGitServiceCEImpl call site updates
src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
Updates checkout reference, remote checkout, ref-creation duplicate check, repo re-fetch/branch enumeration, and merge commit message construction to use stripOriginPrefix().
CommonGitServiceCEImpl call site updates
src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java
Updates checkoutBranch, checkoutRemoteBranch, duplicate-name check in createBranch, merge destination reconstruction, and repo rehydration to normalize branch names via stripOriginPrefix().
Unit tests for stripOriginPrefix
src/test/java/com/appsmith/server/git/central/CentralGitServiceCEImplTest.java, src/test/java/com/appsmith/server/git/common/CommonGitServiceCEImplTest.java
Adds tests asserting that only a leading origin/ segment is stripped, non-leading occurrences remain, and null yields an empty string.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Origin once prefixed each trail,
Now trimmed by a helper's tale.
Central and Common sing the rhyme,
Tests confirm the strip is fine,
Small change, tidy branch time. 🎋

🚥 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%. 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 summarizes the main change: fixing git prefix stripping to only target leading origin prefixes.
Description check ✅ Passed The description covers the purpose, context (related to #41758), specific examples of the fix, and mentions test coverage, following most template requirements despite missing explicit issue link.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java (1)

2913-2916: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use leading-prefix strip here to avoid branch-name corruption

This path still strips all origin/ occurrences via replace, so origin/feature/origin/main becomes feature/main. It should only remove a leading prefix.

Suggested fix
-                                String branchName = gitBranchDTO.getBranchName().replace("origin/", "");
+                                String branchName = stripOriginPrefix(gitBranchDTO.getBranchName());
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java`
around lines 2913 - 2916, The code in CommonGitServiceCEImpl uses
gitBranchDTO.getBranchName().replace("origin/", "") which removes every
occurrence of "origin/" instead of only the leading prefix; change this to strip
only a leading "origin/" (e.g., use replaceFirst("^origin/", "") or substring
after checking startsWith, or StringUtils.removeStart) when computing branchName
so inputs like "origin/feature/origin/main" become "feature/origin/main" and not
"feature/main".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java`:
- Around line 2913-2916: The code in CommonGitServiceCEImpl uses
gitBranchDTO.getBranchName().replace("origin/", "") which removes every
occurrence of "origin/" instead of only the leading prefix; change this to strip
only a leading "origin/" (e.g., use replaceFirst("^origin/", "") or substring
after checking startsWith, or StringUtils.removeStart) when computing branchName
so inputs like "origin/feature/origin/main" become "feature/origin/main" and not
"feature/main".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ed73c785-49d8-4cbe-bc85-38ac7ec62fed

📥 Commits

Reviewing files that changed from the base of the PR and between 893572e and 571486d.

📒 Files selected for processing (4)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/git/common/CommonGitServiceCEImpl.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/central/CentralGitServiceCEImplTest.java
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/common/CommonGitServiceCEImplTest.java

@haimingZZ
Copy link
Copy Markdown
Author

Follow-up pushed: 2fe167c.

Addressed the CodeRabbit finding by changing the remaining branch-listing call site in CommonGitServiceCEImpl to use stripOriginPrefix(...), so only a leading origin/ segment is removed and branch names like origin/feature/origin/main normalize to feature/origin/main.

Validation:

git diff --check

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