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

hudson.scm.ChangeLogSet doesn't incluide merge commits

    • 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?

       

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

          Mark Waite added a comment -

          I'm not willing to consider changing from whatchanged to log unless there is a compatibility switch that allows the user to return to the previous behavior. Many users develop deep and unexpected dependencies on specific behaviors (like skipping merge commits).

          If you'd like to experiment with previous attempts to replace whatchanged with log, refer to PR-237 and PR-445. You could start with those changes in a development version of the plugin, confirm that they meet your needs, and open a new pull request that addresses the request for changes in those pull requests.

          Mark Waite added a comment - I'm not willing to consider changing from whatchanged to log unless there is a compatibility switch that allows the user to return to the previous behavior. Many users develop deep and unexpected dependencies on specific behaviors (like skipping merge commits). If you'd like to experiment with previous attempts to replace whatchanged with log , refer to PR-237 and PR-445 . You could start with those changes in a development version of the plugin, confirm that they meet your needs, and open a new pull request that addresses the request for changes in those pull requests.

          Rail added a comment - - edited

          markewaite changelog for JGitAPIImpl has following comment:

          // git whatachanged doesn't show the merge commits unless -m is given 

          It would be great if we can control this when building ChangeLogCommand:

                      @Override
                      public void includeMergeCommits(Boolean bool) {
                          this.includeMergeCommits = includeMerges;
                      }
          ...
                              for (RevCommit commit : walk) {
                                  if (!includeMergeCommits && commit.getParentCount() > 1) {
                                      continue;
                                  }                        formatter.format(commit, null, pw, true);
                              }

          Please let me know if it can be done as simple as I see it or am I missing something?

          Rail added a comment - - edited markewaite changelog for JGitAPIImpl  has following comment: // git whatachanged doesn't show the merge commits unless -m is given It would be great if we can control this when building ChangeLogCommand:           @Override             public void includeMergeCommits( Boolean bool) {                 this .includeMergeCommits = includeMerges;             } ...                   for (RevCommit commit : walk) {                         if (!includeMergeCommits && commit.getParentCount() > 1) {                             continue ;                         }                        formatter.format(commit, null , pw, true );                     } Please let me know if it can be done as simple as I see it or am I missing something?

          Mark Waite added a comment - - edited

          I am sure that you are missing something, but the things that are missing may be relatively easy.  Some of the things that are needed:

          • Command line git implementation and matching online help including sample Pipeline code
          • JGit implementation and matching online help including sample Pipeline code
          • Automated tests that confirm both JGit and command line git implementations work
          • Automated tests that confirm the current behavior is retained
          • Documentation of the new implementation in the README, including sample Pipeline code

          Mark Waite added a comment - - edited I am sure that you are missing something, but the things that are missing may be relatively easy.  Some of the things that are needed: Command line git implementation and matching online help including sample Pipeline code JGit implementation and matching online help including sample Pipeline code Automated tests that confirm both JGit and command line git implementations work Automated tests that confirm the current behavior is retained Documentation of the new implementation in the README, including sample Pipeline code

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

              Created:
              Updated: