Refine search
@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 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 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(); }
throw ServerLogger.ROOT_LOGGER.failedToPullRepository(ex, gitConfig.getRepository()); try (Git git = Git.wrap(repository)) { git.clean(); if (!isLocalGitRepository(gitConfig.getRepository())) { String remote = getRemoteName(gitConfig.getRepository()); checkoutToSelectedBranch(git); PullResult result = git.pull().setRemote(remote).setRemoteBranchName(branch).setStrategy(MergeStrategy.RESOLVE).call(); if (!result.isSuccessful()) { throw ServerLogger.ROOT_LOGGER.failedToPullRepository(null, gitConfig.getRepository()); try (Git git = Git.init().setDirectory(baseDir).call()) { final AddCommand addCommand = git.add(); addCommand.addFilepattern("data/content/"); try (Git git = Git.init().setDirectory(baseDir).call()) { String remoteName = UUID.randomUUID().toString(); StoredConfig config = git.getRepository().getConfig();
@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 URI push(File source, String name) throws Exception { init(); File gitRoot = new File("target", name); FileUtils.copyDirectory(source, gitRoot); // Push via port forward String repoUrl = String.format("http://localhost:%s/%s", GIT_LOCALPORT, name); Git git = Git.init().setDirectory(gitRoot).call(); Repository repo = git.getRepository(); repo.getConfig().setString("remote", "origin", "url", repoUrl); repo.getConfig().save(); git.add().addFilepattern(".").call(); git.commit().setMessage("testing").setAuthor("Arquillian", "cube@discuss.arquillian.org").call(); git.push().setRemote("origin").setPushAll().setForce(true).call(); repo.close(); // Return an internal service name, for use within the openshift network String serverUrl = String.format("http://%s:%s/%s", GIT_SERVICE, GIT_REMOTEPORT, name); return URI.create(serverUrl); }
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; }
@Override public Git findOrCreateGitRepository(File directory, boolean bare) throws IOException { try { return Git.open(directory); } catch (RepositoryNotFoundException fallback) { try { Git git = Git.init() .setBare(bare && !isFabric) .setDirectory(directory) .setGitDir(bare && !isFabric ? directory : new File(directory, Constants.DOT_GIT)) .call(); fork.tag() .setName("patch-management") .setObjectId(commit)
boolean cloneAll = isCloneAllBranches(); LOG.info("Cloning git repo " + repo + " into directory " + confDir.getCanonicalPath() + " cloneAllBranches: " + cloneAll); CloneCommand command = Git.cloneRepository().setCredentialsProvider(getCredentials()). setCloneAllBranches(cloneAll).setURI(repo).setDirectory(confDir).setRemote(remote); try { LOG.info("Clone git repo on startup disabled"); InitCommand initCommand = Git.init(); initCommand.setDirectory(confDir); git = initCommand.call(); LOG.info("Initialised an empty git configuration repo at {}", confDir.getCanonicalPath()); String branch = git.getRepository().getBranch(); configureBranch(branch);
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); } }
InitCommand initCommand = Git.init(); initCommand.setDirectory(basedir); Git git = initCommand.call(); LOG.info("Initialised an empty git configuration repo at {}", basedir.getAbsolutePath()); Git git = new Git(repository); String remote = getRemote(git, branch); if (remote == null) {
public static Git createGit(Path root, boolean create) { try { final Path gitDir = getGitFile(root); final boolean actuallyCreate = create && !Files.isDirectory(gitDir); if (actuallyCreate) Files.createDirectories(root); final FileRepository repository = new FileRepository(gitDir.toFile()); if (actuallyCreate) repository.create(); final Git git = new Git(repository); if (create) { if (!Files.isDirectory(gitDir)) try { Git.init().setGitDir(gitDir.toFile()).call(); } catch (GitAPIException exception) { throw new RuntimeException("Failed to initialize new git repository in " + root, exception); } } return git; } catch (IOException exception) { throw new RuntimeIOException(exception); } }
throw ServerLogger.ROOT_LOGGER.failedToPullRepository(ex, gitConfig.getRepository()); try (Git git = Git.wrap(repository)) { git.clean(); if (!isLocalGitRepository(gitConfig.getRepository())) { String remote = getRemoteName(gitConfig.getRepository()); checkoutToSelectedBranch(git); PullResult result = git.pull().setRemote(remote).setRemoteBranchName(branch).setStrategy(MergeStrategy.RESOLVE).call(); if (!result.isSuccessful()) { throw ServerLogger.ROOT_LOGGER.failedToPullRepository(null, gitConfig.getRepository()); try (Git git = Git.init().setDirectory(baseDir).call()) { final AddCommand addCommand = git.add(); addCommand.addFilepattern("data/content/"); try (Git git = Git.init().setDirectory(baseDir).call()) { String remoteName = UUID.randomUUID().toString(); StoredConfig config = git.getRepository().getConfig();
@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; }
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; } }
@Override public Git findOrCreateGitRepository(File directory, boolean bare) throws IOException { try { return Git.open(directory); } catch (RepositoryNotFoundException fallback) { try { Git git = Git.init() .setBare(bare && !isFabric) .setDirectory(directory) .setGitDir(bare && !isFabric ? directory : new File(directory, Constants.DOT_GIT)) .call(); fork.tag() .setName("patch-management") .setObjectId(commit)
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(); }