Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) FuseSource, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package io.fabric8.openshift.agent;
 import  org.eclipse.jgit.api.CloneCommand;
 import  org.eclipse.jgit.api.Git;
 import  org.eclipse.jgit.lib.Repository;
 import  org.eclipse.jgit.lib.StoredConfig;
 import  org.eclipse.jgit.transport.CredentialsProvider;
 import  org.slf4j.Logger;
 import  org.slf4j.LoggerFactory;

A helper class for working with a git repo for a Fabric managed OpenShift cartridge
 public class CartridgeGitRepository {
     private static final transient Logger LOG = LoggerFactory.getLogger(CartridgeGitRepository.class);
     public static final String DEFAULT_GIT_PATH = . + "git" + .
             + "fabric-openshift";
     public static final String DEFAULT_LOCAL_LOCATION = System.getProperty("") + ;
     private final File localRepo;
     private String remoteName = "origin";
     private Git git;
     public CartridgeGitRepository(String containerId) {
          = new File( + . + containerId);

Clones or pulls the remote repository and returns the directory with the checkout
     public void cloneOrPull(final String repofinal CredentialsProvider credentialsthrows Exception {
         if (!.exists() && !.mkdirs()) {
             throw new IOException("Failed to create local repository");
         File gitDir = new File(".git");
         if (!gitDir.exists()) {
             .info("Cloning remote repo " + repo);
             CloneCommand command = Git.cloneRepository().setCredentialsProvider(credentials).
         } else {
             FileRepositoryBuilder builder = new FileRepositoryBuilder();
             Repository repository = builder.setGitDir(gitDir)
                     .readEnvironment() // scan environment GIT_* variables
                     .findGitDir() // scan up the file system tree
              = new Git(repository);
             // update the remote repo just in case
             StoredConfig config = repository.getConfig();
                     "+refs/heads/*:refs/remotes/" +  + "/*");
             String branch = "master";
             config.setString("branch"branch"merge""refs/heads/" + branch);
             try {
             } catch (IOException e) {
                         "Failed to save the git configuration to " +  + " with remote repo: "
                                 + repo
                                 + ". " + ee);
             // now pull
             .info("Pulling from remote repo " + repo);
    public File getLocalRepo() {
        return ;
    public Git getGit() throws IOException {
        return ;
    public String getRemoteName() {
        return ;
    public void setRemoteName(String remoteName) {
        this. = remoteName;
New to GrepCode? Check out our FAQ X