SORU
28 Temmuz 2011, PERŞEMBE


JGit: öğretici veya basit bir örnek bulmak

Yapamam JGit için çalışan bir öğretici bulmak.

Eğer herkes iyi bir bağlantı ya da basit bir örnek varsa çok yardımcı olur (f.ex. çalışan kedi-bir-dosya) (How to "cat" a file in JGit? cevap JGit V. 1 ile derleme değildir.0).

Ne yazık ki resmi 7* *yeni başlayanlar için benim için çok yararlı değildir. Ama çok JGit kullanan geliştiriciler olmalı sanırım?

CEVAP
25 NİSAN 2012, ÇARŞAMBA


Nitekim, API belgelenen kullanımı açısından çok az şey var.

Diğer okuyucuların iyiliği için, ben burada en yaygın işlemler için basit bir test sağlar:

  1. Depo oluşturun
  2. Bu klon
  3. Bir dosya ekleyin
  4. Commit
  5. İtin
  6. master origin/master (Bu ise çıplak bir repo klon gereklidir) parça
  7. Çek (boşuna, bu durumda, ama neyse)

Özellikle, dosyaları eklemek gerekirdesenbir yol değil. Ayrıca, izleme klon master varlığı nedeniyle .setForce(true) gerektirir.

Bu örnek, basit olması gerekiyordu olduğunu düşünün ve kendi kendine yeten lütfen.

import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.*;
import org.eclipse.jgit.api.errors.*;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.Repository;

import org.junit.Before;
import org.junit.Test;

public class TestJGit {

    private String localPath, remotePath;
    private Repository localRepo;
    private Git git;

    @Before
    public void init() throws IOException {
        localPath = "/home/me/repos/mytest";
        remotePath = "git@github.com:me/mytestrepo.git";
        localRepo = new FileRepository(localPath   "/.git");
        git = new Git(localRepo);
    }

    @Test
    public void testCreate() throws IOException {
        Repository newRepo = new FileRepository(localPath   ".git");
        newRepo.create();
    }

    @Test
    public void testClone() throws IOException, GitAPIException {
        Git.cloneRepository().setURI(remotePath)
                .setDirectory(new File(localPath)).call();
    }

    @Test
    public void testAdd() throws IOException, GitAPIException {
        File myfile = new File(localPath   "/myfile");
        myfile.createNewFile();
        git.add().addFilepattern("myfile").call();
    }

    @Test
    public void testCommit() throws IOException, GitAPIException,
            JGitInternalException {
        git.commit().setMessage("Added myfile").call();
    }

    @Test
    public void testPush() throws IOException, JGitInternalException,
            GitAPIException {
        git.push().call();
    }

    @Test
    public void testTrackMaster() throws IOException, JGitInternalException,
            GitAPIException {
        git.branchCreate().setName("master")
                .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
                .setStartPoint("origin/master").setForce(true).call();
    }

    @Test
    public void testPull() throws IOException, GitAPIException {
        git.pull().call();
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ASUS North America

    ASUS North A

    12 AĞUSTOS 2008
  • Gee Cee

    Gee Cee

    1 AĞUSTOS 2009
  • TurkishRoyal

    TurkishRoyal

    16 Ocak 2007