Example usage for org.eclipse.jgit.api Git Git

List of usage examples for org.eclipse.jgit.api Git Git

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git Git.

Prototype

public Git(Repository repo) 

Source Link

Document

Construct a new org.eclipse.jgit.api.Git object which can interact with the specified git repository.

Usage

From source file:com.netbeetle.reboot.git.CachedRepository.java

License:Apache License

public FetchResult fetch() throws InvalidRemoteException {
    hasFetched = true;//from   w ww .j av  a 2 s.  c o m
    return new Git(repository).fetch().setRemote("origin").setRemoveDeletedRefs(true).setTimeout(120).call();
}

From source file:com.nlbhub.nlb.vcs.GitAdapter.java

License:Open Source License

@Override
public void initRepo(String path) throws NLBVCSException {
    try {//from  w  w  w .java 2 s.  c o m
        m_localRepo = FileRepositoryBuilder.create(new File(path, ".git"));
        enableLongPaths(m_localRepo, false);
        m_localRepo.create();
        m_git = new Git(m_localRepo);
        initStatuses(false);
        // This commit solves the problem with the incorrect HEAD revision, when files
        // were added but no commits has been done yet
        commit("Initial commit");
    } catch (IOException e) {
        throw new NLBVCSException("Error while Git repository initialization", e);
    }
}

From source file:com.nlbhub.nlb.vcs.GitAdapter.java

License:Open Source License

@Override
public void openRepo(String path) throws NLBVCSException {
    try {//from  w  w w  .  j  av  a2  s .  c o m
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        m_localRepo = (builder.setWorkTree(new File(path)).readEnvironment() // scan environment GIT_* variables
                .setGitDir(new File(path, ".git")) // in fact, this can be omitted
                .build());
        enableLongPaths(m_localRepo, true);
        m_git = new Git(m_localRepo);
        initStatuses(true);
    } catch (IOException e) {
        throw new NLBVCSException("Error while Git repository opening", e);
    }
}

From source file:com.osbitools.ws.shared.prj.web.AbstractWsPrjInit.java

License:LGPL

public static Git createGitRepo(File dir) throws Exception {
    Repository repo = FileRepositoryBuilder.create(dir);
    repo.create(false);/*from w  ww . ja v  a  2  s  .co  m*/

    Git git = new Git(repo);

    // Commit first revision
    git.commit().setMessage("Repository created").call();

    return git;
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

public void commitRepository() {

    try (Git git = new Git(gitRepository)) {

        boolean propertiesUpdated = false;

        Status status = git.status().call();
        for (String filename : status.getUntracked()) {
            if (filename.equals(PROPERTIES_FILENAME)) {
                propertiesUpdated = true;
            }// w  w w.  j  a  v a2  s.  c om
        }

        for (String filename : status.getModified()) {
            if (filename.equals(PROPERTIES_FILENAME)) {
                propertiesUpdated = true;
            }
        }

        if (propertiesUpdated) {
            int result = JOptionPane.showConfirmDialog(mainFrame,
                    "Repository properties changed, add to commit?");
            if (result == JOptionPane.OK_OPTION) {
                git.add().addFilepattern(PROPERTIES_FILENAME).call();
            } else if (result == JOptionPane.CANCEL_OPTION) {
                return;
            }

        }

        String message = JOptionPane.showInputDialog("Commit message");

        RevCommit commitResult = git.commit().setMessage(message).call();
    } catch (GitAPIException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

public void pushRepository() {
    try (Git git = new Git(gitRepository)) {
        Iterable<PushResult> pushResults = git.push().call();

        for (PushResult result : pushResults) {
            System.out.println(result.getMessages());
        }//from w ww . jav a 2  s. c o m

    } catch (GitAPIException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

public void pullRepository() {
    try (Git git = new Git(gitRepository)) {
        PullResult result = git.pull().call();

        System.out.println(result.toString());

    } catch (GitAPIException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    }//www .  j a  v  a  2 s  .  c o m
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

public void updateStatus() {
    Git git = new Git(gitRepository);
    try {//from  w w w.j a  v a 2 s  .  co m
        Status status = git.status().call();
        processStatus(status);
    } catch (GitAPIException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoWorkTreeException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

public void gitAdd(PathModel pathModel) {
    Path relativePath = rootPath.relativize(pathModel.getPath());
    System.out.println(relativePath.toString());
    Git git = new Git(gitRepository);
    try {//from   ww w  . ja  v  a 2s  .  c  o  m
        git.add().addFilepattern(relativePath.toString()).call();
    } catch (GitAPIException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.passgit.app.PassGit.java

License:Open Source License

public void gitRemove(PathModel pathModel) {
    Path relativePath = rootPath.relativize(pathModel.getPath());
    System.out.println(relativePath.toString());
    Git git = new Git(gitRepository);
    try {//from w w  w.  j  av  a  2  s  . c  om
        git.rm().addFilepattern(relativePath.toString()).call();

        deleteFromPathModelTreeModel(pathModel);
    } catch (GitAPIException ex) {
        Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex);
    }
}