vignesh-manel opened a new pull request, #28629: URL: https://github.com/apache/camel/pull/28629
# Description https://issues.apache.org/jira/browse/CAMEL-26192 ## Problem 1. `GitProducer.doCheckout` always called `setCreateBranch(true)`, so the `checkout` operation could only create a branch: checking out a branch that already exists failed with `RefAlreadyExistsException`. 2. `GitCommitConsumer` set `CamelGitCommitId` to `commit.getId()`, which is the `RevCommit` itself. Its `String` form is `commit <sha> <time> -----sp`, not the sha, although `GitConstants` documents the header with `javaType = "String"`. Giving the header to the `cherryPick` operation, which reads it as a `String`, failed. 3. `commit` and `commitAll` discarded the `RevCommit` returned by JGit, so a route could not know the id of the commit it had just made. ## Change - `checkout` without a `tagName` creates the branch only when `refs/heads/<branchName>` does not exist, and otherwise checks out the existing branch. With a `tagName` it still always creates the branch from the tag, as before (checking out an existing branch at a tag would silently ignore the tag). - The commit consumer sets `CamelGitCommitId` to `commit.getName()`, the sha as a `String`. - The consumer also used this header value to skip the commits it had already consumed (`onPreProcessed` / `onProcessed` kept it only when it was an `ObjectId`). It now reads the sha back with `ObjectId.fromString`. Without that, each poll would deliver every commit again. - `commit` and `commitAll` set `CamelGitCommitId` to the sha of the new commit. The body is unchanged, as the endpoint's body-type metadata says for these operations. - The description of `CamelGitCommitId` in `GitConstants` says where the header is set and read; `git.json` is regenerated and copied to the catalog. - Upgrade guide: a *Breaking change* entry for the header type of the commit consumer, plus the new header of `commit`/`commitAll` and the `checkout` behaviour. New tests: - `GitProducerTest.checkoutExistingBranchTest`: creates the branch with `createBranch`, then checks it out. - `GitProducerTest.commitSetsCommitIdTest` and `commitAllOperationSetsCommitIdTest`: the header is the sha of the new commit. The second uses a new route with `operation=commitAll` (the existing `direct:commit-all` route uses `operation=commit`, so `commitAll` had no test). - `GitConsumerCommitTest.commitIdIsTheShaTest`: the header is the sha, and with a 2 s assert period (several polls) the commit is delivered only once. ## Verification (local, JDK 21, Maven 3.9.12) - Before the fix, all 4 new tests failed: `RefAlreadyExistsException: Ref testBranch already exists`, `expected: <sha> but was: <null>` (twice), and `expected: <sha> but was: <commit sha 1793186035 -----sp>`. - After the fix: `GitProducerTest` (38) and `GitConsumerCommitTest` (2) pass. - Mutation: keeping the old `instanceof ObjectId` check in `onProcessed` makes `commitIdIsTheShaTest` fail with `Expected: <1> but was: <4>` (the commit delivered again on each poll). The existing `commitConsumerTest` does not catch that. - `GitConsumerTest` (4) errors locally in its setup, on this branch and on unchanged main alike: its route loads a git config file from gist.githubusercontent.com, and the JVM gets `java.net.ConnectException: Operation timed out` on this machine. I left it to CI. `GitRemoteProducerTest` is skipped. - `mvn install -Psourcecheck -DskipTests` passes in `components/camel-git`, with no uncommitted changes afterwards. The catalog `git.json` is a byte-identical copy of the component one, as on main. # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. _Not from the root: I built `components/camel-git` with `-Psourcecheck`, and copied the regenerated `git.json` to the catalog (the catalog module could not resolve its dependencies locally). CI's uncommitted-changes check covers the rest._ # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. _Claude Code on behalf of vignesh-manel_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
