Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65032

hudson.scm.ChangeLogSet doesn't incluide merge commits

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • git-client-plugin
    • None
    • Jenkins 2.282

      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?

       

            Unassigned Unassigned
            codependent Jose A. Iñigo
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: