do not collect the changesets for the whole branch, if only a git tag was pushed

This commit is contained in:
Sebastian Sdorra
2016-09-28 14:52:18 +02:00
parent 8591ced68d
commit 9fad94403a
3 changed files with 45 additions and 33 deletions

View File

@@ -75,7 +75,7 @@ public class GitHookChangesetCollector
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
* Constructs a new instance
*
*
* @param rpack
@@ -92,10 +92,9 @@ public class GitHookChangesetCollector
//~--- methods --------------------------------------------------------------
/**
* Method description
* Collect all new changesets from the received hook.
*
*
* @return
* @return new changesets
*/
public List<Changeset> collectChangesets()
{
@@ -114,17 +113,19 @@ public class GitHookChangesetCollector
for (ReceiveCommand rc : receiveCommands)
{
//J-
logger.trace("handle receive command, type={}, ref={}, result={}",
new Object[] {
rc.getType(),
rc.getRefName(),
rc.getResult()
}
);
//J+
if (rc.getType() != ReceiveCommand.Type.DELETE)
String ref = rc.getRefName();
logger.trace("handle receive command, type={}, ref={}, result={}", rc.getType(), ref, rc.getResult());
if (rc.getType() == ReceiveCommand.Type.DELETE)
{
logger.debug("skip delete of ref {}", ref);
}
else if (! GitUtil.isBranch(ref))
{
logger.debug("skip ref {}, because it is not a branch", ref);
}
else
{
try
{
@@ -138,13 +139,10 @@ public class GitHookChangesetCollector
builder.append(rc.getType()).append(", ref=");
builder.append(rc.getRefName()).append(", result=");
builder.append(rc.getResult());
logger.error(builder.toString(), ex);
}
}
else
{
logger.debug("skip delete of branch {}", rc.getRefName());
}
}
}
@@ -161,18 +159,6 @@ public class GitHookChangesetCollector
return Lists.newArrayList(changesets.values());
}
/**
* Method description
*
*
* @param changesets
* @param converter
* @param walk
* @param rc
*
* @throws IOException
* @throws IncorrectObjectTypeException
*/
private void collectChangesets(Map<String, Changeset> changesets,
GitChangesetConverter converter, RevWalk walk, ReceiveCommand rc)
throws IncorrectObjectTypeException, IOException
@@ -243,9 +229,7 @@ public class GitHookChangesetCollector
/** listener to track new objects */
private final CollectingPackParserListener listener;
/** Field description */
private final List<ReceiveCommand> receiveCommands;
/** Field description */
private final ReceivePack rpack;
}

View File

@@ -36,6 +36,7 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
@@ -337,6 +338,20 @@ public final class GitUtil
return branch;
}
/**
* Returns {@code true} if the provided reference name is a branch name.
*
* @param refName reference name
*
* @return {@code true} if the name is a branch name
*
* @since 1.50
*/
public static boolean isBranch(String refName)
{
return Strings.nullToEmpty(refName).startsWith(PREFIX_HEADS);
}
/**
* Method description

View File

@@ -91,6 +91,19 @@ public class GitUtilTest
assertEquals("1.0.0", GitUtil.getTagName("refs/tags/1.0.0"));
assertEquals("super/1.0.0", GitUtil.getTagName("refs/tags/super/1.0.0"));
}
/**
* Tests {@link GitUtil#isBranch(java.lang.String)}.
*/
@Test
public void testIsBranchName(){
assertTrue(GitUtil.isBranch("refs/heads/master"));
assertTrue(GitUtil.isBranch("refs/heads/feature/super"));
assertFalse(GitUtil.isBranch(""));
assertFalse(GitUtil.isBranch(null));
assertFalse(GitUtil.isBranch("refs/tags/1.0.0"));
assertFalse(GitUtil.isBranch("refs/heads"));
}
private org.eclipse.jgit.lib.Repository mockRepo(File directory)
{