List of usage examples for org.eclipse.jgit.api Git init
public static InitCommand init()
From source file:org.eclipse.recommenders.internal.snipmatch.GitSnippetRepositoryTest.java
License:Open Source License
@Test public void testinitialClone() throws Exception { git = Git.init().setDirectory(remotePath).call(); git.commit().setMessage("initial state").call(); git.checkout().setName(FORMAT_VERSION).setCreateBranch(true).call(); addFileToRemote(FIRST_FILE, remotePath, git); File firstFile = new File(basedir, FIRST_FILE); sut.open();//from ww w . j a va2 s .com assertTrue(firstFile.exists()); }
From source file:org.eclipse.recommenders.internal.snipmatch.GitSnippetRepositoryTest.java
License:Open Source License
@Test public void testFormatChange() throws Exception { git = Git.init().setDirectory(remotePath).call(); git.commit().setMessage("initial state").call(); git.checkout().setName("OLD-VERSION").setCreateBranch(true).call(); addFileToRemote(FIRST_FILE, remotePath, git); git.checkout().setName(FORMAT_VERSION).setCreateBranch(true).call(); addFileToRemote(SECOND_FILE, remotePath, git); File firstFile = new File(basedir, FIRST_FILE); File secondFile = new File(basedir, SECOND_FILE); sut.open();/*from w w w .j a va 2s.co m*/ assertTrue(firstFile.exists()); assertTrue(secondFile.exists()); }
From source file:org.eclipse.recommenders.snipmatch.GitSnippetRepository.java
License:Open Source License
private void initializeSnippetsRepo() throws GitAPIException { InitCommand init = Git.init(); init.setBare(false); init.setDirectory(basedir); init.call(); }
From source file:org.fusesource.fabric.git.internal.CachingGitDataStoreTest.java
License:Apache License
@Before public void setUp() throws Exception { sfb = new ZKServerFactoryBean(); delete(sfb.getDataDir());/*from w w w. j av a 2 s .c o m*/ delete(sfb.getDataLogDir()); sfb.afterPropertiesSet(); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString("localhost:" + sfb.getClientPortAddress().getPort()) .retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000); curator = builder.build(); curator.start(); curator.getZookeeperClient().blockUntilConnectedOrTimedOut(); // setup a local and remote git repo basedir = System.getProperty("basedir", "."); File root = new File(basedir + "/target/git").getCanonicalFile(); delete(root); new File(root, "remote").mkdirs(); remote = Git.init().setDirectory(new File(root, "remote")).call(); remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath(); new File(root, "local").mkdirs(); git = Git.init().setDirectory(new File(root, "local")).call(); git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", remoteUrl); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); DefaultRuntimeProperties sysprops = new DefaultRuntimeProperties(); sysprops.setProperty(SystemProperties.KARAF_DATA, "target/data"); FabricGitServiceImpl gitService = new FabricGitServiceImpl(); gitService.bindRuntimeProperties(sysprops); gitService.activate(); gitService.setGitForTesting(git); DataStoreTemplateRegistry registrationHandler = new DataStoreTemplateRegistry(); registrationHandler.activateComponent(); dataStore = new CachingGitDataStore(); dataStore.bindCurator(curator); dataStore.bindGitService(gitService); dataStore.bindRegistrationHandler(registrationHandler); dataStore.bindRuntimeProperties(sysprops); Map<String, String> datastoreProperties = new HashMap<String, String>(); datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl); dataStore.activate(datastoreProperties); }
From source file:org.fusesource.fabric.git.internal.FabricGitServiceImpl.java
License:Apache License
private Git openOrInit(File repo) throws IOException { try {/*from ww w.java2 s.c o m*/ return Git.open(repo); } catch (RepositoryNotFoundException e) { try { Git git = Git.init().setDirectory(repo).call(); git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); return git; } catch (GitAPIException ex) { throw new IOException(ex); } } }
From source file:org.fusesource.fabric.git.internal.GitDataStoreTest.java
License:Apache License
@Before public void setUp() throws Exception { sfb = new ZKServerFactoryBean(); delete(sfb.getDataDir());// www . j ava 2s . c o m delete(sfb.getDataLogDir()); sfb.afterPropertiesSet(); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString("localhost:" + sfb.getClientPortAddress().getPort()) .retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000); curator = builder.build(); curator.start(); curator.getZookeeperClient().blockUntilConnectedOrTimedOut(); // setup a local and remote git repo basedir = System.getProperty("basedir", "."); File root = new File(basedir + "/target/git").getCanonicalFile(); delete(root); new File(root, "remote").mkdirs(); remote = Git.init().setDirectory(new File(root, "remote")).call(); remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath(); new File(root, "local").mkdirs(); git = Git.init().setDirectory(new File(root, "local")).call(); git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", remoteUrl); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); FabricGitServiceImpl gitService = new FabricGitServiceImpl(); gitService.activate(EasyMock.createMock(ComponentContext.class)); gitService.setGitForTesting(git); dataStore = createDataStore(); dataStore.bindCuratorForTesting(curator); dataStore.bindGitService(gitService); dataStore.activate(EasyMock.createMock(ComponentContext.class)); Map<String, String> datastoreProperties = new HashMap<String, String>(); datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl); dataStore.setDataStoreProperties(datastoreProperties); dataStore.start(); }
From source file:org.fusesource.fabric.openshift.OpenShiftPomDeployerTest.java
License:Apache License
protected void doTest(String folder, String[] artifactUrls, String[] repoUrls, String expectedCamelDependencyScope, String expectedHawtioDependencyScope) throws Exception { File sourceDir = new File(baseDir, "src/test/resources/" + folder); assertDirectoryExists(sourceDir);//from ww w . j av a 2 s . c om File pomSource = new File(sourceDir, "pom.xml"); assertFileExists(pomSource); File outputDir = new File(baseDir, "target/" + getClass().getName() + "/" + folder); outputDir.mkdirs(); assertDirectoryExists(outputDir); File pom = new File(outputDir, "pom.xml"); Files.copy(pomSource, pom); assertFileExists(pom); git = Git.init().setDirectory(outputDir).call(); assertDirectoryExists(new File(outputDir, ".git")); git.add().addFilepattern("pom.xml").call(); git.commit().setMessage("Initial import").call(); // now we have the git repo setup; lets run the update OpenShiftPomDeployer deployer = new OpenShiftPomDeployer(git, outputDir, deployDir, webAppDir); System.out.println("About to update the pom " + pom + " with artifacts: " + Arrays.asList(artifactUrls)); List<Parser> artifacts = new ArrayList<Parser>(); for (String artifactUrl : artifactUrls) { artifacts.add(new Parser(artifactUrl)); } List<MavenRepositoryURL> repos = new ArrayList<MavenRepositoryURL>(); for (String repoUrl : repoUrls) { repos.add(new MavenRepositoryURL(repoUrl)); } deployer.update(artifacts, repos); System.out.println("Completed the new pom is: "); System.out.println(Files.toString(pom)); Document xml = XmlUtils.parseDoc(pom); Element plugins = assertXPathElement(xml, "project/profiles/profile[id = 'openshift']/build/plugins"); Element cleanExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-clean-plugin']/executions/execution[id = 'fuse-fabric-clean']"); Element dependencySharedExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-shared']"); Element dependencyWebAppsExecution = assertXPathElement(plugins, "plugin[artifactId = 'maven-dependency-plugin']/executions/execution[id = 'fuse-fabric-deploy-webapps']"); Element warPluginWarName = xpath("plugin[artifactId = 'maven-war-plugin']/configuration/warName") .element(plugins); if (warPluginWarName != null) { String warName = warPluginWarName.getTextContent(); System.out.println("WarName is now: " + warName); assertTrue("Should not have ROOT war name", !"ROOT".equals(warName)); } Element dependencies = assertXPathElement(xml, "project/dependencies"); Element repositories = assertXPathElement(xml, "project/repositories"); for (Parser artifact : artifacts) { // lets check there's only 1 dependency for group & artifact and it has the right version String group = groupId(artifact); String artifactId = artifact.getArtifact(); Element dependency = assertSingleDependencyForGroupAndArtifact(dependencies, group, artifactId); Element version = assertXPathElement(dependency, "version"); assertEquals("Version", artifact.getVersion(), version.getTextContent()); } // lets check we either preserve scope, add provided or don't add a scope if there's none present in the underlying pom assertDependencyScope(dependencies, "org.apache.camel", "camel-core", expectedCamelDependencyScope); assertDependencyScope(dependencies, "org.drools", "drools-wb-distribution-wars", "provided"); assertDependencyScope(dependencies, "io.hawt", "hawtio-web", expectedHawtioDependencyScope); assertRepositoryUrl(repositories, "http://repository.jboss.org/nexus/content/groups/public/"); assertRepositoryUrl(repositories, "http://repo.fusesource.com/nexus/content/groups/ea/"); }
From source file:org.gitective.tests.GitTestCase.java
License:Open Source License
/** * Initialize a new repo in a new directory * * @return created .git folder/* w ww. j a v a 2 s . co m*/ * @throws GitAPIException */ protected File initRepo() throws GitAPIException { String tmpDir = System.getProperty("java.io.tmpdir"); assertNotNull("java.io.tmpdir was null", tmpDir); File dir = new File(tmpDir, "git-test-case-" + System.nanoTime()); assertTrue(dir.mkdir()); Git.init().setDirectory(dir).setBare(false).call(); File repo = new File(dir, Constants.DOT_GIT); assertTrue(repo.exists()); repo.deleteOnExit(); return repo; }
From source file:org.gitistics.test.RepositoryBuilderImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public RepositoryWorkerReturn<Repository> open() { try {//from w w w . java 2s .c o m String tmpDir = System.getProperty("java.io.tmpdir"); File dir = new File(tmpDir, UUID.randomUUID().toString().replaceAll("-", "")); Git.init().setDirectory(dir).setBare(false).call(); repositories.add(dir); File file = new File(dir, ".git"); Repository repository = new FileRepository(file); return (RepositoryWorkerReturn<Repository>) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { RepositoryWorkerReturn.class }, new ReturnHolder(new RepositoryWokerImpl(dir, repository), repository)); } catch (Exception e) { throw new RuntimeException("Error creating git repository ", e); } }
From source file:org.gradle.vcs.fixtures.GitFileRepository.java
License:Apache License
private void createGitRepo(File repoDir) throws GitAPIException { git = Git.init().setDirectory(repoDir).call(); }