List of usage examples for org.eclipse.jgit.internal.storage.file FileRepository close
@Override public void close()
Decrement the use count, and maybe close resources.
From source file:com.tenxdev.ovcs.command.CommitCommand.java
License:Open Source License
@Override /**/*w w w .j a v a2 s. co m*/ * {@inheritDoc} */ public void execute(final String... args) throws OvcsException { if (args.length != 1) { throw new OvcsException(USAGE); } System.out.println("Fetching changes from database..."); final FileRepository repository = getRepoForCurrentDir(); try { try (Connection conn = getDbConnectionForRepo(repository)) { final Git git = new Git(repository); final List<ChangeEntry> changes = writeChanges(repository); if (changes.isEmpty()) { System.out.println("No changes have been made, ending session"); } else { try { for (final ChangeEntry changeEntry : changes) { git.add() .addFilepattern(changeEntry.getName().toUpperCase(Locale.getDefault()) + ".sql") .call(); } git.commit().setMessage(getCommitMessage()).setAll(true).call(); } catch (final GitAPIException e) { throw new OvcsException("Unable to commit: " + e.getMessage(), e); } } try (CallableStatement stmt = conn.prepareCall("begin ovcs.handler.end_session; end;")) { stmt.execute(); conn.commit(); } catch (final SQLException e) { throw new OvcsException( "Unexpected error while committing database changes, you may have to call " + "ovcs.handler.end_session from your schema and commit to bring the database into a consistent state.", e); } if (!changes.isEmpty()) { try { doPush(git); System.out.println("All changes committed and sent to remote repository."); } catch (final GitAPIException e) { throw new OvcsException(String.format( "All changes have been committed, but were not sent to the remote repository%n" + "Please run the ovcs push command to retry sending to the remote repository%nError: %s", e.getMessage()), e); } } } catch (final SQLException e) { throw new OvcsException("Unexpected error while closing database connection, you may have to call " + "ovcs.handler.end_session from your schema and commit to bring the database into a consistent state.", e); } } finally { repository.close(); } }
From source file:com.tenxdev.ovcs.command.DiffCommand.java
License:Open Source License
/** * {@inheritDoc}/*from w w w .j a v a 2 s .co m*/ */ @Override public void execute(final String... args) throws OvcsException { if (args.length != 1 && args.length != 2) { throw new UsageException(USAGE); } String targetObject = null; if (args.length == 2) { targetObject = args[1].toUpperCase(Locale.getDefault()); if (!targetObject.toLowerCase(Locale.getDefault()).endsWith(".sql")) { targetObject = targetObject + ".sql"; } } final FileRepository fileRepository = getRepoForCurrentDir(); try { writeChanges(fileRepository); final DiffFormatter formatter = new DiffFormatter(System.out); formatter.setNewPrefix("new/"); formatter.setOldPrefix("old/"); formatter.setRepository(fileRepository); if (targetObject != null) { formatter.setPathFilter(PathFilter.create(targetObject)); } final AbstractTreeIterator commitTreeIterator = GitUtils.prepareHeadTreeParser(fileRepository); final FileTreeIterator workTreeIterator = new FileTreeIterator(fileRepository); final List<DiffEntry> diffEntries = formatter.scan(commitTreeIterator, workTreeIterator); for (final DiffEntry entry : diffEntries) { System.out.println("Entry: " + entry); formatter.format(entry); } } catch (final IOException e) { throw new OvcsException("Unable to generate diff: " + e.getMessage(), e); } finally { fileRepository.close(); } }
From source file:com.tenxdev.ovcs.command.PushCommand.java
License:Open Source License
/** * {@inheritDoc}/* w ww. j a v a 2s .c o m*/ */ @Override public void execute(final String... args) throws OvcsException { if (args.length != 1) { throw new UsageException(USAGE); } final FileRepository repository = getRepoForCurrentDir(); try { doPush(new Git(repository)); } catch (final GitAPIException e) { throw new OvcsException("Unable to push: " + e.getMessage(), e); } finally { repository.close(); } }
From source file:com.tenxdev.ovcs.command.StatusCommand.java
License:Open Source License
/** * {@inheritDoc}/*from www. j a v a2 s.c o m*/ */ @Override public void execute(final String... args) throws OvcsException { if (args.length != 1) { throw new UsageException(USAGE); } System.out.println("Fetching changes from database..."); final FileRepository repository = getRepoForCurrentDir(); try { writeChanges(repository); displayChanges(repository); } finally { repository.close(); } }
From source file:com.tenxdev.ovcs.command.SyncCommand.java
License:Open Source License
/** * {@inheritDoc}//from www. ja va2 s . co m */ @Override public void execute(final String... args) throws OvcsException { if (args.length != 1) { throw new UsageException(USAGE); } final FileRepository repository = getRepoForCurrentDir(); try { final File workingDirectory = repository.getWorkTree(); new Git(repository).pull().setProgressMonitor(new TextProgressMonitor()).call(); try (Connection conn = getDbConnectionForRepo(repository)) { writeSchemaObjects(conn, workingDirectory.toPath()); commitAndPush(); } catch (final SQLException e) { throw new OvcsException("Unable to connect to database: " + e.getMessage(), e); } } catch (final GitAPIException e) { throw new OvcsException("Unable to synchronize with remote repository: " + e.getMessage(), e); } finally { repository.close(); } }
From source file:org.eclipse.egit.core.internal.ProjectReferenceImporter.java
License:Open Source License
private static boolean repositoryAlreadyExistsForUrl(File repositoryPath, URIish gitUrl) { if (repositoryPath.exists()) { FileRepository existingRepository; try {//w w w . ja v a2s . c o m existingRepository = new FileRepository(repositoryPath); } catch (IOException e) { return false; } try { boolean exists = containsRemoteForUrl(existingRepository.getConfig(), gitUrl); return exists; } catch (URISyntaxException e) { return false; } finally { existingRepository.close(); } } return false; }
From source file:org.sonatype.m2e.egit.internal.EgitScmHandler.java
License:Open Source License
protected void fixAutoCRLF(File gitDirectory) throws IOException { // jgit does not have support for core.autocrlf but it sets the core.autocrlf=false in the local git // repository config (https://bugs.eclipse.org/bugs/show_bug.cgi?id=301775). // We need to unset it. FileRepository localRepository = new FileRepository(gitDirectory); try {//from w w w .j a va 2s . co m FileBasedConfig localConfig = localRepository.getConfig(); localConfig.unset(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF); localConfig.save(); } finally { localRepository.close(); } }
From source file:ru.nikitenkogleb.androidtools.newappwizard.GitSupport.java
/** Send changes to remote repository */ final void close(String userName, String userEmail, String initMessage) { if (!isSuccessful()) return;//from w w w . j ava2 s. c om FileRepository mRepository = null; Git mGit = null; try { mRepository = new FileRepository(new File(mProjectPath, ".git")); mGit = new Git(mRepository); mGit.add().addFilepattern(".").call(); mGit.commit().setAll(true).setAuthor(userName, userEmail).setCommitter(userName, userEmail) .setMessage(initMessage).call(); final PushCommand pushCommand = mGit.push().setRemote("origin").setPushAll(); if (mSshConfigCallback != null) pushCommand.setTransportConfigCallback(mSshConfigCallback); else pushCommand.setCredentialsProvider(mHttpsCredentialsProvider); pushCommand.call(); } catch (GitAPIException | IOException e) { e.printStackTrace(); } if (mGit != null) mGit.close(); if (mRepository != null) mRepository.close(); }