Package org.eclipse.jgit.storage.file

Examples of org.eclipse.jgit.storage.file.FileRepository


            dotGit = gitRoot;
        } else {
            dotGit = new File(gitRoot, Constants.DOT_GIT);
        }

        FileRepository repository = localRepos.get(dotGit);
        if (repository != null && dotGit.exists()) {
            return repository;
        }

        if (!dotGit.exists()) {
            Git.cloneRepository().setDirectory(gitRoot).setCloneAllBranches(true).setURI(gitUrl).call();
            FileBasedConfig config = new FileBasedConfig(new File(dotGit, "config"), FS.DETECTED);
            config.load();
            if (gitPushUrl != null) {
                config.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "pushurl", gitPushUrl);
            }
            config.save();
        }

        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        repository = builder.setGitDir(dotGit).readEnvironment().findGitDir().build();
        localRepos.put(dotGit, repository);
        try {
            repository.incrementOpen();
            Git git = Git.wrap(repository);

            // Check branch
            boolean pull = true;
            String currentBranch = repository.getBranch();
            if (branch != null && !branch.equals(currentBranch)) {
                CheckoutCommand checkout = git.checkout();
                if (!branchExists(git, branch)) {
                    checkout.setCreateBranch(true);
                    pull = false;
                }
                checkout.setName(branch);
                checkout.call();
            }
            if (pull) {
                git.pull().call();
            } else {
                git.fetch().call();
            }
        } catch (Exception e) {
            if (!(e.getCause() instanceof TransportException)) {
                throw new RuntimeException(e);
            }
        } finally {
            if (repository != null) {
                repository.close();
            }
        }

        return repository;
    }
View Full Code Here


    InternalLocalFetchConnection() throws TransportException {
      super(TransportLocal.this);

      final Repository dst;
      try {
        dst = new FileRepository(remoteGitDir);
      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
View Full Code Here

    InternalLocalPushConnection() throws TransportException {
      super(TransportLocal.this);

      final Repository dst;
      try {
        dst = new FileRepository(remoteGitDir);
      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
View Full Code Here

   *             the repository could not be accessed to configure the rest of
   *             the builder's parameters.
   */
  @SuppressWarnings("unchecked")
  public R build() throws IOException {
    R repo = (R) new FileRepository(setup());
    if (isMustExist() && !repo.getObjectDatabase().exists())
      throw new RepositoryNotFoundException(getGitDir());
    return repo;
  }
View Full Code Here

   {
      try
      {
         final URIish uri = new URIish(sourceUri);
         File gitdir = new File(projectDir, Constants.DOT_GIT);
         db = new FileRepository(gitdir);
         db.create();
         final FileBasedConfig dstcfg = db.getConfig();
         dstcfg.setBoolean("core", null, "bare", false);
         dstcfg.save();
View Full Code Here

    InternalLocalFetchConnection() throws TransportException {
      super(TransportLocal.this);

      final Repository dst;
      try {
        dst = new FileRepository(remoteGitDir);
      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
View Full Code Here

    InternalLocalPushConnection() throws TransportException {
      super(TransportLocal.this);

      final Repository dst;
      try {
        dst = new FileRepository(remoteGitDir);
      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
View Full Code Here

   *             the repository could not be accessed to configure the rest of
   *             the builder's parameters.
   */
  @SuppressWarnings("unchecked")
  public R build() throws IOException {
    R repo = (R) new FileRepository(setup());
    if (isMustExist() && !repo.getObjectDatabase().exists())
      throw new RepositoryNotFoundException(getGitDir());
    return repo;
  }
View Full Code Here

                                              new UsernamePasswordCredentialsProvider(
                                                                                      System.getProperty(CartridgeConstants.INTERNAL_GIT_USERNAME),
                                                                                      System.getProperty(CartridgeConstants.INTERNAL_GIT_PASSWORD).toCharArray());
    // Clone
    // --------------------------
    FileRepository localRepo = null;
    try {
      localRepo = new FileRepository(new File(parentDirName + "/.git"));
    } catch (IOException e) {
      log.error("Exception occurred in creating a new file repository. Reason: " + e.getMessage());
      throw e;
    }
View Full Code Here

      }
      credentialsProvider = new UsernamePasswordCredentialsProvider(repoUsername, repoPassword.toCharArray());
    }

    // Initialize temp local file repo
    FileRepository localRepo = null;
    try {
      File f = new File(parentDirName + "/.git");
      localRepo = new FileRepository(f);
      if (log.isDebugEnabled()) {
        log.debug("Local File Repo: " + f.getAbsoluteFile());
      }
    } catch (IOException e) {
      throw new ADCException("Error creating local file repo", e);
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.storage.file.FileRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.