Search in sources :

Example 56 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project egit by eclipse.

the class PushTest method setup.

@Before
public void setup() throws Exception {
    TestUtil.disableProxy();
    remoteRepository = new SampleTestRepository(NUMBER_RANDOM_COMMITS, true);
    localRepoPath = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile(), "test" + System.nanoTime());
    String branch = Constants.R_HEADS + SampleTestRepository.FIX;
    CloneOperation cloneOperation = new CloneOperation(new URIish(remoteRepository.getUri()), true, null, localRepoPath, branch, "origin", 30);
    cloneOperation.setCredentialsProvider(new UsernamePasswordCredentialsProvider("agitter", "letmein"));
    cloneOperation.run(new NullProgressMonitor());
    file = new File(localRepoPath, SampleTestRepository.A_txt_name);
    assertTrue(file.exists());
    localRepository = Activator.getDefault().getRepositoryCache().lookupRepository(new File(localRepoPath, ".git"));
    assertNotNull(localRepository);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) SampleTestRepository(org.eclipse.egit.ui.wizards.clone.SampleTestRepository) File(java.io.File) CloneOperation(org.eclipse.egit.core.op.CloneOperation) Before(org.junit.Before)

Example 57 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project ArTEMiS by ls1intum.

the class GitService method pull.

/**
 * Pulls from remote repository.
 *
 * @param repo Local Repository Object.
 * @return The PullResult which contains FetchResult and MergeResult.
 * @throws GitAPIException
 */
public PullResult pull(Repository repo) throws GitAPIException {
    Git git = new Git(repo);
    // flush cache of files
    repo.setFiles(null);
    return git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).call();
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git)

Example 58 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project zeppelin by apache.

the class GitHubNotebookRepo method pushToRemoteSteam.

private void pushToRemoteSteam() {
    try {
        LOG.debug("Pushing latest changes to remote stream");
        PushCommand pushCommand = git.push();
        pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken()));
        pushCommand.call();
    } catch (GitAPIException e) {
        LOG.error("Error when pushing latest changes to remote repository", e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) PushCommand(org.eclipse.jgit.api.PushCommand)

Example 59 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project zeppelin by apache.

the class GitHubNotebookRepo method pullFromRemoteStream.

private void pullFromRemoteStream() {
    try {
        LOG.debug("Pulling latest changes from remote stream");
        PullCommand pullCommand = git.pull();
        pullCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(zeppelinConfiguration.getZeppelinNotebookGitUsername(), zeppelinConfiguration.getZeppelinNotebookGitAccessToken()));
        pullCommand.call();
    } catch (GitAPIException e) {
        LOG.error("Error when pulling latest changes from remote repository", e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PullCommand(org.eclipse.jgit.api.PullCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)

Example 60 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project zaproxy by zaproxy.

the class CreateTagAndGitHubRelease method createTag.

private void createTag() throws Exception {
    Repository repository = new FileRepositoryBuilder().setGitDir(new File(getProject().getRootDir(), ".git")).build();
    try (Git git = new Git(repository)) {
        URIish originUri = new URIish(GITHUB_BASE_URL + getRepo().get());
        git.remoteSetUrl().setRemoteName(GIT_REMOTE_ORIGIN).setRemoteUri(originUri).call();
        GitHubUser ghUser = getUser().get();
        PersonIdent personIdent = new PersonIdent(ghUser.getName(), ghUser.getEmail());
        Ref tag = git.tag().setName(getTag().get()).setMessage(getTagMessage().get()).setAnnotated(true).setTagger(personIdent).call();
        git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(ghUser.getName(), ghUser.getAuthToken())).add(tag).call();
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) GitHubUser(org.zaproxy.zap.GitHubUser) PersonIdent(org.eclipse.jgit.lib.PersonIdent) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) File(java.io.File)

Aggregations

UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)75 Git (org.eclipse.jgit.api.Git)47 File (java.io.File)33 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)23 IOException (java.io.IOException)18 Test (org.junit.Test)18 CloneCommand (org.eclipse.jgit.api.CloneCommand)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)15 RepositoryModel (com.gitblit.models.RepositoryModel)12 PushResult (org.eclipse.jgit.transport.PushResult)12 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)9 FileOutputStream (java.io.FileOutputStream)8 PushCommand (org.eclipse.jgit.api.PushCommand)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 BufferedWriter (java.io.BufferedWriter)7 OutputStreamWriter (java.io.OutputStreamWriter)7 Date (java.util.Date)7 Ref (org.eclipse.jgit.lib.Ref)7 Repository (org.eclipse.jgit.lib.Repository)7 RefSpec (org.eclipse.jgit.transport.RefSpec)7