jenkinsci / jenkinsci/git-client-plugin

[JENKINS-65032] hudson.scm.ChangeLogSet doesn't incluide merge commits

Open
#1,634 3 comments 0 reactions 0 assignees View on GitHub
component:git-client-plugin imported-jira-issue priority:major resolution:unresolved
Dominant language
Java
Stars
152
Forks
402
Avg merge
6h 47m
Merged PRs (30d)
4

Description

I'm developing a Jenkins Plugin that provides a pipeline step. When this step is executed in the pipeline it looks for all commit messages of the current project between the last and the previous one:

override fun getCommitMessages(context: StepContext, commitInfo: MapString?>): Set<String> {

val taskListener = context.get(TaskListener::class.java)!!
val run = context.get(Run::class.java)
var workflowRun = run as WorkflowRun?
val hasChanges = commitInfo[PREVIOUS_COMMIT] != commitInfo[LAST_COMMIT]
var foundPreviousCommit = false
val commits = mutableSetOf<String>()

while(hasChanges && !foundPreviousCommit && workflowRun != null){
workflowRun.changeSets.forEach { it ->
val latestCommits = mutableSetOf<String>()
it?.items?.forEach {
it as GitChangeSet
taskListener.logger.println("changeset commit id: ${it.id}")
if (it.id == commitInfo[PREVIOUS_COMMIT]){
taskListener.logger.println("found previous commit: ${it.id}")
foundPreviousCommit = true
} else {
latestCommits.add(it.msg)
}
}
if(!foundPreviousCommit) {
taskListener.logger.println("adding changeset commits: $latestCommits")
commits.addAll(latestCommits)
}
}
workflowRun = workflowRun?.previousBuild
}


Suppose I have this commit history:

The previous commit was IA-1 msg, and the last one, IA-7, so I was expecting to have commits IA-2, IA-3, IA-4, IA-5, IA-6, IA-7 included in the changeset. However IA-6, which is a merge commit is missing.

This is what I've seen debugging:

 

changeSets contains 5 elements, corresponding to commits IA-2, IA-3, IA-4, IA-5, IA-7

IA-6 is missing:

 

IA-7 correctly indicates parentCommit=8a4f204c1abfbac9864502dcd96d26716a754add, which would be the one with message IA-6

That commit should also be included in the changeSet collection.

I kept digging into this finding that the changelog is loaded in

CliGitAPIImpl -> changelog() -> execute()

Here it uses the whatchanged command:

git whatchanged --no-abbrev -M "format=commit %H%ntree %T%nparent %P%nauthor %aN <%aE> %ai%ncommitter %cN <%cE> %ci%n%n%w(0,4,4)%B" -n 1024

According to Git's documentation:

```
Shows commit logs and diff output each commit introduces.
New users are encouraged to use git-log[1] instead. The whatchanged command is essentially the same as git-log[1] but defaults to show the raw format diff output and to skip merges.
The command is kept primarily for historical reasons; fingers of many people who learned Git long before git log was invented by reading Linux kernel mailing list are trained to type it.
```

whatchanged skips merge information

Would you consider changing this to use git log instead, and thus, include all commits including the merge ones?

 

---
Originally reported by codependent, imported from: hudson.scm.ChangeLogSet doesn't incluide merge commits


  • status: Open
  • priority: Major
  • component(s): git-client-plugin
  • resolution: Unresolved
  • votes: 1
  • watchers: 4
  • imported: 20251211-071809

Raw content of original issue

I'm developing a Jenkins Plugin that provides a pipeline step. When this step is executed in the pipeline it looks for all commit messages of the current project between the last and the previous one:



override fun getCommitMessages(context: StepContext, commitInfo: Map<Commit, String?>): Set<String> {

val taskListener = context.get(TaskListener::class.java)!!
val run = context.get(Run::class.java)
var workflowRun = run as WorkflowRun?
val hasChanges = commitInfo[PREVIOUS_COMMIT] != commitInfo[LAST_COMMIT]
var foundPreviousCommit = false
val commits = mutableSetOf<String>()

while(hasChanges && !foundPreviousCommit && workflowRun != null){
workflowRun.changeSets.forEach { it ->
val latestCommits = mutableSetOf<String>()
it?.items?.forEach {
it as GitChangeSet
taskListener.logger.println("changeset commit id: ${it.id}")
if (it.id == commitInfo[PREVIOUS_COMMIT]){
taskListener.logger.println("found previous commit: ${it.id}")
foundPreviousCommit = true
} else {
latestCommits.add(it.msg)
}
}
if(!foundPreviousCommit) {
taskListener.logger.println("adding changeset commits: $latestCommits")
commits.addAll(latestCommits)
}
}
workflowRun = workflowRun?.previousBuild
}



Suppose I have this commit history:

The previous commit was IA-1 msg, and the last one, IA-7, so I was expecting to have commits IA-2, IA-3, IA-4, IA-5, IA-6, IA-7 included in the changeset. However IA-6, which is a merge commit is missing.

This is what I've seen debugging:

 

changeSets contains 5 elements, corresponding to commits IA-2, IA-3, IA-4, IA-5, IA-7

IA-6 is missing:

 

IA-7 correctly indicates parentCommit=8a4f204c1abfbac9864502dcd96d26716a754add, which would be the one with message IA-6

That commit should also be included in the changeSet collection.

I kept digging into this finding that the changelog is loaded in



CliGitAPIImpl -> changelog() -> execute()


Here it uses the whatchanged command:



git whatchanged --no-abbrev -M "format=commit %H%ntree %T%nparent %P%nauthor %aN <%aE> %ai%ncommitter %cN <%cE> %ci%n%n%w(0,4,4)%B" -n 1024


According to Git's documentation:



Shows commit logs and diff output each commit introduces.

New users are encouraged to use git-log[1] instead. The whatchanged command is essentially the same as git-log[1] but defaults to show the raw format diff output and to skip merges.
The command is kept primarily for historical reasons; fingers of many people who learned Git long before git log was invented by reading Linux kernel mailing list are trained to type it.


whatchanged skips merge information

Would you consider changing this to use git log instead, and thus, include all commits including the merge ones?

 

  • environment: Jenkins 2.282

3 attachments

- [image-2021-03-05-10-16-41-222.png](https://issues.jenkins.io/secure/attachment/54138/image-2021-03-05-10-16-41-222.png)
> ![image-2021-03-05-10-16-41-222.png](https://issues.jenkins.io/secure/attachment/54138/image-2021-03-05-10-16-41-222.png)
- [image-2021-03-05-11-50-38-886.png](https://issues.jenkins.io/secure/attachment/54137/image-2021-03-05-11-50-38-886.png)
> ![image-2021-03-05-11-50-38-886.png](https://issues.jenkins.io/secure/attachment/54137/image-2021-03-05-11-50-38-886.png)
- [image-2021-03-05-11-53-41-182.png](https://issues.jenkins.io/secure/attachment/54136/image-2021-03-05-11-53-41-182.png)
> ![image-2021-03-05-11-53-41-182.png](https://issues.jenkins.io/secure/attachment/54136/image-2021-03-05-11-53-41-182.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.