List of usage examples for org.eclipse.jgit.api Git getRepository
public Repository getRepository()
From source file:com.gmail.cjbooms.thesis.pythonappengine.server.git.GitCommandsServiceImpl.java
License:Open Source License
/** * Pull changes from Remote Repository/*from w w w . j a v a2 s . co m*/ * * @param pathToLocalRepository Root Location Of Repository or Project * @param remoteRepoURL The URL of the Remote Repository to push to * @param userName The remote login user name * @param password The remote login password * @throws IOException, GitAPIException, URISyntaxException */ public void pullChangesFromRemoteRepository(String pathToLocalRepository, String remoteRepoURL, String userName, String password) throws IOException { File repositoryDirectory = new File(pathToLocalRepository); Git localGitRepositoryRef = Git.open(repositoryDirectory); Repository localRepository = localGitRepositoryRef.getRepository(); URIish remoteURI = null; try { remoteURI = new URIish(remoteRepoURL); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage()); } Transport t = Transport.open(localRepository, remoteURI); ((TransportHttp) t).setUseSmartHttp(true); t.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password)); RefSpec refSpec = new RefSpec("+refs/heads/*:refs/heads/*"); t.fetch(NullProgressMonitor.INSTANCE, Collections.singleton(refSpec)); }
From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java
License:Open Source License
/** * Reads a single note out as a string from the given commit hash. * Returns null if the note isn't found. *//*from w ww . j a v a 2s . c o m*/ private String readOneNote(Git git, String notesRef, String hash) throws GitClientException { try (RevWalk walker = new RevWalk(git.getRepository())) { ShowNoteCommand cmd = git.notesShow(); cmd.setNotesRef(notesRef); ObjectId ref = git.getRepository().resolve(hash); RevCommit commit = walker.parseCommit(ref); cmd.setObjectId(commit); Note note = cmd.call(); if (note == null) { return null; } return noteToString(repo, note); } catch (Exception e) { throw new GitClientException(e); } }
From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTask.java
License:Apache License
private void updateSampleRepo() { Git localGitRepo = getLocalRepo(); if (localGitRepo == null) { // clone repo localGitRepo = cloneGithubRepo(); } else {/* ww w .ja v a2s. c o m*/ // sync repo try { localGitRepo.pull().call(); } catch (GitAPIException e) { LOG.error("Error syncing local sample repository", e); } } if (localGitRepo != null) { localGitRepo.getRepository().close(); } }
From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTaskTest.java
License:Apache License
@Ignore @Test/* ww w.jav a 2 s. c o m*/ public void testSync_noLocalRepo() throws IOException, GitAPIException { // Sync files from mock Git Hub repo to mock local Android sample template repo SampleSyncTask sampleSyncTask = new SampleSyncTask(mockAndroidRepoPath, mockGitHubRepoPath); sampleSyncTask.run(); File mockAndroidRepoDir = new File(mockAndroidRepoPath); Assert.assertTrue(mockAndroidRepoDir.exists()); Git mockAndroidRepo = Git.open(mockAndroidRepoDir); Assert.assertEquals("refs/heads/master", mockAndroidRepo.getRepository().getFullBranch()); Assert.assertEquals(1, mockAndroidRepo.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call().size()); File mockGitHubRepoDir = new File(mockGitHubRepoPath); Assert.assertTrue(mockGitHubRepoDir.exists()); File[] mockAndroidRepoFiles = mockAndroidRepoDir.listFiles(); File[] mockGitHubRepoFiles = mockGitHubRepoDir.listFiles(); Assert.assertEquals(mockGitHubRepoFiles.length, mockAndroidRepoFiles.length); int num = 0; for (File aFile : mockGitHubRepoFiles) { aFile.getName().equals(mockAndroidRepoFiles[0].getName()); num++; } }
From source file:com.google.gerrit.acceptance.git.GitUtil.java
License:Apache License
public static void add(Git git, String path, String content) throws GitAPIException, IOException { File f = new File(git.getRepository().getDirectory().getParentFile(), path); File p = f.getParentFile();/*w ww. ja v a 2 s .c om*/ if (!p.exists() && !p.mkdirs()) { throw new IOException("failed to create dir: " + p.getAbsolutePath()); } FileWriter w = new FileWriter(f); BufferedWriter out = new BufferedWriter(w); try { out.write(content); } finally { out.close(); } final AddCommand addCmd = git.add(); addCmd.addFilepattern(path); addCmd.call(); }
From source file:com.google.gerrit.acceptance.git.GitUtil.java
License:Apache License
private static ObjectId computeChangeId(Git git, PersonIdent i, String msg) throws IOException { RevWalk rw = new RevWalk(git.getRepository()); try {/*from w w w .j av a 2s. c o m*/ Ref head = git.getRepository().getRef(Constants.HEAD); if (head.getObjectId() != null) { RevCommit parent = rw.lookupCommit(head.getObjectId()); return ChangeIdUtil.computeChangeId(parent.getTree(), parent.getId(), i, i, msg); } else { return ChangeIdUtil.computeChangeId(null, null, i, i, msg); } } finally { rw.release(); } }
From source file:com.google.gerrit.acceptance.git.ssh.GitUtil.java
License:Apache License
private static ObjectId computeChangeId(Git git, PersonIdent i, String msg) throws IOException { RevWalk rw = new RevWalk(git.getRepository()); try {//from w w w . j a v a2 s.c o m RevCommit parent = rw.lookupCommit(git.getRepository().getRef(Constants.HEAD).getObjectId()); return ChangeIdUtil.computeChangeId(parent.getTree(), parent.getId(), i, i, msg); } finally { rw.release(); } }
From source file:com.googlesource.gerrit.plugins.findowners.OwnersValidatorTest.java
License:Apache License
private static String generateFilePattern(File f, Git git) { return f.getAbsolutePath().replace(git.getRepository().getWorkTree().getAbsolutePath(), "").substring(1); }
From source file:com.hazelcast.hzblame.blame.Blame.java
License:Open Source License
private File getProjectRoot() { Git git = isEE ? gitEE : gitOS; return git.getRepository().getDirectory().getParentFile(); }
From source file:com.hazelcast.simulator.utils.jars.GitSupport.java
License:Open Source License
private void syncRemoteRepositories(Git git) throws IOException { StoredConfig config = git.getRepository().getConfig(); Set<GitRepository> customRepositoriesCopy = new HashSet<GitRepository>(customRepositories); Set<String> existingRemoteRepoNames = config.getSubsections(CONFIG_REMOTE); for (String remoteName : existingRemoteRepoNames) { String url = config.getString(CONFIG_REMOTE, remoteName, CONFIG_URL); boolean isConfigured = customRepositoriesCopy.remove(new GitRepository(remoteName, url)); if (!isConfigured && isCustomRepository(remoteName)) { removeRepository(config, remoteName); }/*from www. j a va 2 s . c o m*/ } for (GitRepository repository : customRepositoriesCopy) { addRepository(config, repository); } config.save(); }