org.eclipse.jgit.lib.Repository.close() - java examples

Here are the examples of the java api org.eclipse.jgit.lib.Repository.close() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

153 Examples 7

19 View Complete Implementation : GitTestHelper.java
Copyright Eclipse Public License 1.0
Author : cchabanois
public static void tryDeleteRepository(Repository repository) {
    try {
        repository.close();
        FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING);
        FileUtils.delete(repository.getWorkTree(), FileUtils.RECURSIVE | FileUtils.RETRY | FileUtils.SKIP_MISSING);
    } catch (IOException e) {
    }
}

19 View Complete Implementation : GitRepository.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : gluonhq
public void close() {
    repo.close();
}

19 View Complete Implementation : BaseGitCommand.java
Copyright Apache License 2.0
Author : gitblit
private void service() throws IOException, Failure {
    try {
        repo = openRepository();
        runImpl();
    } finally {
        if (repo != null) {
            repo.close();
        }
    }
}

19 View Complete Implementation : JGitUtils.java
Copyright Apache License 2.0
Author : apache
public static boolean isUserSetup(File root) {
    Repository repository = getRepository(root);
    boolean userExists = true;
    if (repository != null) {
        try {
            StoredConfig config = repository.getConfig();
            // NOI18N
            String name = config.getString("user", null, "name");
            // NOI18N
            String email = config.getString("user", null, "email");
            if (name == null || name.isEmpty() || email == null || email.isEmpty()) {
                userExists = false;
            }
        } finally {
            repository.close();
        }
    }
    return userExists;
}

19 View Complete Implementation : ScenarioTest.java
Copyright Apache License 2.0
Author : jgitver
/**
 * Cleanups after each tests.
 */
@AfterEach
public void cleanVersionCalculator() {
    mute(() -> git.close());
    mute(() -> repository.close());
    mute(() -> versionCalculator.close());
}

19 View Complete Implementation : AbstractGitCommand.java
Copyright Apache License 2.0
Author : rtyley
private void service() throws IOException, Failure {
    try {
        repo = repoManager.openRepository(projectName());
    } catch (RepositoryNotFoundException e) {
        throw new Failure(1, "fatal: '" + projectName() + "': not a git archive", e);
    }
    try {
        runImpl();
    } finally {
        repo.close();
    }
}

19 View Complete Implementation : JGitDiscoveryTest.java
Copyright MIT License
Author : danielflower
@After
public void closeRepo() {
    repo.close();
}

19 View Complete Implementation : DevicesGit.java
Copyright GNU General Public License v3.0
Author : Androxyde
public static void closeRepository() {
    logger.info("Quietly closing devices repository.");
    try {
        git.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        localRepo.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

19 View Complete Implementation : Issue22OnJGitverHistoryTest.java
Copyright Apache License 2.0
Author : jgitver
@AfterEach
public void cleanup() {
    mute(() -> git.close());
    mute(() -> repository.close());
    mute(() -> versionCalculator.close());
}

19 View Complete Implementation : RepoViewTest.java
Copyright Apache License 2.0
Author : gerrit-review
@After
public void tearDown() {
    view.close();
    repo.close();
}

19 View Complete Implementation : AbstractGitCommand.java
Copyright Apache License 2.0
Author : gerrit-review
private void service() throws IOException, PermissionBackendException, Failure {
    project = projectState.getProject();
    projectName = project.getNameKey();
    try {
        repo = repoManager.openRepository(projectName);
    } catch (RepositoryNotFoundException e) {
        throw new Failure(1, "fatal: '" + project.getName() + "': not a git archive", e);
    }
    try {
        runImpl();
    } finally {
        repo.close();
    }
}

19 View Complete Implementation : KieRepositoryHandler.java
Copyright Apache License 2.0
Author : kiegroup
@Override
public void dispose() {
    super.dispose();
    if (repository != null) {
        repository.close();
        repository = null;
    }
}

19 View Complete Implementation : GitUtils.java
Copyright Eclipse Public License 1.0
Author : eclipse
public static String getCloneUrl(File gitDir) {
    Repository db = null;
    try {
        db = FileRepositoryBuilder.create(resolveGitDir(gitDir));
        return getCloneUrl(db);
    } catch (IOException e) {
    // ignore and skip Git URL
    } finally {
        if (db != null) {
            db.close();
        }
    }
    return null;
}

19 View Complete Implementation : AbstractGroupTest.java
Copyright Apache License 2.0
Author : GerritCodeReview
@After
public void abstractGroupTestTearDown() throws Exception {
    allUsersRepo.close();
}

19 View Complete Implementation : JGitRepository.java
Copyright Apache License 2.0
Author : apache
public synchronized void decreaseClientUsage() {
    repository.close();
}

19 View Complete Implementation : JGitRepository.java
Copyright Apache License 2.0
Author : onepremise
public void close() {
    closeTransport();
    if (repository != null)
        repository.close();
}

18 View Complete Implementation : GitVersionCalculatorImpl.java
Copyright Apache License 2.0
Author : jgitver
@Override
public void close() throws Exception {
    if (repository != null) {
        repository.close();
    }
}

18 View Complete Implementation : JGitUtils.java
Copyright Apache License 2.0
Author : apache
public static RepositoryInfo.PushMode getPushMode(File root) {
    Repository repository = getRepository(root);
    if (repository != null) {
        try {
            // NOI18N
            String val = repository.getConfig().getString("push", null, "default");
            if ("upstream".equals(val)) {
                // NOI18N
                return PushMode.UPSTREAM;
            }
        } finally {
            repository.close();
        }
    }
    return PushMode.ASK;
}

18 View Complete Implementation : JGitRepository.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : koraktor
/**
 * {@inheritDoc}
 * <p>
 * Closes JGit's repository instance.
 *
 * @see Repository#close
 */
@Override
public void close() {
    if (repository != null) {
        repository.close();
        repository = null;
    }
}

18 View Complete Implementation : UserIdentityServiceImplTest.java
Copyright GNU Affero General Public License v3.0
Author : ptitfred
private static void closeRepo(Repository... repos) {
    for (Repository repo : repos) {
        if (repo != null) {
            repo.close();
            tests.FilesUtils.recursiveDelete(repo.getDirectory().getParentFile());
            repo = null;
        }
    }
}

18 View Complete Implementation : RemoteGitPersistenceResourceTestCase.java
Copyright GNU Lesser General Public License v2.1
Author : wildfly
@After
public void deleteDirectoriesAndFiles() throws Exception {
    if (remoteRepository != null) {
        remoteRepository.close();
    }
    if (repository != null) {
        repository.close();
    }
    delete(remoteRoot.toFile());
    delete(root.toFile());
}

18 View Complete Implementation : FilesCopyAcrossSystemsTest.java
Copyright Apache License 2.0
Author : beijunyi
@After
public void closeTargetSystem() throws IOException {
    targetGfs.close();
    targetRepo.close();
}

18 View Complete Implementation : AbstractGitRepositoryTestCase.java
Copyright GNU Lesser General Public License v2.1
Author : wildfly
protected void closeEmptyRemoteRepository() throws Exception {
    if (emptyRemoteRepository != null) {
        emptyRemoteRepository.close();
    }
    FileUtils.delete(emptyRemoteRoot.toFile(), FileUtils.RECURSIVE | FileUtils.RETRY);
}

18 View Complete Implementation : RepositoryUtilsOpenRepositoryTest.java
Copyright Apache License 2.0
Author : beijunyi
@After
public void tearDown() throws IOException {
    if (repo != null)
        repo.close();
    FileUtils.delete(dir, FileUtils.RECURSIVE);
}

18 View Complete Implementation : InitJob.java
Copyright Eclipse Public License 1.0
Author : eclipse
@Override
public IStatus performJob() {
    Repository repository = null;
    try {
        InitCommand command = new InitCommand();
        File directory = new File(clone.getContentLocation());
        command.setDirectory(directory);
        repository = command.call().getRepository();
        Git git = Git.wrap(repository);
        // configure the repo
        GitCloneHandlerV1.doConfigureClone(git, user, gitUserName, gitUserMail);
        // we need to perform an initial commit to workaround JGit bug 339610
        git.commit().setMessage("Initial commit").call();
    } catch (CoreException e) {
        return e.getStatus();
    } catch (GitAPIException e) {
        return getGitAPIExceptionStatus(e, "Error initializing git repository");
    } catch (JGitInternalException e) {
        return getJGitInternalExceptionStatus(e, "Error initializing git repository");
    } catch (Exception e) {
        return new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error initializing git repository", e);
    } finally {
        if (repository != null) {
            repository.close();
        }
    }
    JSONObject jsonData = new JSONObject();
    try {
        jsonData.put(ProtocolConstants.KEY_LOCATION, URI.create(this.cloneLocation));
    } catch (JSONException e) {
    // Should not happen
    }
    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, jsonData);
}

18 View Complete Implementation : PushCertificateChecker.java
Copyright Apache License 2.0
Author : gerrit-review
/**
 * Check a push certificate.
 *
 * @return result of the check.
 */
public final Result check(PushCertificate cert) {
    if (checkNonce && cert.getNonceStatus() != NonceStatus.OK) {
        return new Result(null, CheckResult.bad("Invalid nonce"));
    }
    List<CheckResult> results = new ArrayList<>(2);
    Result sigResult = null;
    try {
        PGPSignature sig = readSignature(cert);
        if (sig != null) {
            @SuppressWarnings("resource")
            Repository repo = getRepository();
            try (PublicKeyStore store = new PublicKeyStore(repo)) {
                sigResult = checkSignature(sig, cert, store);
                results.add(checkCustom(repo));
            } finally {
                if (shouldClose(repo)) {
                    repo.close();
                }
            }
        } else {
            results.add(CheckResult.bad("Invalid signature format"));
        }
    } catch (PGPException | IOException e) {
        String msg = "Internal error checking push certificate";
        log.error(msg, e);
        results.add(CheckResult.bad(msg));
    }
    return combine(sigResult, results);
}

18 View Complete Implementation : GerritPublicKeyCheckerTest.java
Copyright Apache License 2.0
Author : gerrit-review
@After
public void tearDown() throws Exception {
    store.close();
    storeRepo.close();
}

18 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public void commit(List<String> rootDirPath, String committerName, String committerEmail, String replacedle, String description) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        new Git(repo).commit().setAuthor(committerName, committerEmail).setMessage(replacedle + "\n\n" + description).call();
        repo.close();
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

18 View Complete Implementation : DaemonService.java
Copyright Apache License 2.0
Author : kiegroup
void execute(final org.uberfire.java.nio.fs.jgit.daemon.git.DaemonClient client, final String commandLine) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException {
    final String name = commandLine.substring(command.length() + 1);
    Repository db;
    try {
        db = client.getDaemon().openRepository(client, name);
    } catch (ServiceMayNotContinueException e) {
        // An error when opening the repo means the client is expecting a ref
        // advertisement, so use that style of error.
        PacketLineOut pktOut = new PacketLineOut(client.getOutputStream());
        pktOut.writeString("ERR " + e.getMessage() + "\n");
        db = null;
    }
    if (db == null) {
        return;
    }
    try {
        if (isEnabledFor(db)) {
            execute(client, db);
        }
    } finally {
        db.close();
    }
}

18 View Complete Implementation : PushCertificateChecker.java
Copyright Apache License 2.0
Author : GerritCodeReview
/**
 * Check a push certificate.
 *
 * @return result of the check.
 */
public final Result check(PushCertificate cert) {
    if (checkNonce && cert.getNonceStatus() != NonceStatus.OK) {
        return new Result(null, CheckResult.bad("Invalid nonce"));
    }
    List<CheckResult> results = new ArrayList<>(2);
    Result sigResult = null;
    try {
        PGPSignature sig = readSignature(cert);
        if (sig != null) {
            @SuppressWarnings("resource")
            Repository repo = getRepository();
            try (PublicKeyStore store = new PublicKeyStore(repo)) {
                sigResult = checkSignature(sig, cert, store);
                results.add(checkCustom(repo));
            } finally {
                if (shouldClose(repo)) {
                    repo.close();
                }
            }
        } else {
            results.add(CheckResult.bad("Invalid signature format"));
        }
    } catch (PGPException | IOException e) {
        String msg = "Internal error checking push certificate";
        logger.atSevere().withCause(e).log(msg);
        results.add(CheckResult.bad(msg));
    }
    return combine(sigResult, results);
}

18 View Complete Implementation : RawFilter.java
Copyright Apache License 2.0
Author : gitblit
/**
 * Extract the repository name from the url.
 *
 * @param url
 * @return repository name
 */
@Override
protected String extractRepositoryName(String url) {
    // get the repository name from the url by finding a known url suffix
    String repository = "";
    Repository r = null;
    int offset = 0;
    while (r == null) {
        int slash = url.indexOf('/', offset);
        if (slash == -1) {
            repository = url;
        } else {
            repository = url.substring(0, slash);
        }
        r = repositoryManager.getRepository(repository, false);
        if (r == null) {
            // try again
            offset = slash + 1;
        } else {
            // close the repo
            r.close();
        }
        if (repository.equals(url)) {
            // either only repository in url or no repository found
            break;
        }
    }
    return repository;
}

18 View Complete Implementation : GitConfigSource.java
Copyright Apache License 2.0
Author : oracle
@Override
public void close() throws IOException {
    if (!isClosed) {
        try {
            if (repository != null) {
                repository.close();
            }
            closeGits();
            if (isTempDirectory) {
                deleteTempDirectory();
            }
        } finally {
            isClosed = true;
        }
    }
}

18 View Complete Implementation : EmbeddedHttpGitServerTest.java
Copyright Apache License 2.0
Author : arquillian
@After
public void cleanup() {
    executeAfterTest.forEach(cleanup -> cleanup.apply(null));
    if (repository != null) {
        repository.close();
    }
    if (gitCloner != null) {
        gitCloner.removeClone();
    }
    if (gitServer != null) {
        gitServer.stop();
    }
}

18 View Complete Implementation : GitDaemonService.java
Copyright Apache License 2.0
Author : gitblit
void execute(final GitDaemonClient client, final String commandLine) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException {
    final String name = commandLine.substring(command.length() + 1);
    Repository db;
    try {
        db = client.getDaemon().openRepository(client, name);
    } catch (ServiceMayNotContinueException e) {
        // An error when opening the repo means the client is expecting a ref
        // advertisement, so use that style of error.
        PacketLineOut pktOut = new PacketLineOut(client.getOutputStream());
        // $NON-NLS-1$ //$NON-NLS-2$
        pktOut.writeString("ERR " + e.getMessage() + "\n");
        db = null;
    }
    if (db == null)
        return;
    try {
        if (isEnabledFor(db))
            execute(client, db);
    } finally {
        db.close();
    }
}

18 View Complete Implementation : RepositoryPage.java
Copyright Apache License 2.0
Author : gitblit
@Override
protected void onBeforeRender() {
    // dispose of repository object
    if (r != null) {
        r.close();
        r = null;
    }
    // setup page header and footer
    setupPage(getRepositoryName(), "/ " + getPageName());
    super.onBeforeRender();
}

18 View Complete Implementation : RemoteGitRepositoryTestCase.java
Copyright GNU Lesser General Public License v2.1
Author : wildfly
private void closeRemoteRepository() throws Exception {
    if (remoteRepository != null) {
        remoteRepository.close();
    }
    FileUtils.delete(remoteRoot.toFile(), FileUtils.RECURSIVE | FileUtils.RETRY);
}

18 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public boolean push(List<String> rootDirPath) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        new Git(repo).push().setRefSpecs(new RefSpec("master:master")).call();
        repo.close();
        return true;
    } catch (TransportException e) {
        return false;
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

18 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public void resetHard(List<String> rootDirPath) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        new Git(repo).reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
        repo.close();
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

18 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public void addAll(List<String> rootDirPath) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        new Git(repo).add().addFilepattern(".").call();
        repo.close();
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

18 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public void resetToParent(List<String> rootDirPath) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        new Git(repo).reset().setRef(repo.resolve("HEAD^").getName()).call();
        repo.close();
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

17 View Complete Implementation : SMAGitTest.java
Copyright MIT License
Author : aesanch2
/**
 * After to tear down the test.
 *
 * @throws Exception
 */
@After
public void tearDown() throws Exception {
    repository.close();
    FileUtils.deleteDirectory(localPath);
}

17 View Complete Implementation : JGitUtils.java
Copyright Apache License 2.0
Author : apache
public static void persistUser(File root, GitUser author) throws GitException {
    Repository repository = getRepository(root);
    if (repository != null) {
        try {
            StoredConfig config = repository.getConfig();
            // NOI18N
            config.setString("user", null, "name", author.getName());
            // NOI18N
            config.setString("user", null, "email", author.getEmailAddress());
            try {
                config.save();
                FileUtil.refreshFor(new File(GitUtils.getGitFolderForRoot(root), "config"));
            } catch (IOException ex) {
                throw new GitException(ex);
            }
        } finally {
            repository.close();
        }
    }
}

17 View Complete Implementation : EmbeddedHttpGitServerTest.java
Copyright Apache License 2.0
Author : arquillian
@Test
public void should_be_able_to_push_to_served_repository_on_the_default_port() throws Exception {
    // given
    gitServer = EmbeddedHttpGitServer.fromBundle("das-repo", "repo.bundle").create();
    gitCloner = new GitCloner("http://localhost:8765/das-repo");
    final GitCloner secondGitCloner = new GitCloner("http://localhost:8765/das-repo");
    executeAfterTest.add(v -> {
        secondGitCloner.removeClone();
        return v;
    });
    gitServer.start();
    repository = gitCloner.cloneRepositoryToTempFolder();
    createNewFileAndPush(repository, "new-file.txt", "new file", "feat: new file");
    // when
    final Repository secondClone = secondGitCloner.cloneRepositoryToTempFolder();
    executeAfterTest.add(v -> {
        secondClone.close();
        return v;
    });
    // then
    replacedertThat(new File(secondClone.getDirectory().getParent(), "new-file.txt")).exists();
}

17 View Complete Implementation : EmbeddedHttpGitServerTest.java
Copyright Apache License 2.0
Author : arquillian
@Test
public void should_be_able_to_serve_multiple_repositories() throws Exception {
    // given
    gitServer = EmbeddedHttpGitServer.fromBundle("das-repo", "repo.bundle").fromPath(Paths.get("src/test/resources/saas-launchpad.bundle")).usingPort(5433).create();
    gitServer.start();
    final GitCloner dasRepoCloner = new GitCloner("http://localhost:5433/das-repo");
    final GitCloner launchpadCloner = new GitCloner("http://localhost:5433/saas-launchpad.bundle");
    // when
    final Repository dasRepo = dasRepoCloner.cloneRepositoryToTempFolder();
    executeAfterTest.add(v -> {
        dasRepo.close();
        return v;
    });
    final Repository launchpad = launchpadCloner.cloneRepositoryToTempFolder();
    executeAfterTest.add(v -> {
        launchpad.close();
        return v;
    });
    // then
    replacedertThat(new File(dasRepo.getDirectory().getParent(), "Jenkinsfile")).exists();
    replacedertThat(new File(launchpad.getDirectory().getParent(), "config.yaml")).exists();
}

17 View Complete Implementation : OutputStreamQuery.java
Copyright Apache License 2.0
Author : gerrit-review
private static void closeAll(Iterable<RevWalk> revWalks, Iterable<Repository> repos) {
    if (repos != null) {
        for (Repository repo : repos) {
            repo.close();
        }
    }
    if (revWalks != null) {
        for (RevWalk revWalk : revWalks) {
            revWalk.close();
        }
    }
}

17 View Complete Implementation : RepoView.java
Copyright Apache License 2.0
Author : gerrit-review
// Not AutoCloseable so callers can't improperly close it. Plus it's never managed with a try
// block anyway.
void close() {
    if (closeRepo) {
        inserter.close();
        rw.close();
        repo.close();
    }
}

17 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public boolean rebase(List<String> rootDirPath) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        RebaseResult result = new Git(repo).rebase().setUpstream("origin/master").call();
        if (result.getStatus() == RebaseResult.Status.STOPPED) {
            new Git(repo).rebase().setOperation(RebaseCommand.Operation.ABORT).call();
            repo.close();
            return false;
        }
        repo.close();
        return true;
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

17 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public List<GitCommit> getLog(List<String> rootDirPath) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        Iterable<RevCommit> logs = new Git(repo).log().call();
        ImmutableList.Builder<GitCommit> versions = ImmutableList.builder();
        for (RevCommit rev : logs) {
            versions.add(new GitCommit(rev.getName(), rev.getAuthorIdent().getName(), new Date(rev.getCommitTime() * 1000L), rev.getShortMessage(), rev.getFullMessage()));
        }
        repo.close();
        return versions.build();
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

17 View Complete Implementation : LocalGitProvider.java
Copyright GNU General Public License v2.0
Author : ia-toki
@Override
public void restore(List<String> rootDirPath, String hash) {
    File root = new File(fileSystemProvider.getURL(rootDirPath));
    try {
        Repository repo = FileRepositoryBuilder.create(new File(root, ".git"));
        ObjectId head = repo.resolve("HEAD");
        RevertCommand command = new Git(repo).revert();
        Iterable<RevCommit> logs = new Git(repo).log().call();
        for (RevCommit rev : logs) {
            if (rev.getName().equals(hash)) {
                break;
            }
            command.include(rev);
        }
        command.call();
        new Git(repo).rebase().setUpstream(head).runInteractively(new RebaseCommand.InteractiveHandler() {

            @Override
            public void prepareSteps(List<RebaseTodoLine> list) {
                for (int i = 0; i < list.size(); i++) {
                    try {
                        if (i == 0) {
                            list.get(i).setAction(RebaseTodoLine.Action.REWORD);
                        } else {
                            list.get(i).setAction(RebaseTodoLine.Action.FIXUP);
                        }
                    } catch (IllegalTodoFileModification e) {
                    // nothing
                    }
                }
            }

            @Override
            public String modifyCommitMessage(String s) {
                return "Revert to commit " + hash.substring(0, 7);
            }
        }).call();
        repo.close();
    } catch (IOException | GitAPIException e) {
        throw new RuntimeException(e);
    }
}

17 View Complete Implementation : StatusesServiceImplTest.java
Copyright GNU Affero General Public License v3.0
Author : ptitfred
@AfterClreplaced
public static void tearDownClreplaced() {
    if (test != null) {
        test.close();
        tests.FilesUtils.recursiveDelete(test.getDirectory().getParentFile());
        test = null;
    }
}