Java Code Examples for org.eclipse.jgit.lib.Repository#create()

The following examples show how to use org.eclipse.jgit.lib.Repository#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OldGitNotebookRepo.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
public void init(ZeppelinConfiguration conf) throws IOException {
  //TODO(zjffdu), it is weird that I can not call super.init directly here, as it would cause
  //AbstractMethodError
  this.conf = conf;
  setNotebookDirectory(conf.getNotebookDir());

  localPath = getRootDir().getName().getPath();
  LOG.info("Opening a git repo at '{}'", localPath);
  Repository localRepo = new FileRepository(Joiner.on(File.separator).join(localPath, ".git"));
  if (!localRepo.getDirectory().exists()) {
    LOG.info("Git repo {} does not exist, creating a new one", localRepo.getDirectory());
    localRepo.create();
  }
  git = new Git(localRepo);
}
 
Example 2
Source File: GitNotebookRepo.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
public void init(ZeppelinConfiguration conf) throws IOException {
  //TODO(zjffdu), it is weird that I can not call super.init directly here, as it would cause
  //AbstractMethodError
  this.conf = conf;
  setNotebookDirectory(conf.getNotebookDir());

  LOGGER.info("Opening a git repo at '{}'", this.rootNotebookFolder);
  Repository localRepo = new FileRepository(Joiner.on(File.separator)
      .join(this.rootNotebookFolder, ".git"));
  if (!localRepo.getDirectory().exists()) {
    LOGGER.info("Git repo {} does not exist, creating a new one", localRepo.getDirectory());
    localRepo.create();
  }
  git = new Git(localRepo);
}
 
Example 3
Source File: GitMirrorTest.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
private static void createGitRepo(Repository gitRepo) throws IOException {
    gitRepo.create();

    // Disable GPG signing.
    final StoredConfig config = gitRepo.getConfig();
    config.setBoolean(CONFIG_COMMIT_SECTION, null, CONFIG_KEY_GPGSIGN, false);
    config.save();
}
 
Example 4
Source File: RepositoryHelper.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Repository createRepository(File repo) throws IOException, GitAPIException {
    if (!repo.exists()) {
        Files.createDirectory(repo.toPath());
    }

    Repository repository = FileRepositoryBuilder.create(new File(repo, ".git"));
    repository.create();

    return repository;
}
 
Example 5
Source File: ConfigServerTestUtils.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
public static Repository prepareBareRemote() throws IOException {
	// Create a folder in the temp folder that will act as the remote repository
	File remoteDir = File.createTempFile("remote", "");
	remoteDir.delete();
	remoteDir.mkdirs();

	// Create a bare repository
	FileKey fileKey = FileKey.exact(remoteDir, FS.DETECTED);
	Repository remoteRepo = fileKey.open(false);
	remoteRepo.create(true);

	return remoteRepo;
}
 
Example 6
Source File: GitProjectRepo.java    From writelatex-git-bridge with MIT License 5 votes vote down vote up
@Override
public void initRepo(RepoStore repoStore) throws IOException {
    initRepositoryField(repoStore);
    Preconditions.checkState(repository.isPresent());
    Repository repo = this.repository.get();
    // TODO: assert that this is a fresh repo. At the moment, we can't be
    // sure whether the repo to be init'd doesn't exist or is just fresh
    // and we crashed / aborted while committing
    if (repo.getObjectDatabase().exists()) return;
    repo.create();
}
 
Example 7
Source File: Helper.java    From tutorials with MIT License 5 votes vote down vote up
public static Repository createNewRepository() throws IOException {
    // prepare a new folder
    File localPath = File.createTempFile("TestGitRepository", "");
    if(!localPath.delete()) {
        throw new IOException("Could not delete temporary file " + localPath);
    }

    // create the directory
    Repository repository = FileRepositoryBuilder.create(new File(localPath, ".git"));
    repository.create();

    return repository;
}
 
Example 8
Source File: GitHubNotebookRepoTest.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
  conf = ZeppelinConfiguration.create();

  String remoteRepositoryPath = System.getProperty("java.io.tmpdir") + "/ZeppelinTestRemote_" +
          System.currentTimeMillis();
  String localRepositoryPath = System.getProperty("java.io.tmpdir") + "/ZeppelinTest_" +
          System.currentTimeMillis();

  // Create a fake remote notebook Git repository locally in another directory
  remoteZeppelinDir = new File(remoteRepositoryPath);
  remoteZeppelinDir.mkdirs();

  // Create a local repository for notebooks
  localZeppelinDir = new File(localRepositoryPath);
  localZeppelinDir.mkdirs();

  // Notebooks directory (for both the remote and local directories)
  localNotebooksDir = Joiner.on(File.separator).join(localRepositoryPath, "notebook");
  remoteNotebooksDir = Joiner.on(File.separator).join(remoteRepositoryPath, "notebook");

  File notebookDir = new File(localNotebooksDir);
  notebookDir.mkdirs();
  
  FileUtils.copyDirectory(
      new File(GitHubNotebookRepoTest.class.getResource("/notebook").getFile()),
      new File(remoteNotebooksDir));

  // Create the fake remote Git repository
  Repository remoteRepository = new FileRepository(Joiner.on(File.separator).join(remoteNotebooksDir, ".git"));
  remoteRepository.create();

  remoteGit = new Git(remoteRepository);
  remoteGit.add().addFilepattern(".").call();
  firstCommitRevision = remoteGit.commit().setMessage("First commit from remote repository").call();

  // Set the Git and Git configurations
  System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), remoteZeppelinDir.getAbsolutePath());
  System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());

  // Set the GitHub configurations
  System.setProperty(
          ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(),
          "org.apache.zeppelin.notebook.repo.GitHubNotebookRepo");
  System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_GIT_REMOTE_URL.getVarName(),
          remoteNotebooksDir + File.separator + ".git");
  System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_GIT_REMOTE_USERNAME.getVarName(), "token");
  System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_GIT_REMOTE_ACCESS_TOKEN.getVarName(),
          "access-token");

  // Create the Notebook repository (configured for the local repository)
  gitHubNotebookRepo = new GitHubNotebookRepo();
  gitHubNotebookRepo.init(conf);
}
 
Example 9
Source File: MultiHopFlowCompilerTest.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
@Test (dependsOnMethods = "testUnresolvedFlow")
public void testGitFlowGraphMonitorService()
    throws IOException, GitAPIException, URISyntaxException, InterruptedException {
  File remoteDir = new File(TESTDIR + "/remote");
  File cloneDir = new File(TESTDIR + "/clone");
  File flowGraphDir = new File(cloneDir, "/gobblin-flowgraph");

  //Clean up
  cleanUpDir(TESTDIR);

  // Create a bare repository
  RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED);
  Repository remoteRepo = fileKey.open(false);
  remoteRepo.create(true);

  Git gitForPush = Git.cloneRepository().setURI(remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();

  // push an empty commit as a base for detecting changes
  gitForPush.commit().setMessage("First commit").call();
  RefSpec masterRefSpec = new RefSpec("master");
  gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();

  URI flowTemplateCatalogUri = this.getClass().getClassLoader().getResource("template_catalog").toURI();

  Config config = ConfigBuilder.create()
      .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "."
          + ConfigurationKeys.GIT_MONITOR_REPO_URI, remoteRepo.getDirectory().getAbsolutePath())
      .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TESTDIR + "/git-flowgraph")
      .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5)
      .addPrimitive(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY, flowTemplateCatalogUri.toString())
      .build();

  //Create a MultiHopFlowCompiler instance
  specCompiler = new MultiHopFlowCompiler(config, Optional.absent(), false);

  specCompiler.setActive(true);

  //Ensure node1 is not present in the graph
  Assert.assertNull(specCompiler.getFlowGraph().getNode("node1"));

  // push a new node file
  File nodeDir = new File(flowGraphDir, "node1");
  File nodeFile = new File(nodeDir, "node1.properties");
  nodeDir.mkdirs();
  nodeFile.createNewFile();
  Files.write(FlowGraphConfigurationKeys.DATA_NODE_IS_ACTIVE_KEY + "=true\nparam1=val1" + "\n", nodeFile, Charsets.UTF_8);

  // add, commit, push node
  gitForPush.add().addFilepattern(formNodeFilePath(flowGraphDir, nodeDir.getName(), nodeFile.getName())).call();
  gitForPush.commit().setMessage("Node commit").call();
  gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();

  // polling is every 5 seconds, so wait twice as long and check
  TimeUnit.SECONDS.sleep(10);

  //Test that a DataNode is added to FlowGraph
  DataNode dataNode = specCompiler.getFlowGraph().getNode("node1");
  Assert.assertEquals(dataNode.getId(), "node1");
  Assert.assertEquals(dataNode.getRawConfig().getString("param1"), "val1");
}
 
Example 10
Source File: TestHelper.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@NotNull
static Repository emptyRepository() throws IOException {
  final Repository repository = new InMemoryRepository(new DfsRepositoryDescription(null));
  repository.create();
  return repository;
}
 
Example 11
Source File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with Apache License 2.0 4 votes vote down vote up
private static Repository createRepository() throws IOException {
    File repoDir = Files.createTempDir();
    Repository repo = new FileRepository(new File(repoDir, ".git"));
    repo.create();
    return repo;
}