Commits

Sebastian Sdorra committed 1f1cae0

use always the branch informations from the receivecommand

  • Participants
  • Parent commits 0aba7e5
  • Branches issue-242

Comments (0)

Files changed (2)

File scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetConverter.java

 
 //~--- non-JDK imports --------------------------------------------------------
 
+import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
 
 import org.eclipse.jgit.diff.DiffEntry;
    * Method description
    *
    *
-   *
    * @param commit
    *
    * @return
    */
   public Changeset createChangeset(RevCommit commit) throws IOException
   {
+    List<String> branches = Lists.newArrayList();
+    Set<Ref> refs = repository.getAllRefsByPeeledObjectId().get(commit.getId());
+
+    if (Util.isNotEmpty(refs))
+    {
+
+      for (Ref ref : refs)
+      {
+        String branch = GitUtil.getBranch(ref);
+
+        if (branch != null)
+        {
+          branches.add(branch);
+        }
+      }
+
+    }
+
+    return createChangeset(commit, branches);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   *
+   * @param commit
+   * @param branches
+   *
+   * @return
+   *
+   * @throws IOException
+   */
+  public Changeset createChangeset(RevCommit commit, List<String> branches)
+    throws IOException
+  {
     String id = commit.getId().abbreviate(idLength).name();
     List<String> parentList = null;
     RevCommit[] parents = commit.getParents();
       changeset.getTags().addAll(tagCollection);
     }
 
-    Set<Ref> refs = repository.getAllRefsByPeeledObjectId().get(commit.getId());
-
-    if (Util.isNotEmpty(refs))
-    {
-
-      for (Ref ref : refs)
-      {
-        String branch = GitUtil.getBranch(ref);
-
-        if (branch != null)
-        {
-          changeset.getBranches().add(branch);
-        }
-      }
-
-    }
+    changeset.setBranches(branches);
 
     return changeset;
   }

File scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java

     org.eclipse.jgit.lib.Repository repository = rpack.getRepository();
 
     RevWalk walk = null;
-    
+
     GitChangesetConverter converter = null;
 
     try
     {
       walk = rpack.getRevWalk();
-      converter = new GitChangesetConverter(repository, walk, GitUtil.ID_LENGTH);
+      converter = new GitChangesetConverter(repository, walk,
+        GitUtil.ID_LENGTH);
 
       for (ReceiveCommand rc : receiveCommands)
       {
 
         RevCommit commit = walk.next();
 
+        List<String> branches = Lists.newArrayList(branch);
+
         while (commit != null)
         {
+
           // parse commit body to avoid npe
           walk.parseBody(commit);
-          Changeset changeset = converter.createChangeset(commit);
 
-          List<String> branches = changeset.getBranches();
+          Changeset changeset = converter.createChangeset(commit, branches);
 
-          if (branches.isEmpty())
+          if (logger.isTraceEnabled())
           {
-            if (logger.isTraceEnabled())
-            {
-              //J-
-                logger.trace(
-                  "missing branch informations for {}, set default branch {}",
-                  changeset.getId(),
-                  branch
-                );
-                //J+
-            }
-
-            branches.add(branch);
+            logger.trace("retrive commit {} for hook", changeset.getId());
           }
 
           changesets.add(changeset);