@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); } } }
/** * 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(); }
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }
public static void InitGitRepository(File gitRepoDir) throws Exception { try { Git.init().setDirectory(gitRepoDir).setBare(false).call(); } catch (GitAPIException e) { String errorMsg = "Initializing local repo at " + gitRepoDir.getPath() + " failed"; log.error(errorMsg, e); throw new Exception(errorMsg, e); } }
private void doInit(String workspace, boolean bare) throws GitException { try { Git.init().setBare(bare).setDirectory(new File(workspace)).call(); } catch (GitAPIException e) { throw new GitException(e); } }
@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())); } }
private Repository init(URIish u) throws GitAPIException { InitCommand command = Git.init(); command.setBare(bare); if (directory == null && gitDir == null) directory = new File(u.getHumanishName(), Constants.DOT_GIT); validateDirs(directory, gitDir, bare); if (directory != null && directory.exists() && directory.listFiles().length != 0) throw new JGitInternalException(MessageFormat.format( JGitText.get().cloneNonEmptyDirectory, directory.getName())); if (gitDir != null && gitDir.exists() && gitDir.listFiles().length != 0) throw new JGitInternalException(MessageFormat.format( JGitText.get().cloneNonEmptyDirectory, gitDir.getName())); if (directory != null) command.setDirectory(directory); if (gitDir != null) command.setGitDir(gitDir); return command.call().getRepository(); }
protected void doInit(Exchange exchange, String operation) throws Exception { Git result = null; if (ObjectHelper.isEmpty(endpoint.getLocalPath())) { throw new IllegalArgumentException("Local path must specified to execute " + operation); } try { result = Git.init().setDirectory(new File(endpoint.getLocalPath(), "")).setBare(false).call(); } catch (Exception e) { LOG.error("There was an error in Git {} operation", operation); throw e; } finally { if (ObjectHelper.isNotEmpty(result)) { result.close(); } } }
@Override public void execute() throws BuildException { if (bare) { log("Initializing bare repository at " + destination); } else { log("Initializing repository at " + destination); } try { InitCommand init = Git.init(); init.setBare(bare).setDirectory(destination); init.call(); } catch (Exception e) { throw new BuildException("Could not initialize repository", e); } } }
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); } }
public static BackupService prepare(File localDir, URIish remoteUri, int backupTimeInMinutes) throws GitAPIException, IOException { Git local; try { local = Git.open(localDir); } catch (RepositoryNotFoundException e) { log.info("Initialising " + fullPath(localDir) + " as a git repo for backup purposes"); local = Git.init().setDirectory(localDir).setBare(false).call(); } log.info("Setting backup URL to " + remoteUri); if (local.remoteList().call().stream().anyMatch(remoteConfig -> remoteConfig.getName().equals("origin"))) { RemoteSetUrlCommand remoteSetUrlCommand = local.remoteSetUrl(); remoteSetUrlCommand.setName("origin"); remoteSetUrlCommand.setUri(remoteUri); remoteSetUrlCommand.call(); } else { RemoteAddCommand remoteAddCommand = local.remoteAdd(); remoteAddCommand.setName("origin"); remoteAddCommand.setUri(remoteUri); remoteAddCommand.call(); } URL inputUrl = BackupService.class.getResource("/dataDirGitIgnore.txt"); FileUtils.copyURLToFile(inputUrl, new File(localDir, ".gitignore")); return new BackupService(local, remoteUri.toString(), backupTimeInMinutes); } }
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(); }
private Git createBareRepository(File root) throws GitAPIException { return Git.init().setDirectory(root).setBare(true).call(); }
private Git createBareRepository(File root) throws GitAPIException { return Git.init().setDirectory(root).setBare(true).call(); }
@Override public Git cloneRepository(Git git, boolean fetchAndCheckout) throws GitAPIException, IOException { File tmpLocation = new File(tmpPatchManagement, TS.format(new Date())); Git fork = Git.init().setBare(false) .setGitDir(new File(tmpLocation, Constants.DOT_GIT)) .setDirectory(tmpLocation).call(); StoredConfig config = fork.getRepository().getConfig(); config.setString("remote", "origin", "url", git.getRepository().getDirectory().getCanonicalPath()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); if (fetchAndCheckout) { fork.fetch() .setRemote("origin") .setTagOpt(TagOpt.FETCH_TAGS) .call(); fork.checkout() .setCreateBranch(true) .setName(getMainBranchName()) .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) .setStartPoint("origin/" + getMainBranchName()) .call(); } return fork; }
public void initRepo() { if (exists()) { return; } try { Git.init().setDirectory(getRootDir()).setBare(false).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } }
public static Path createBareRepository(Path data, String commitMessage) throws Exception { // init bare repository Path repo = createTempDir(); Git.init().setBare(true).setDirectory(repo.toFile()).call(); // clone the repository into a new directory Path workdir = createTempDir(); Git git = Git.cloneRepository() .setDirectory(workdir.toFile()) .setURI("file://" + repo.toString()) .call(); // copy our files into the repository IOUtils.copy(data, workdir); // add, commit, and push copied files git.add().addFilepattern(".").call(); git.commit().setMessage(commitMessage).call(); git.push().call(); return repo; }
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; }