mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-31 20:59:47 +01:00
merge 2.0.0-m3
This commit is contained in:
@@ -4,5 +4,5 @@ import org.eclipse.jgit.lib.Repository;
|
||||
import sonia.scm.repository.spi.GitContext;
|
||||
import sonia.scm.repository.util.WorkdirFactory;
|
||||
|
||||
public interface GitWorkdirFactory extends WorkdirFactory<Repository, GitContext> {
|
||||
public interface GitWorkdirFactory extends WorkdirFactory<Repository, Repository, GitContext> {
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class AbstractGitCommand
|
||||
}
|
||||
|
||||
<R, W extends GitCloneWorker<R>> R inClone(Function<Git, W> workerSupplier, GitWorkdirFactory workdirFactory, String initialBranch) {
|
||||
try (WorkingCopy<Repository> workingCopy = workdirFactory.createWorkingCopy(context, initialBranch)) {
|
||||
try (WorkingCopy<Repository, Repository> workingCopy = workdirFactory.createWorkingCopy(context, initialBranch)) {
|
||||
Repository repository = workingCopy.getWorkingRepository();
|
||||
logger.debug("cloned repository to folder {}", repository.getWorkTree());
|
||||
return workerSupplier.apply(new Git(repository)).run();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class GitBranchCommand extends AbstractGitCommand implements BranchComman
|
||||
|
||||
@Override
|
||||
public Branch branch(BranchRequest request) {
|
||||
try (WorkingCopy<org.eclipse.jgit.lib.Repository> workingCopy = workdirFactory.createWorkingCopy(context, request.getParentBranch())) {
|
||||
try (WorkingCopy<org.eclipse.jgit.lib.Repository, org.eclipse.jgit.lib.Repository> workingCopy = workdirFactory.createWorkingCopy(context, request.getParentBranch())) {
|
||||
Git clone = new Git(workingCopy.getWorkingRepository());
|
||||
Ref ref = clone.branchCreate().setName(request.getNewBranch()).call();
|
||||
Iterable<PushResult> call = clone.push().add(request.getNewBranch()).call();
|
||||
|
||||
@@ -106,7 +106,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Changeset getChangeset(String revision)
|
||||
public Changeset getChangeset(String revision, LogCommandRequest request)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -131,7 +131,18 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
if (commit != null)
|
||||
{
|
||||
converter = new GitChangesetConverter(gr, revWalk);
|
||||
changeset = converter.createChangeset(commit);
|
||||
|
||||
if (isBranchRequested(request)) {
|
||||
String branch = request.getBranch();
|
||||
if (isMergedIntoBranch(gr, revWalk, commit, branch)) {
|
||||
logger.trace("returning commit {} with branch {}", commit.getId(), branch);
|
||||
changeset = converter.createChangeset(commit, branch);
|
||||
} else {
|
||||
logger.debug("returning null, because commit {} was not merged into branch {}", commit.getId(), branch);
|
||||
}
|
||||
} else {
|
||||
changeset = converter.createChangeset(commit);
|
||||
}
|
||||
}
|
||||
else if (logger.isWarnEnabled())
|
||||
{
|
||||
@@ -157,6 +168,18 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
return changeset;
|
||||
}
|
||||
|
||||
private boolean isMergedIntoBranch(Repository repository, RevWalk revWalk, RevCommit commit, String branchName) throws IOException {
|
||||
return revWalk.isMergedInto(commit, findHeadCommitOfBranch(repository, revWalk, branchName));
|
||||
}
|
||||
|
||||
private boolean isBranchRequested(LogCommandRequest request) {
|
||||
return request != null && !Strings.isNullOrEmpty(request.getBranch());
|
||||
}
|
||||
|
||||
private RevCommit findHeadCommitOfBranch(Repository repository, RevWalk revWalk, String branchName) throws IOException {
|
||||
return revWalk.parseCommit(GitUtil.getCommit(repository, revWalk, repository.findRef(branchName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, GitContext> implements GitWorkdirFactory {
|
||||
public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, Repository, GitContext> implements GitWorkdirFactory {
|
||||
|
||||
@Inject
|
||||
public SimpleGitWorkdirFactory(WorkdirProvider workdirProvider) {
|
||||
@@ -26,7 +26,7 @@ public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, Gi
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParentAndClone<Repository> cloneRepository(GitContext context, File target, String initialBranch) {
|
||||
public ParentAndClone<Repository, Repository> cloneRepository(GitContext context, File target, String initialBranch) {
|
||||
try {
|
||||
Repository clone = Git.cloneRepository()
|
||||
.setURI(createScmTransportProtocolUri(context.getDirectory()))
|
||||
@@ -60,6 +60,13 @@ public class SimpleGitWorkdirFactory extends SimpleWorkdirFactory<Repository, Gi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeWorkdirInternal(Repository workdir) throws Exception {
|
||||
if (workdir != null) {
|
||||
workdir.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected sonia.scm.repository.Repository getScmRepository(GitContext context) {
|
||||
return context.getRepository();
|
||||
|
||||
Reference in New Issue
Block a user