/** * 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(); }
private Git openOrInit(File localRepo) throws IOException { try { return Git.open(localRepo); } catch (RepositoryNotFoundException e) { try { return Git.init().setDirectory(localRepo) .setGitDir(new File(localRepo, Constants.DOT_GIT)) .call(); } catch (GitAPIException ex) { throw new IOException(ex); } } }
public GitConfigurationPersister(GitRepository gitRepository, ConfigurationFile file, QName rootElement, XMLElementReader<List<ModelNode>> rootParser, XMLElementWriter<ModelMarshallingContext> rootDeparser, boolean suppressLoad) { super(file.getBootFile(), rootElement, rootParser, rootDeparser, suppressLoad); root = file.getConfigurationDir().getParentFile().toPath(); mainFile = file.getMainFile(); this.gitRepository = gitRepository; File baseDir = root.toFile(); try { File gitDir = new File(baseDir, Constants.DOT_GIT); if(!gitDir.exists()) { gitDir.mkdir(); } if (gitRepository.isBare()) { Git.init().setDirectory(baseDir).setGitDir(gitDir).call(); ServerLogger.ROOT_LOGGER.gitRespositoryInitialized(baseDir.getAbsolutePath()); } } catch (IllegalStateException | GitAPIException e) { ControllerLogger.ROOT_LOGGER.error(e); } }
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); } }
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(); }
public GitConfigurationPersister(GitRepository gitRepository, ConfigurationFile file, QName rootElement, XMLElementReader<List<ModelNode>> rootParser, XMLElementWriter<ModelMarshallingContext> rootDeparser, boolean suppressLoad) { super(file.getBootFile(), rootElement, rootParser, rootDeparser, suppressLoad); root = file.getConfigurationDir().getParentFile().toPath(); mainFile = file.getMainFile(); this.gitRepository = gitRepository; File baseDir = root.toFile(); try { File gitDir = new File(baseDir, Constants.DOT_GIT); if(!gitDir.exists()) { gitDir.mkdir(); } if (gitRepository.isBare()) { Git.init().setDirectory(baseDir).setGitDir(gitDir).call(); ServerLogger.ROOT_LOGGER.gitRespositoryInitialized(baseDir.getAbsolutePath()); } } catch (IllegalStateException | GitAPIException e) { ControllerLogger.ROOT_LOGGER.error(e); } }
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(); }
@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; }
@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; }
.setBare(bare && !isFabric) .setDirectory(directory) .setGitDir(bare && !isFabric ? directory : new File(directory, Constants.DOT_GIT)) .call();
.setBare(bare && !isFabric) .setDirectory(directory) .setGitDir(bare && !isFabric ? directory : new File(directory, Constants.DOT_GIT)) .call();