Search in sources :

Example 6 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project Corgi by kevinYin.

the class JGitTest method testClone.

@Test
public void testClone() throws IOException, GitAPIException {
    long begin = System.currentTimeMillis();
    CredentialsProvider cp = new UsernamePasswordCredentialsProvider("kevin", "111");
    Git cloneGit = Git.cloneRepository().setURI(remotePath).setCredentialsProvider(cp).setBranch("20170329_testBranch").setDirectory(new File(localPath)).call();
    long time = System.currentTimeMillis() - begin;
    System.out.println(time);
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) File(java.io.File) Test(org.junit.Test)

Example 7 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project Corgi by kevinYin.

the class JGitTest method testGetVersion.

@Test
public void testGetVersion() throws Exception {
    Repository existingRepo = new FileRepositoryBuilder().setGitDir(new File("/Users/kevin/beiliao/gitlab/platform-parent/.git")).build();
    Git git = new Git(existingRepo);
    CredentialsProvider cp = new UsernamePasswordCredentialsProvider("K-Priest", "kevin711");
    Collection<Ref> refs = git.lsRemote().setCredentialsProvider(cp).setRemote("origin").call();
    for (Ref ref : refs) {
        System.out.println(ref.getObjectId().getName());
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) File(java.io.File) Test(org.junit.Test)

Example 8 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project Corgi by kevinYin.

the class JGitTest method testRemoteInfoWithoutClone.

@Test
public void testRemoteInfoWithoutClone() throws GitAPIException {
    CredentialsProvider cp = new UsernamePasswordCredentialsProvider("K-Priest", "kevin711");
    Collection<Ref> refs = Git.lsRemoteRepository().setHeads(true).setCredentialsProvider(cp).setRemote("git@gits.ibeiliao.net:platform/platform-parent.git").setTags(true).call();
    for (Ref ref : refs) {
        System.out.println(ref.getName());
        System.out.println(ref.getObjectId().getName());
    }
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Ref(org.eclipse.jgit.lib.Ref) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) Test(org.junit.Test)

Example 9 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project archi-modelrepository-plugin by archi-contribs.

the class ArchiRepository method fetchFromRemote.

@Override
public FetchResult fetchFromRemote(String userName, String userPassword, ProgressMonitor monitor, boolean isDryrun) throws IOException, GitAPIException {
    try (Git git = Git.open(getLocalRepositoryFolder())) {
        // Check and set tracked master branch
        setTrackedMasterBranch(git);
        FetchCommand fetchCommand = git.fetch();
        fetchCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword));
        fetchCommand.setProgressMonitor(monitor);
        fetchCommand.setDryRun(isDryrun);
        return fetchCommand.call();
    }
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git) FetchCommand(org.eclipse.jgit.api.FetchCommand)

Example 10 with UsernamePasswordCredentialsProvider

use of org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider in project archi-modelrepository-plugin by archi-contribs.

the class ArchiRepository method cloneModel.

@Override
public void cloneModel(String repoURL, String userName, String userPassword, ProgressMonitor monitor) throws GitAPIException, IOException {
    CloneCommand cloneCommand = Git.cloneRepository();
    cloneCommand.setDirectory(getLocalRepositoryFolder());
    cloneCommand.setURI(repoURL);
    cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword));
    cloneCommand.setProgressMonitor(monitor);
    try (Git git = cloneCommand.call()) {
        // Use the same line endings
        setConfigLineEndings(git);
    }
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Git(org.eclipse.jgit.api.Git)

Aggregations

UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)76 Git (org.eclipse.jgit.api.Git)47 File (java.io.File)34 CredentialsProvider (org.eclipse.jgit.transport.CredentialsProvider)23 IOException (java.io.IOException)19 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 URIish (org.eclipse.jgit.transport.URIish)7