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

JGit changelog max limit not working well with merge commits

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • git-client-plugin
    • None

      git-client version 2.1.0
      Jgit changelog does not work well when setting max revisions limit, if the revisions containt merge commits.
      That is because RevWalker will only return the number of revision as set by limitations, but ChangelogCommand default behaviour is to skip merge commits. Resulting in returning less commits then requested by the user.
      This can be seen by the below test case (for GitApiTestCase class) where JGit returns empty changelog if the head commit is a merge commit, and max limit was set to 1. The test will pass if the max limit is increased to 2.

          public void test_changelog_with_merge_commit_and_max_log_history() throws Exception {
              w.init();
              w.commitEmpty("init");
      
              // First commit to branch1
              w.git.branch("branch1");
              w.git.checkout("branch1");
              w.touch("file1", "content1");
              w.git.add("file1");
              w.git.commit("commit1");
              String commitSha1 = w.git.revParse("HEAD").name();
      
              // Merge branch1 into master
              w.git.checkout("master");
              String mergeMessage = "Merge message to be tested.";
              w.git.merge().setMessage(mergeMessage).setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.NO_FF).setRevisionToMerge(w.git.getHeadRev(w.repoPath(), "branch1")).execute();
              StringWriter writer = new StringWriter();
              w.git.changelog().max(1).to(writer).execute(); // Changing max limit to 2 will pass the test
              assertThat(writer.toString(),not(isEmptyString()));
          }
      
      

          [JENKINS-40023] JGit changelog max limit not working well with merge commits

          tzafrir created issue -
          tzafrir made changes -
          Description Original: git-client version 2.1.0
          Adding the below test case in GitAPITestCase.java fails with JGit but passes with CliGit.
          For JGit it seems that after RevWalker check the merge commit at HEAD, it finds no prior commits to list and show in the changelog.
          Whereas the CliGit does find the commit with the message "commit1" and returns it's SHA1

          {code}
              public void test_changelog_with_merge_commit() throws Exception {
                  w.init();
                  w.commitEmpty("init");

                  // First commit to branch1
                  w.git.branch("branch1");
                  w.git.checkout("branch1");
                  w.touch("file1", "content1");
                  w.git.add("file1");
                  w.git.commit("commit1");
                  String commitSha1 = w.git.revParse("HEAD").name();

                  // Merge branch1 into master
                  w.git.checkout("master");
                  String mergeMessage = "Merge message to be tested.";
                  w.git.merge().setMessage(mergeMessage).setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.NO_FF).setRevisionToMerge(w.git.getHeadRev(w.repoPath(), "branch1")).execute();
                  // Obtain last commit message
                  String mergeSha1 = w.git.revParse("HEAD").name();
                  check_changelog_sha1(commitSha1, "master");
              }
          {code}
          New: git-client version 2.1.0
          Jgit changelog does not work well when setting max revisions limit, if the revisions containt merge commits.
          That is because RevWalker will only return the number of revision as set by limitations, but ChangelogCommand default behaviour is to skip merge commits. Resulting in returning less commits then requested by the user.
          This can be seen by the below test case (for GitApiTestCase class) where JGit returns empty changelog if the head commit is a merge commit, and max limit was set to 1. The test will pass if the max limit is increased to 2.

          {code}
              public void test_changelog_with_merge_commit_and_max_log_history() throws Exception {
                  w.init();
                  w.commitEmpty("init");

                  // First commit to branch1
                  w.git.branch("branch1");
                  w.git.checkout("branch1");
                  w.touch("file1", "content1");
                  w.git.add("file1");
                  w.git.commit("commit1");
                  String commitSha1 = w.git.revParse("HEAD").name();

                  // Merge branch1 into master
                  w.git.checkout("master");
                  String mergeMessage = "Merge message to be tested.";
                  w.git.merge().setMessage(mergeMessage).setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.NO_FF).setRevisionToMerge(w.git.getHeadRev(w.repoPath(), "branch1")).execute();
                  StringWriter writer = new StringWriter();
                  w.git.changelog().max(1).to(writer).execute(); // Changing max limit to 2 will pass the test
                  assertThat(writer.toString(),not(isEmptyString()));
              }

          {code}
          tzafrir made changes -
          Summary Original: JGit changelog list no changes prior to merge commit New: JGit changelog max limit not working well with merge commits
          Mark Waite made changes -
          Assignee Original: Mark Waite [ markewaite ]

            Unassigned Unassigned
            tzafrir11 tzafrir
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: