mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-21 15:59:48 +01:00
Cleanup
This commit is contained in:
@@ -38,6 +38,7 @@ import sonia.scm.repository.GitWorkingCopyFactory;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.util.WorkingCopyPool;
|
||||
import sonia.scm.repository.util.SimpleWorkingCopyFactory;
|
||||
import sonia.scm.repository.util.WorkingCopyPool.ParentAndClone;
|
||||
import sonia.scm.util.SystemUtil;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -85,10 +86,10 @@ public class SimpleGitWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ParentAndClone<Repository, Repository> reclaimRepository(GitContext context, File target, String initialBranch) throws IOException, ReclaimFailedException {
|
||||
protected ParentAndClone<Repository, Repository> reclaimRepository(GitContext context, File target, String initialBranch) throws ReclaimFailedException {
|
||||
LOG.trace("reclaim repository {}", context.getRepository().getId());
|
||||
long start = System.nanoTime();
|
||||
Repository repo = GitUtil.open(target);
|
||||
Repository repo = openTarget(target);
|
||||
try (Git git = Git.open(target)) {
|
||||
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
||||
git.clean().setForce(true).setCleanDirectories(true).call();
|
||||
@@ -97,7 +98,7 @@ public class SimpleGitWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposi
|
||||
git.branchDelete().setBranchNames(initialBranch).setForce(true).call();
|
||||
git.checkout().setName(initialBranch).setCreateBranch(true).call();
|
||||
return new ParentAndClone<>(null, repo, target);
|
||||
} catch (GitAPIException e) {
|
||||
} catch (GitAPIException | IOException e) {
|
||||
throw new ReclaimFailedException(e);
|
||||
} finally {
|
||||
long end = System.nanoTime();
|
||||
@@ -106,6 +107,14 @@ public class SimpleGitWorkingCopyFactory extends SimpleWorkingCopyFactory<Reposi
|
||||
}
|
||||
}
|
||||
|
||||
private Repository openTarget(File target) throws ReclaimFailedException {
|
||||
try {
|
||||
return GitUtil.open(target);
|
||||
} catch (IOException e) {
|
||||
throw new ReclaimFailedException(e);
|
||||
}
|
||||
}
|
||||
|
||||
String createScmTransportProtocolUri(File bareRepository) {
|
||||
if (SystemUtil.isWindows()) {
|
||||
return ScmTransportProtocol.NAME + ":///" + bareRepository.getAbsolutePath().replaceAll("\\\\", "/");
|
||||
|
||||
Reference in New Issue
Block a user