Package org.eclipse.jgit.api

Examples of org.eclipse.jgit.api.Git


  private boolean shownURI;

  @Override
  protected void run() throws Exception {
    Git git = new Git(db);
    PushCommand push = git.push();
    push.setDryRun(dryRun);
    push.setForce(force);
    push.setProgressMonitor(new TextProgressMonitor());
    push.setReceivePack(receivePack);
    push.setRefSpecs(refSpecs);
View Full Code Here


      outw.println(CLIText.formatLine(
          MessageFormat.format(CLIText.get().onBranch, branch)));
    } else
      outw.println(CLIText.formatLine(CLIText.get().notOnAnyBranch));
    // List changes
    StatusCommand statusCommand = new Git(db).status();
    if (filterPaths != null && filterPaths.size() > 0)
      for (String path : filterPaths)
        statusCommand.addPath(path);
    org.eclipse.jgit.api.Status status = statusCommand.call();
    Collection<String> added = status.getAdded();
View Full Code Here

      throw new MojoFailureException("app is not set");

    if (!stagingDirectory.exists())
      throw new MojoFailureException("Inexistant staging directory. Create one with heroku:prepare");

    Git repo = Git.open(stagingDirectory);

    String remoteUrl = "git@heroku.com:" + app + ".git";
   
    StoredConfig config = repo.getRepository().getConfig();
   
    config.setString("remote", "heroku", "url", remoteUrl);
   
    config.save();

    log("Pushing from %s to %s", stagingDirectory, remoteUrl);

    JschConfigSessionFactory sessionFactory = new JschConfigSessionFactory() {
      @Override
      protected void configure(OpenSshConfig.Host hc, Session session) {
        session.setConfig("StrictHostKeyChecking", "no");
        session.setConfig("IdentityFile", sshKey);
       
        CredentialsProvider provider = new CredentialsProvider() {
          @Override
          public boolean isInteractive() {
            return false;
          }

          @Override
          public boolean supports(CredentialItem... items) {
            return true;
          }

          @Override
          public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
            //for (CredentialItem item : items) {
            //  ((CredentialItem.StringType) item).setValue("yourpassphrase");
            //}
            return true;
          }
        };
        UserInfo userInfo = new CredentialsProviderUserInfo(session, provider);
        session.setUserInfo(userInfo);
      }
    };
    SshSessionFactory.setInstance(sessionFactory);

    PushCommand pushCommand = repo.push().setRemote(remoteUrl).add("master").setProgressMonitor(new TextProgressMonitor()).setForce(true);
       
    pushCommand.call();
  }
View Full Code Here

    }

    @Override
    public JGitFlow call() throws JGitFlowException
    {
        Git git = null;

        if (null == this.context)
        {
            this.context = new InitContext();
        }

        try
        {
            git = getOrInitGit(directory);
        }
        catch (IOException e)
        {
            throw new JGitFlowException(e);
        }
        catch (GitAPIException e)
        {
            throw new JGitFlowException(e);
        }

        Repository repo = git.getRepository();
        GitFlowConfiguration gfConfig = new GitFlowConfiguration(git);
        RevWalk walk = null;
        try
        {
            if (!force && gfConfig.gitFlowIsInitialized())
            {
                throw new AlreadyInitializedException("Already initialized for git flow.");
            }

            //First setup master
            if (gfConfig.hasMasterConfigured() && !force)
            {
                context.setMaster(gfConfig.getMaster());
            }
            else
            {
                //if no local master exists, but a remote does, check it out
                if (!GitHelper.localBranchExists(git, context.getMaster()) && GitHelper.remoteBranchExists(git, context.getMaster()))
                {
                    git.branchCreate()
                       .setName(context.getMaster())
                       .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
                       .setStartPoint("origin/" + context.getMaster())
                       .call();
                }
            }

            gfConfig.setMaster(context.getMaster());


            //now setup develop
            if (gfConfig.hasDevelopConfigured() && !force)
            {
                context.setDevelop(gfConfig.getDevelop());
            }

            if (context.getDevelop().equals(context.getMaster()))
            {
                throw new JGitFlowException("master and develop branches cannot be the same: [" + context.getMaster() + "]");
            }

            gfConfig.setDevelop(context.getDevelop());

            //Creation of HEAD
            walk = new RevWalk(repo);
            ObjectId masterBranch = repo.resolve(Constants.R_HEADS + context.getMaster());
            RevCommit masterCommit = null;

            if (null != masterBranch)
            {
                try
                {
                    masterCommit = walk.parseCommit(masterBranch);
                }
                catch (MissingObjectException e)
                {
                    //ignore
                }
                catch (IncorrectObjectTypeException e)
                {
                    //ignore
                }
            }

            if (null == masterCommit)
            {
                RefUpdate refUpdate = repo.getRefDatabase().newUpdate(Constants.HEAD, false);
                refUpdate.setForceUpdate(true);
                refUpdate.link(Constants.R_HEADS + context.getMaster());

                git.commit().setMessage("Initial Commit").call();
            }

            //creation of develop
            if (!GitHelper.localBranchExists(git, context.getDevelop()))
            {
                if (GitHelper.remoteBranchExists(git, context.getDevelop()))
                {
                    git.branchCreate()
                       .setName(context.getDevelop())
                       .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
                       .setStartPoint("origin/" + context.getDevelop())
                       .call();
                }
                else
                {
                    git.branchCreate()
                       .setName(context.getDevelop())
                       .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK)
                       .call();
                }
            }
            git.checkout().setName(context.getDevelop()).call();

            //setup prefixes
            for (String prefixName : gfConfig.getPrefixNames())
            {
                if (!gfConfig.hasPrefixConfigured(prefixName) || force)
View Full Code Here

        return this;
    }

    private Git getOrInitGit(File folder) throws IOException, GitAPIException
    {
        Git gitRepo;
        try
        {
            gitRepo = Git.open(folder);
        }
        catch (RepositoryNotFoundException e)
View Full Code Here

    public static JGitFlow get(File tempDir) throws JGitFlowException
    {
        try
        {
            Git gitRepo = Git.open(tempDir);
            GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo);
            return new JGitFlow(gitRepo,gfConfig);
        }
        catch (IOException e)
        {
View Full Code Here

    public static boolean isInitialized(File dir)
    {
        boolean inited = false;
        try
        {
            Git gitRepo = Git.open(dir);
            GitFlowConfiguration gfConfig = new GitFlowConfiguration(gitRepo);
            inited = gfConfig.gitFlowIsInitialized();
        }
        catch (IOException e)
        {
View Full Code Here

    region = defaultIfBlank(region, "us-east-1");
  }

  @Override
  protected Object executeInternal() throws Exception {
    Git git = getGitRepo();
    String versionLabel = null;

    String commitId = null;

    Ref masterRef = git.getRepository()
        .getRef("master");
    if (null != masterRef)
      commitId = ObjectId.toString(masterRef.getObjectId());

    Status status = git.status().call();

    boolean pushAhead = false;

    if (null != commitId && status.isClean()) {
      versionLabel = lookupVersionLabelForCommitId(commitId);

      if (null == versionLabel) {
        getLog().info("No Changes. However, we've didn't get something close in AWS Elastic Beanstalk and we're pushing ahead");
        pushAhead = true;
      } else {
        getLog().info("No Changes. However, we've got something close in AWS Elastic Beanstalk and we're continuing");

        project.getProperties().put("beanstalk.versionLabel", versionLabel);

        return null;
      }
    }

    if (!pushAhead) {
      // Asks for Existing Files to get added
      git.add().setUpdate(true).addFilepattern(".").call();

      // Now as for any new files (untracked)

      AddCommand addCommand = git.add();

      if (!status.getUntracked().isEmpty()) {
        for (String s : status.getUntracked()) {
          getLog().info("Adding file " + s);
          addCommand.addFilepattern(s);
        }

        addCommand.call();
      }

      git.commit().setAll(true).setMessage(versionDescription).call();

      masterRef = git.getRepository()
          .getRef("master");

      commitId = ObjectId.toString(masterRef.getObjectId());
    }

    String environmentName = null;

    /*
     * Builds the remote push URL
     */
    if (null != curEnv && !skipEnvironmentUpdate)
      environmentName = curEnv.getEnvironmentName();

    String remote = new RequestSigner(getAWSCredentials(), applicationName,
        region, commitId, environmentName, new Date()).getPushUrl();

    /*
     * Does the Push
     */
    {
      PushCommand cmd = git.//
          push();

      cmd.setProgressMonitor(new TextProgressMonitor());

      Iterable<PushResult> pushResults = null;
View Full Code Here

    return versionLabel;
  }

  private Git getGitRepo() throws Exception {
    Git git = null;

    if (!useStagingDirectory) {
      File gitRepo = new File(sourceDirectory, ".git");

      if (!gitRepo.exists()) {
View Full Code Here

public class FeatureFinishTest extends BaseGitFlowTest
{
    @Test
    public void finishFeature() throws Exception
    {
        Git git = RepoUtil.createRepositoryWithMasterAndDevelop(newDir());
        JGitFlowInitCommand initCommand = new JGitFlowInitCommand();
        JGitFlow flow = initCommand.setDirectory(git.getRepository().getWorkTree()).call();

        flow.featureStart("my-feature").call();

        //just in case
        assertEquals(flow.getFeatureBranchPrefix() + "my-feature", git.getRepository().getBranch());
       
        flow.featureFinish("my-feature").call();

        //we should be on develop branch
        assertEquals(flow.getDevelopBranchName(), git.getRepository().getBranch());
       
        //feature branch should be gone
        Ref ref2check = git.getRepository().getRef(flow.getFeatureBranchPrefix() + "my-feature");
        assertNull(ref2check);

    }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.api.Git

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.