Package org.eclipse.jgit.api

Examples of org.eclipse.jgit.api.Git


    {
        product.visit(SpeakeasyUserPage.class)
                .openInstallDialog()
                .uploadPlugin(buildSimplePluginFile("git", "Git test"));

        Git git = gitClone(product.getProductInstance(), "git");
        File mf = new File(git.getRepository().getWorkTree(), "atlassian-plugin.xml");
        assertTrue(mf.exists());

        FileUtils.writeStringToFile(mf, FileUtils.readFileToString(mf).replace("Git test", "Git changed test"));
        git.commit()
                .setAll(true)
                .setMessage("changed")
                .setCommitter("admin", "admin@example.com")
                .call();
        git.push()
                .setRemote("origin")
                .setCredentialsProvider(new UsernamePasswordCredentialsProvider("admin", "admin"))
                .call();
        SpeakeasyUserPage page = product.visit(SpeakeasyUserPage.class);
        assertEquals("Git changed test", page.getPlugins().get("git").getName());
View Full Code Here


    }

    @Test
    public void testPushNew() throws IOException, MessagingException, URISyntaxException, NoHeadException, NoMessageException, ConcurrentRefUpdateException, WrongRepositoryStateException, InvalidRemoteException, NoFilepatternException
    {
        Git git = createNewLocalRepository(product.getProductInstance(), "git-pushNew");
        push(git, "origin");
        SpeakeasyUserPage page = product.visit(SpeakeasyUserPage.class);
        assertTrue(page.getPluginKeys().contains("git-pushNew"));
        page.uninstallPlugin("git-pushNew");
    }
View Full Code Here

    }

    @Test
    public void testPushNewAsTwoKeys() throws IOException, MessagingException, URISyntaxException, NoHeadException, NoMessageException, ConcurrentRefUpdateException, WrongRepositoryStateException, InvalidRemoteException, NoFilepatternException
    {
        Git git = createNewLocalRepository(product.getProductInstance(), "git-pushFirst");
        addRemote(product.getProductInstance(), "git-pushSecond", "second", git);
        push(git, "origin");
        push(git, "second");
        SpeakeasyUserPage page = product.visit(SpeakeasyUserPage.class);
        assertTrue(page.getPluginKeys().contains("git-pushFirst"));
View Full Code Here

    }

    private void updateRepositoryIfDirty(Repository repo, AbstractExtensionEvent event, Bundle bundle) throws IOException, NoFilepatternException, NoHeadException, NoMessageException, ConcurrentRefUpdateException, WrongRepositoryStateException
    {
        final File workTree = repo.getWorkTree();
        Git git = new Git(repo);

        Set<File> workTreeFilesToDelete = findFiles(repo.getWorkTree());
        for (String path : getPublicBundlePathsRecursive(bundle, ""))
        {
            File target = new File(workTree, path);
            workTreeFilesToDelete.remove(target);
            if (path.endsWith("/"))
            {
                target.mkdirs();
            }
            else
            {
                FileOutputStream fout = null;
                try
                {
                    fout = new FileOutputStream(target);
                    IOUtils.copy(bundle.getResource(path).openStream(), fout);
                    fout.close();
                }
                finally
                {
                    IOUtils.closeQuietly(fout);
                }
                git.add().addFilepattern(path).call();
            }
        }
        for (File file : workTreeFilesToDelete)
        {
            FileUtils.deleteQuietly(file);
        }

        Status status = git.status().call();
        if (!status.getAdded().isEmpty() ||
            !status.getChanged().isEmpty() ||
            !status.getMissing().isEmpty() ||
            !status.getRemoved().isEmpty() ||
            !status.getUntracked().isEmpty())
        {
            git.commit().
                setAll(true).
                setAuthor(event.getUserName(), event.getUserEmail()).
                setCommitter("speakeasy", "speakeasy@atlassian.com").
                setMessage(event.getMessage()).
                call();
View Full Code Here

    {
        File jar = executor.forKey(pluginKey, SYNC_EVENT, new Operation<Repository, File>()
        {
            public File operateOn(Repository repo) throws Exception
            {
                Git git = new Git(repo);
                if (repo.getAllRefs().containsKey("refs/heads/master"))
                {
                    git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
                    for (String path : git.status().call().getUntracked())
                    {
                        new File(repo.getWorkTree(), path).delete();
                    }
                }
                return ZipWriter.addDirectoryContentsToJar(repo.getWorkTree(), ".git");
View Full Code Here

        });
    }

    private void cloneRepository(Repository repo, String forkedPluginKey)
    {
        Git git = new Git(repo);
        git.cloneRepository()
            .setURI(repo.getDirectory().toURI().toString())
            .setDirectory(new File(repositoriesDir, forkedPluginKey))
            .setBare(false)
            .call();
        executor.forKey(forkedPluginKey, SYNC_EVENT, new Operation<Repository, Void>()
View Full Code Here

    protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
                                                      ScmVersion version )
        throws ScmException
    {

        Git git = null;
        try
        {
            File basedir = fileSet.getBasedir();
            git = Git.open( basedir );

            boolean doCommit = false;

            if ( !fileSet.getFileList().isEmpty() )
            {
                doCommit = JGitUtils.addAllFiles( git, fileSet ).size() > 0;
            }
            else
            {
                // add all tracked files which are modified manually
                Set<String> changeds = git.status().call().getModified();
                if ( changeds.isEmpty() )
                {
                    // warn there is nothing to add
                    getLogger().warn( "there are no files to be added" );
                    doCommit = false;
                }
                else
                {
                    AddCommand add = git.add();
                    for ( String changed : changeds )
                    {
                        getLogger().debug( "add manualy: " + changed );
                        add.addFilepattern( changed );
                        doCommit = true;
                    }
                    add.call();
                }
            }

            List<ScmFile> checkedInFiles = Collections.emptyList();
            if ( doCommit )
            {
                RevCommit commitRev = git.commit().setMessage( message ).call();
                getLogger().info( "commit done: " + commitRev.getShortMessage() );
                checkedInFiles = JGitUtils.getFilesInCommit( git.getRepository(), commitRev );
                if ( getLogger().isDebugEnabled() )
                {
                    for ( ScmFile scmFile : checkedInFiles )
                    {
                        getLogger().debug( "in commit: " + scmFile );
                    }
                }
            }

            if ( repo.isPushChanges() )
            {
                String branch = version != null ? version.getName() : null;
                if ( StringUtils.isBlank( branch ) )
                {
                    branch = git.getRepository().getBranch();
                }
                RefSpec refSpec = new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_HEADS + branch );
                getLogger().info( "push changes to remote... " + refSpec.toString() );
                JGitUtils.push( getLogger(), git, (GitScmProviderRepository) repo, refSpec );
            }
View Full Code Here

      }
    } catch (IOException e) {
      throw new ADCException("Error creating local file repo", e);
    }

    Git git = new Git(localRepo);
    LsRemoteCommand cmd = git.lsRemote().setRemote(repoURL);
    if (credentialsProvider != null) {
      cmd.setCredentialsProvider(credentialsProvider);
    }
    try {
      Collection<Ref> collection = cmd.call();
View Full Code Here

     */
    @Override
    public JGitFlow call() throws JGitFlowIOException, JGitFlowGitAPIException, AlreadyInitializedException, SameBranchException
    {
       
        Git git = null;
       
        reporter.debugCommandCall(SHORT_NAME);
       
        if (null == this.context)
        {
            this.context = new InitContext();
        }

        try
        {
            git = getOrInitGit(directory);
        }
        catch (IOException e)
        {
            reporter.errorText(SHORT_NAME, e.getMessage());
            reporter.endCommand();
            throw new JGitFlowIOException(e);
        }
        catch (GitAPIException e)
        {
            reporter.errorText(SHORT_NAME, e.getMessage());
            reporter.endCommand();
            throw new JGitFlowGitAPIException(e);
        }

        Repository repo = git.getRepository();
        GitFlowConfiguration gfConfig = new GitFlowConfiguration(git);
        RevWalk walk = null;
        try
        {
            if (!force && gfConfig.gitFlowIsInitialized())
            {
                reporter.errorText(SHORT_NAME,"git flow is already initialized and force flag is false");
                reporter.endCommand();
                throw new AlreadyInitializedException("Already initialized for git flow.");
            }

            //First setup master
            if (gfConfig.hasMasterConfigured() && !force)
            {
                context.setMaster(gfConfig.getMaster());
            }
           

            //if no local master exists, but a remote does, check it out
            if (!GitHelper.localBranchExists(git, context.getMaster()) && GitHelper.remoteBranchExists(git, context.getMaster()))
            {
                reporter.debugText(SHORT_NAME,"creating new local master branch from origin master");
                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()))
            {
                reporter.errorText(SHORT_NAME,"master and develop branches configured with the same name: [" + context.getMaster() + "]");
                reporter.endCommand();
                throw new SameBranchException("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)
            {
                reporter.debugText(SHORT_NAME,"no commits found on master. creating initial commit.");
                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()))
                {
                    reporter.debugText(SHORT_NAME,"creating new local develop branch from origin develop");
                    git.branchCreate()
                       .setName(context.getDevelop())
                       .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
                       .setStartPoint("origin/" + context.getDevelop())
                       .call();
                }
                else
                {
                    reporter.debugText(SHORT_NAME,"creating new local develop branch without origin");
                    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

    }

    private Git getOrInitGit(File folder) throws IOException, GitAPIException
    {
        reporter.debugMethod(SHORT_NAME,"getOrInitGit");
        Git gitRepo;
        try
        {
            reporter.debugText(SHORT_NAME,"looking for git folder in " + folder.getAbsolutePath());
            RepositoryBuilder rb = new RepositoryBuilder()
                    .readEnvironment()
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.