mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 05:55:44 +01:00
do not collect the changesets for the whole branch, if only a git tag was pushed
This commit is contained in:
@@ -75,7 +75,7 @@ public class GitHookChangesetCollector
|
|||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs a new instance
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param rpack
|
* @param rpack
|
||||||
@@ -92,10 +92,9 @@ public class GitHookChangesetCollector
|
|||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Collect all new changesets from the received hook.
|
||||||
*
|
*
|
||||||
*
|
* @return new changesets
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public List<Changeset> collectChangesets()
|
public List<Changeset> collectChangesets()
|
||||||
{
|
{
|
||||||
@@ -114,17 +113,19 @@ public class GitHookChangesetCollector
|
|||||||
|
|
||||||
for (ReceiveCommand rc : receiveCommands)
|
for (ReceiveCommand rc : receiveCommands)
|
||||||
{
|
{
|
||||||
//J-
|
String ref = rc.getRefName();
|
||||||
logger.trace("handle receive command, type={}, ref={}, result={}",
|
|
||||||
new Object[] {
|
|
||||||
rc.getType(),
|
|
||||||
rc.getRefName(),
|
|
||||||
rc.getResult()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//J+
|
|
||||||
|
|
||||||
if (rc.getType() != ReceiveCommand.Type.DELETE)
|
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
|
try
|
||||||
{
|
{
|
||||||
@@ -138,13 +139,10 @@ public class GitHookChangesetCollector
|
|||||||
builder.append(rc.getType()).append(", ref=");
|
builder.append(rc.getType()).append(", ref=");
|
||||||
builder.append(rc.getRefName()).append(", result=");
|
builder.append(rc.getRefName()).append(", result=");
|
||||||
builder.append(rc.getResult());
|
builder.append(rc.getResult());
|
||||||
|
|
||||||
logger.error(builder.toString(), ex);
|
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());
|
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,
|
private void collectChangesets(Map<String, Changeset> changesets,
|
||||||
GitChangesetConverter converter, RevWalk walk, ReceiveCommand rc)
|
GitChangesetConverter converter, RevWalk walk, ReceiveCommand rc)
|
||||||
throws IncorrectObjectTypeException, IOException
|
throws IncorrectObjectTypeException, IOException
|
||||||
@@ -243,9 +229,7 @@ public class GitHookChangesetCollector
|
|||||||
/** listener to track new objects */
|
/** listener to track new objects */
|
||||||
private final CollectingPackParserListener listener;
|
private final CollectingPackParserListener listener;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private final List<ReceiveCommand> receiveCommands;
|
private final List<ReceiveCommand> receiveCommands;
|
||||||
|
|
||||||
/** Field description */
|
|
||||||
private final ReceivePack rpack;
|
private final ReceivePack rpack;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ package sonia.scm.repository;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
@@ -338,6 +339,20 @@ public final class GitUtil
|
|||||||
return branch;
|
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
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -92,6 +92,19 @@ public class GitUtilTest
|
|||||||
assertEquals("super/1.0.0", GitUtil.getTagName("refs/tags/super/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)
|
private org.eclipse.jgit.lib.Repository mockRepo(File directory)
|
||||||
{
|
{
|
||||||
org.eclipse.jgit.lib.Repository repo =
|
org.eclipse.jgit.lib.Repository repo =
|
||||||
|
|||||||
Reference in New Issue
Block a user