mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-22 16:29:51 +01:00
retrieve branch informations from receive command
This commit is contained in:
@@ -36,6 +36,7 @@ package sonia.scm.repository;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
import org.eclipse.jgit.lib.Ref;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.revwalk.RevSort;
|
import org.eclipse.jgit.revwalk.RevSort;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
@@ -44,6 +45,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -72,14 +74,16 @@ public class GitRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param directory
|
* @param directory
|
||||||
|
* @param ref
|
||||||
* @param newId
|
* @param newId
|
||||||
* @param oldId
|
* @param oldId
|
||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
public GitRepositoryHookEvent(File directory, ObjectId newId, ObjectId oldId,
|
public GitRepositoryHookEvent(File directory, Ref ref, ObjectId newId,
|
||||||
RepositoryHookType type)
|
ObjectId oldId, RepositoryHookType type)
|
||||||
{
|
{
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
|
this.defaultBranch = GitUtil.getBranch(ref);
|
||||||
this.newId = newId;
|
this.newId = newId;
|
||||||
this.oldId = oldId;
|
this.oldId = oldId;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -152,7 +156,21 @@ public class GitRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
|
|
||||||
while (commit != null)
|
while (commit != null)
|
||||||
{
|
{
|
||||||
result.add(converter.createChangeset(commit));
|
Changeset changeset = converter.createChangeset(commit);
|
||||||
|
|
||||||
|
if (changeset.getBranches().isEmpty()
|
||||||
|
&& Util.isNotEmpty(defaultBranch))
|
||||||
|
{
|
||||||
|
if (logger.isTraceEnabled())
|
||||||
|
{
|
||||||
|
logger.trace("set branch to current default branch {}",
|
||||||
|
defaultBranch);
|
||||||
|
}
|
||||||
|
|
||||||
|
changeset.getBranches().add(defaultBranch);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.add(changeset);
|
||||||
commit = walk.next();
|
commit = walk.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,6 +194,9 @@ public class GitRepositoryHookEvent extends AbstractRepositoryHookEvent
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
private List<Changeset> changesets;
|
private List<Changeset> changesets;
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private String defaultBranch;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private File directory;
|
private File directory;
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,9 @@ public class GitUtil
|
|||||||
{
|
{
|
||||||
String branch = null;
|
String branch = null;
|
||||||
|
|
||||||
|
if (ref != null)
|
||||||
|
{
|
||||||
|
|
||||||
String name = ref.getName();
|
String name = ref.getName();
|
||||||
|
|
||||||
if (name.startsWith(PREFIX_HEADS))
|
if (name.startsWith(PREFIX_HEADS))
|
||||||
@@ -231,6 +234,8 @@ public class GitUtil
|
|||||||
branch = name.substring(PREFIX_HEADS.length());
|
branch = name.substring(PREFIX_HEADS.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return branch;
|
return branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +255,9 @@ public class GitUtil
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
ObjectId branchId = null;
|
ObjectId branchId = null;
|
||||||
if ( ! branchName.startsWith(REF_HEAD) ){
|
|
||||||
|
if (!branchName.startsWith(REF_HEAD))
|
||||||
|
{
|
||||||
branchName = PREFIX_HEADS.concat(branchName);
|
branchName = PREFIX_HEADS.concat(branchName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
|
|||||||
* @param refName
|
* @param refName
|
||||||
*/
|
*/
|
||||||
private void executeFileHook(ReceivePack rpack, ReceiveCommand rc,
|
private void executeFileHook(ReceivePack rpack, ReceiveCommand rc,
|
||||||
File repositoryDirectory, File hook,
|
File repositoryDirectory, File hook, ObjectId oldId, ObjectId newId,
|
||||||
ObjectId oldId, ObjectId newId, String refName)
|
String refName)
|
||||||
{
|
{
|
||||||
final Command cmd = new SimpleCommand(hook.getAbsolutePath(), getId(oldId),
|
final Command cmd = new SimpleCommand(hook.getAbsolutePath(), getId(oldId),
|
||||||
getId(newId), Util.nonNull(refName));
|
getId(newId), Util.nonNull(refName));
|
||||||
@@ -199,11 +199,7 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description, ccurred
|
* Method description, occurred
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* @param rpack
|
* @param rpack
|
||||||
* @param rc
|
* @param rc
|
||||||
@@ -213,15 +209,14 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
|
|||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
private void fireHookEvent(ReceivePack rpack, ReceiveCommand rc,
|
private void fireHookEvent(ReceivePack rpack, ReceiveCommand rc,
|
||||||
File directory, ObjectId oldId, ObjectId newId,
|
File directory, ObjectId oldId, ObjectId newId, RepositoryHookType type)
|
||||||
RepositoryHookType type)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String repositoryName = RepositoryUtil.getRepositoryName(handler,
|
String repositoryName = RepositoryUtil.getRepositoryName(handler,
|
||||||
directory);
|
directory);
|
||||||
GitRepositoryHookEvent e = new GitRepositoryHookEvent(directory, newId,
|
GitRepositoryHookEvent e = new GitRepositoryHookEvent(directory,
|
||||||
oldId, type);
|
rc.getRef(), newId, oldId, type);
|
||||||
|
|
||||||
repositoryManager.fireHookEvent(GitRepositoryHandler.TYPE_NAME,
|
repositoryManager.fireHookEvent(GitRepositoryHandler.TYPE_NAME,
|
||||||
repositoryName, e);
|
repositoryName, e);
|
||||||
@@ -250,8 +245,7 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
|
|||||||
* @param type
|
* @param type
|
||||||
*/
|
*/
|
||||||
private void onReceive(ReceivePack rpack,
|
private void onReceive(ReceivePack rpack,
|
||||||
Collection<ReceiveCommand> receiveCommands,
|
Collection<ReceiveCommand> receiveCommands, RepositoryHookType type)
|
||||||
RepositoryHookType type)
|
|
||||||
{
|
{
|
||||||
for (ReceiveCommand rc : receiveCommands)
|
for (ReceiveCommand rc : receiveCommands)
|
||||||
{
|
{
|
||||||
@@ -325,8 +319,7 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
|
|||||||
*/
|
*/
|
||||||
private File getHookScript(File directory, String name)
|
private File getHookScript(File directory, String name)
|
||||||
{
|
{
|
||||||
File baseFile =
|
File baseFile = new File(directory,
|
||||||
new File(directory,
|
|
||||||
FILE_HOOKDIRECTORY.concat(File.separator).concat(name));
|
FILE_HOOKDIRECTORY.concat(File.separator).concat(name));
|
||||||
|
|
||||||
return IOUtil.getScript(baseFile);
|
return IOUtil.getScript(baseFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user