@Signature public void __construct(File directory, boolean create) throws IOException, GitAPIException { try { __wrappedObject = Git.open(directory, FS.DETECTED); } catch (RepositoryNotFoundException e) { if (create) { Git.init().setBare(false).setDirectory(directory).call(); __wrappedObject = Git.open(directory, FS.DETECTED); } } }
private static File createRepository() throws IOException, GitAPIException { File dir = File.createTempFile("gitinit", ".test"); if(!dir.delete()) { throw new IOException("Could not delete temporary file " + dir); } Git.init() .setDirectory(dir) .call(); try (Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), ".git"))) { System.out.println("Created a new repository at " + repository.getDirectory()); } return dir; } }
public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException { // prepare a new folder File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // create the directory try (Git git = Git.init().setDirectory(localPath).call()) { System.out.println("Having repository: " + git.getRepository().getDirectory()); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
private static File createRepository() throws IOException, GitAPIException { File dir = File.createTempFile("gitinit", ".test"); if(!dir.delete()) { throw new IOException("Could not delete temporary file " + dir); } Git.init() .setDirectory(dir) .call(); try (Repository repository = FileRepositoryBuilder.create(new File(dir.getAbsolutePath(), ".git"))) { System.out.println("Created a new repository at " + repository.getDirectory()); } return dir; } }
public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException { // prepare a new folder File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // create the directory try (Git git = Git.init().setDirectory(localPath).call()) { System.out.println("Having repository: " + git.getRepository().getDirectory()); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
try (Git git = Git.init() .setDirectory(dir) .call()) {
try (Git git = Git.init() .setDirectory(dir) .call()) {
/** * Init git repo with bare * * @param gitPath xxx.git folder * @throws GitException */ public static void init(Path gitPath, boolean bare) throws GitException { try { if (bare) { Git.init().setBare(bare).setGitDir(gitPath.toFile()).call(); } else { Git.init().setDirectory(gitPath.toFile()).call(); } } catch (GitAPIException e) { throw new GitException(e.getMessage()); } }
private Repository init() throws GitAPIException { InitCommand command = Git.init(); command.setBare(bare); if (fs != null) { command.setFs(fs); } if (directory != null) { command.setDirectory(directory); } if (gitDir != null) { command.setGitDir(gitDir); } return command.call().getRepository(); }
/** * Create local .git with remote info * * @return .git file path, /targetDir/.git */ private File initGit(Set<String> checkoutFiles) throws GitException { try (Git git = Git.init().setDirectory(targetDir.toFile()).call()) { Repository repository = git.getRepository(); File gitDir = repository.getDirectory(); setSparseCheckout(gitDir, checkoutFiles); configRemote(repository.getConfig(), "origin", gitUrl); return gitDir; } catch (GitAPIException e) { throw new GitException("Fail to init git repo at: " + targetDir, e); } }
private Git openOrInit(File localRepo) throws IOException { try { return Git.open(localRepo); } catch (RepositoryNotFoundException e) { try { return Git.init().setDirectory(localRepo).call(); } catch (GitAPIException ex) { throw new IOException(ex); } } }
@Override protected void run() throws Exception { InitCommand command = Git.init(); command.setBare(bare); if (gitdir != null) command.setDirectory(new File(gitdir)); Repository repository = command.call().getRepository(); outw.println(MessageFormat.format( CLIText.get().initializedEmptyGitRepositoryIn, repository .getDirectory().getAbsolutePath())); } }
public boolean init() { try { Git.init().setDirectory(mRepo.getDir()).call(); } catch (Throwable e) { setException(e); return false; } return true; } }
public boolean init() { try { Git.init().setDirectory(mRepo.getDir()).call(); } catch (Throwable e) { setException(e); return false; } return true; } }
public static String createGitRepo(File src) throws IOException, GitAPIException { Path tmpDir = createTempDir(); IOUtils.copy(src.toPath(), tmpDir); Git repo = Git.init().setDirectory(tmpDir.toFile()).call(); repo.add().addFilepattern(".").call(); repo.commit().setMessage("import").call(); return tmpDir.toAbsolutePath().toString(); }
private Git createLocalRepo(Path path) throws IOException, GitAPIException { Files.delete(path); return Git.init() .setDirectory(path.toFile()) .call(); }
public static Git newRepository( final File repoFolder, final boolean bare ) throws IOException { checkNotNull( "repoFolder", repoFolder ); try { return Git.init().setBare( bare ).setDirectory( repoFolder ).call(); } catch ( GitAPIException e ) { throw new IOException( e ); } }
public static Git newRepository(final File repoFolder) throws IOException { checkNotNull("repoFolder", repoFolder); try { return Git.init().setBare(true).setDirectory(repoFolder).call(); } catch (GitAPIException e) { throw new IOException(e); } }
@BeforeClass public static void createGitRepository() throws GitAPIException, IOException { gitRepository = new File(System.getProperty("user.dir"), "target/git-repository/"); Git git = Git.init().setDirectory(gitRepository).call(); URL pomUrl = RestTestBase.class.getResource("/pom.xml"); File pomFile = new File(gitRepository, "pom.xml"); FileUtils.copyURLToFile(pomUrl, pomFile); git.add().addFilepattern("pom.xml").call(); git.commit().setMessage("Add pom.xml").call(); }
protected Git setupGit( final File tempDir ) throws IOException, GitAPIException { final Git git = Git.init().setBare( true ).setDirectory( tempDir ).call(); commit( git, "master", "name", "name@example.com", "cool1", null, null, false, new HashMap<String, File>() {{ put( "file1.txt", tempFile( "content" ) ); put( "file2.txt", tempFile( "content2" ) ); }} ); return git; }