HarshMehta112 commented on issue #1391:
URL: https://github.com/apache/maven-release/issues/1391#issuecomment-3605444464

   @kwin  I got your point. 
   ## Solution
   
   A new phase `ScmCheckRemoteSyncPhase` has been added to the beginning of the 
prepare phase sequence (right after `check-poms`). This phase:
   
   1. **Checks if push is enabled** - Only runs when `pushChanges` is `true` 
(default)
   2. **Detects unpulled commits** - Fails fast if the remote branch has 
commits that haven't been pulled locally
   3. **Warns about unpushed commits** - Provides information about local 
commits that will be pushed
   4. **Provider-specific implementation** - Currently fully implemented for 
Git, with graceful degradation for other SCM providers
   
   ## How It Works
   
   ### For Git Repositories
   
   The phase executes the following Git commands:
   
   1. `git rev-parse --abbrev-ref HEAD` - Gets the current branch name
   2. `git remote update` - Fetches remote repository information without 
merging
   3. `git rev-parse --abbrev-ref <branch>@{upstream}` - Gets the remote 
tracking branch
   4. `git rev-list --count HEAD..<remote>` - Counts unpulled commits (remote 
ahead of local)
   5. `git rev-list --count <remote>..HEAD` - Counts unpushed commits (local 
ahead of remote)
   
   ### Failure Conditions
   
   The release will **fail immediately** if:
   - The local branch is behind the remote branch (unpulled commits exist)
   
   ### Warning Conditions
   
   The release will **continue with a warning** if:
   - The local branch has unpushed commits (these will be pushed at the end)
   
   ## Configuration
   
   No additional configuration is required. The feature respects the existing 
`pushChanges` parameter:
   
   ```xml
   <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-release-plugin</artifactId>
       <configuration>
           <!-- Enable/disable the remote sync check -->
           <pushChanges>true</pushChanges>  <!-- default: true -->
       </configuration>
   </plugin>
   ```
   
   Or via command line:
   ```bash
   mvn release:prepare -DpushChanges=false  # Skips remote sync check
   ```
   
   ## Limitations
   
   - **Git-specific**: Full implementation only available for Git repositories
   - **Requires Git installed**: The phase executes Git commands via 
ProcessBuilder
   - **Network dependency**: Requires network access to fetch remote information
   - **Race condition**: There's a small time window between the check and the 
actual push where new commits could be added remotely
   
   Let me know if I can proceed with a PR. Thanks!
   


-- 
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]

Reply via email to