org.eclipse.jgit.api.CloneCommand Java Examples

The following examples show how to use org.eclipse.jgit.api.CloneCommand. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UIGit.java    From hop with Apache License 2.0 6 votes vote down vote up
public boolean cloneRepo( String directory, String uri ) {
  CloneCommand cmd = Git.cloneRepository();
  cmd.setDirectory( new File( directory ) );
  cmd.setURI( uri );
  cmd.setCredentialsProvider( credentialsProvider );
  try {
    Git git = cmd.call();
    git.close();
    return true;
  } catch ( Exception e ) {
    if ( ( e instanceof TransportException )
        && ( ( e.getMessage().contains( "Authentication is required but no CredentialsProvider has been registered" )
          || e.getMessage().contains( "not authorized" ) ) ) ) {
      if ( promptUsernamePassword() ) {
        return cloneRepo( directory, uri );
      }
    } else {
      showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
    }
  }
  return false;
}
 
Example #2
Source File: GitProctorCore.java    From proctor with Apache License 2.0 6 votes vote down vote up
private Git cloneRepository(final File workingDir) throws GitAPIException {
    final CloneCommand cloneCommand = Git.cloneRepository()
            .setURI(gitUrl)
            .setDirectory(workingDir)
            .setProgressMonitor(PROGRESS_MONITOR)
            .setCredentialsProvider(user)
            .setTimeout(cloneTimeoutSeconds);

    if (StringUtils.isNotEmpty(branchName)) {
        final String refBranchName = "refs/heads/" + branchName;
        cloneCommand.setBranchesToClone(ImmutableSet.of(refBranchName))
                .setBranch(refBranchName); // prevent clone command from looking at the HEAD of the master branch
    }

    return cloneCommand.call();
}
 
Example #3
Source File: GitRepository.java    From CardinalPGM with MIT License 6 votes vote down vote up
@Override
public void refreshRepo() throws RotationLoadException, IOException {
    try {
        if (git == null) {
            if (new File(getPath() + File.separator + ".git").exists())
                this.git = Git.open(new File(getPath()));
            else
                this.git = ((CloneCommand) addCredentials(
                        Git.cloneRepository().setURI(gitUrl.toString()).setDirectory(new File(getPath())))).call();
        }
        git.clean().call();
        addCredentials(git.fetch()).call();
        git.reset().setRef("@{upstream}").setMode(ResetCommand.ResetType.HARD).call();
    } catch (GitAPIException e) {
        e.printStackTrace();
        throw new RotationLoadException("Could not load git repository: " + gitUrl);
    }
    super.refreshRepo();
}
 
Example #4
Source File: GitContentRepositoryHelper.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
private void configureTransportAuthenticaion(final CloneCommand cloneCommand, final String remotePassword,
                                             final String remoteUsername, final String remoteUrl) {
    // Check if this remote git repository has username/password provided
    if (!StringUtils.isEmpty(remoteUsername)) {
        if (StringUtils.isEmpty(remotePassword)) {
            // Username was provided but password is empty
            logger.debug("Password field is empty while cloning from remote repository: " + remoteUrl);
        }
        // Studio should only support usr/pwd ssh repo.
        // until we add per user + per server private key configuration.
        if (remoteUrl.toLowerCase().contains("ssh://")) {
            new SshUsernamePasswordAuthConfigurator(remotePassword).configureAuthentication(cloneCommand);
        } else {
            new BasicUsernamePasswordAuthConfigurator(remoteUsername, remotePassword)
                    .configureAuthentication(cloneCommand);
        }
    }
}
 
Example #5
Source File: JGitWrapper.java    From mOrgAnd with GNU General Public License v2.0 6 votes vote down vote up
private void createNewRepo(ProgressMonitor monitor) throws GitAPIException, IllegalArgumentException {
    File localRepo = new File(localPath);
    if (localRepo.exists()) // Safety check so we don't accidentally delete directory
        throw new IllegalStateException("Directory already exists");

    try {
        CloneCommand cloneCommand = Git.cloneRepository()
                .setCredentialsProvider(credentialsProvider)
                .setURI(remotePath)
                .setBranch(branch)
                .setDirectory(localRepo)
                .setBare(false);
        if (monitor != null)
            cloneCommand.setProgressMonitor(monitor);
        cloneCommand.call();
    } catch (GitAPIException e) {
        FileUtils.deleteDirectory(localRepo);
        throw e;
    }
}
 
Example #6
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSetRemoveBranchesFlagToFetchCommand() throws Exception {
	Git mockGit = mock(Git.class);
	FetchCommand fetchCommand = mock(FetchCommand.class);

	when(mockGit.fetch()).thenReturn(fetchCommand);
	when(fetchCommand.call()).thenReturn(mock(FetchResult.class));

	JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
			this.environment, new JGitEnvironmentProperties());
	envRepository
			.setGitFactory(new MockGitFactory(mockGit, mock(CloneCommand.class)));
	envRepository.setUri("http://somegitserver/somegitrepo");
	envRepository.setDeleteUntrackedBranches(true);

	envRepository.fetch(mockGit, "master");

	verify(fetchCommand, times(1)).setRemoveDeletedRefs(true);
	verify(fetchCommand, times(1)).call();
}
 
Example #7
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSetTransportConfigCallbackOnCloneAndFetch() throws Exception {
	Git mockGit = mock(Git.class);
	FetchCommand fetchCommand = mock(FetchCommand.class);
	when(mockGit.fetch()).thenReturn(fetchCommand);
	when(fetchCommand.call()).thenReturn(mock(FetchResult.class));

	CloneCommand mockCloneCommand = mock(CloneCommand.class);
	when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
	when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);

	TransportConfigCallback configCallback = mock(TransportConfigCallback.class);
	JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
			this.environment, new JGitEnvironmentProperties());
	envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
	envRepository.setUri("http://somegitserver/somegitrepo");
	envRepository.setTransportConfigCallback(configCallback);
	envRepository.setCloneOnStart(true);

	envRepository.afterPropertiesSet();
	verify(mockCloneCommand, times(1)).setTransportConfigCallback(configCallback);

	envRepository.fetch(mockGit, "master");
	verify(fetchCommand, times(1)).setTransportConfigCallback(configCallback);
}
 
Example #8
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDeleteBaseDirWhenCloneFails() throws Exception {
	Git mockGit = mock(Git.class);
	CloneCommand mockCloneCommand = mock(CloneCommand.class);

	when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
	when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
	when(mockCloneCommand.call())
			.thenThrow(new TransportException("failed to clone"));

	JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
			this.environment, new JGitEnvironmentProperties());
	envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
	envRepository.setUri("http://somegitserver/somegitrepo");
	envRepository.setBasedir(this.basedir);

	try {
		envRepository.findOne("bar", "staging", "master");
	}
	catch (Exception ex) {
		// expected - ignore
	}

	assertThat(this.basedir.listFiles().length > 0)
			.as("baseDir should be deleted when clone fails").isFalse();
}
 
Example #9
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void afterPropertiesSet_CloneOnStartTrueWithFileURL_CloneAndFetchNotCalled()
		throws Exception {
	Git mockGit = mock(Git.class);
	CloneCommand mockCloneCommand = mock(CloneCommand.class);

	when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
	when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);

	JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
			this.environment, new JGitEnvironmentProperties());
	envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
	envRepository.setUri("file://somefilesystem/somegitrepo");
	envRepository.setCloneOnStart(true);
	envRepository.afterPropertiesSet();
	verify(mockCloneCommand, times(0)).call();
	verify(mockGit, times(0)).fetch();
}
 
Example #10
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void afterPropertiesSet_CloneOnStartFalse_CloneAndFetchNotCalled()
		throws Exception {
	Git mockGit = mock(Git.class);
	CloneCommand mockCloneCommand = mock(CloneCommand.class);

	when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
	when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);

	JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
			this.environment, new JGitEnvironmentProperties());
	envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
	envRepository.setUri("http://somegitserver/somegitrepo");
	envRepository.afterPropertiesSet();
	verify(mockCloneCommand, times(0)).call();
	verify(mockGit, times(0)).fetch();
}
 
Example #11
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void afterPropertiesSet_CloneOnStartTrue_CloneAndFetchCalled()
		throws Exception {
	Git mockGit = mock(Git.class);
	CloneCommand mockCloneCommand = mock(CloneCommand.class);

	when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
	when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);

	JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(
			this.environment, new JGitEnvironmentProperties());
	envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
	envRepository.setUri("http://somegitserver/somegitrepo");
	envRepository.setCloneOnStart(true);
	envRepository.afterPropertiesSet();
	verify(mockCloneCommand, times(1)).call();
}
 
Example #12
Source File: CloneRepositoryAdapter.java    From coderadar with MIT License 6 votes vote down vote up
@Override
public void cloneRepository(CloneRepositoryCommand cloneRepositoryCommand)
    throws UnableToCloneRepositoryException {
  try {
    // TODO: support progress monitoring
    CloneCommand cloneCommand =
        Git.cloneRepository()
            .setURI(cloneRepositoryCommand.getRemoteUrl())
            .setDirectory(new File(cloneRepositoryCommand.getLocalDir()))
            .setBare(true);
    if (cloneRepositoryCommand.getUsername() != null
        && cloneRepositoryCommand.getPassword() != null) {
      cloneCommand.setCredentialsProvider(
          new UsernamePasswordCredentialsProvider(
              cloneRepositoryCommand.getUsername(), cloneRepositoryCommand.getPassword()));
    }
    cloneCommand.call().close();
  } catch (GitAPIException e) {
    throw new UnableToCloneRepositoryException(e.getMessage());
  }
}
 
Example #13
Source File: GitHubConnector.java    From tool.accelerate.core with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a repository on GitHub and in a local temporary directory. This is a one time operation as
 * once it is created on GitHub and locally it cannot be recreated.
 */
public File createGitRepository(String repositoryName) throws IOException {
    RepositoryService service = new RepositoryService();
    service.getClient().setOAuth2Token(oAuthToken);
    Repository repository = new Repository();
    repository.setName(repositoryName);
    repository = service.createRepository(repository);
    repositoryLocation = repository.getHtmlUrl();

    CloneCommand cloneCommand = Git.cloneRepository()
            .setURI(repository.getCloneUrl())
            .setDirectory(localGitDirectory);
    addAuth(cloneCommand);
    try {
        localRepository = cloneCommand.call();
    } catch (GitAPIException e) {
        throw new IOException("Error cloning to local file system", e);
    }
    return localGitDirectory;
}
 
Example #14
Source File: GitRepo.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
private Git cloneToBasedir(URI projectUrl, File destinationFolder) {
	String url = projectUrl.toString();
	String projectGitUrl = url.endsWith(".git") ? url : url + ".git";
	if (log.isDebugEnabled()) {
		log.debug("Project git url [" + projectGitUrl + "]");
	}
	CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository()
			.setURI(projectGitUrl).setDirectory(destinationFolder);
	try {
		Git git = command.call();
		if (git.getRepository().getRemoteNames().isEmpty()) {
			log.info("No remote added. Will add remote of the cloned project");
			git.remoteSetUrl().setUri(new URIish(projectGitUrl));
			git.remoteSetUrl().setName("origin");
			git.remoteSetUrl().setPush(true);
		}
		return git;
	}
	catch (GitAPIException | URISyntaxException e) {
		deleteBaseDirIfExists();
		throw new IllegalStateException(e);
	}
}
 
Example #15
Source File: ProjectFileSystem.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey, String remote, String tag) {
    StopWatch watch = new StopWatch();

    // clone the repo!
    boolean cloneAll = true;
    LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath() + " cloneAllBranches: " + cloneAll);
    CloneCommand command = Git.cloneRepository();
    GitUtils.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey);
    command = command.setCredentialsProvider(credentialsProvider).
            setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote);

    try {
        Git git = command.call();
        if (tag != null){
            git.checkout().setName(tag).call();
        }
    } catch (Throwable e) {
        LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e);
        throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage());
    } finally {
        LOG.info("cloneRepo took " + watch.taken());
    }
}
 
Example #16
Source File: ForgeClientAsserts.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that we can git clone the given repository
 */
public static Git assertGitCloneRepo(String cloneUrl, File outputFolder) throws GitAPIException, IOException {
    LOG.info("Cloning git repo: " + cloneUrl + " to folder: " + outputFolder);

    Files.recursiveDelete(outputFolder);
    outputFolder.mkdirs();

    CloneCommand command = Git.cloneRepository();
    command = command.setCloneAllBranches(false).setURI(cloneUrl).setDirectory(outputFolder).setRemote("origin");

    Git git;
    try {
        git = command.call();
    } catch (Exception e) {
        LOG.error("Failed to git clone remote repo " + cloneUrl + " due: " + e.getMessage(), e);
        throw e;
    }
    return git;
}
 
Example #17
Source File: CloneTask.java    From ant-git-tasks with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() {
        try {
                CloneCommand cloneCommand = new CloneCommand();

                if (branchToTrack != null) {
                        cloneCommand.setBranch(branchToTrack);
                }

                if (!branchNames.isEmpty()) {
                        cloneCommand.setBranchesToClone(branchNames);
                }

                cloneCommand.setURI(getUri()).
                        setBare(bare).
                        setCloneAllBranches(cloneAllBranches).
                        setCloneSubmodules(cloneSubModules).
                        setNoCheckout(noCheckout).
                        setDirectory(getDirectory());

                setupCredentials(cloneCommand);

                if (getProgressMonitor() != null) {
                        cloneCommand.setProgressMonitor(getProgressMonitor());
                }

                cloneCommand.call();
        }
        catch (Exception e) {
                throw new GitBuildException(String.format(MESSAGE_CLONE_FAILED, getUri()), e);
        }
}
 
Example #18
Source File: ProjectWebsiteTest.java    From jbake with MIT License 5 votes vote down vote up
private void cloneJbakeWebsite() throws GitAPIException {
    CloneCommand cmd = Git.cloneRepository();
    cmd.setBare(false);
    cmd.setBranch("master");
    cmd.setRemote("origin");
    cmd.setURI(WEBSITE_REPO_URL);
    cmd.setDirectory(projectFolder);

    cmd.call();

    assertThat(new File(projectFolder,"README.md").exists()).isTrue();
}
 
Example #19
Source File: GitServiceImpl.java    From molicode with Apache License 2.0 5 votes vote down vote up
private void pullGitRepoInLock(GitRepoVo gitRepoVo, CommonResult<String> result) throws IOException, GitAPIException {
    String filePath = SystemFileUtils.buildGitRepoDir(gitRepoVo.getGitUrl(), gitRepoVo.getBranchName());
    File repoDir = new File(filePath);

    CostWatch costWatch = CostWatch.createStarted();
    Git git = null;
    CredentialsProvider credentialsProvider = buildCredentialsProvider(gitRepoVo);
    if (repoDir.exists() && isGitDirectory(repoDir)) {
        git = Git.open(repoDir);
        LogHelper.DEFAULT.info("git repo already exist, fetch from url={}, branch={}", gitRepoVo.getGitUrl(), gitRepoVo.getBranchName());
        PullCommand pull = git.pull();
        if (credentialsProvider != null) {
            pull.setCredentialsProvider(credentialsProvider);
        }
        pull.setRemoteBranchName(gitRepoVo.getBranchName()).call();
        result.addDefaultModel("info", "仓库已存在,拉取最新内容到分支:" + gitRepoVo.getBranchName());
    } else {
        FileIoUtil.makeDir(repoDir);
        CloneCommand cloneCommand = Git.cloneRepository().setURI(gitRepoVo.getGitUrl()).setDirectory(repoDir).setBranch(gitRepoVo.getBranchName());
        if (credentialsProvider != null) {
            cloneCommand.setCredentialsProvider(credentialsProvider);
        }
        git = cloneCommand
                .call();
        LogHelper.DEFAULT.info("Cloning from " + gitRepoVo.getGitUrl() + " to " + git.getRepository());
        result.addDefaultModel("info", "仓库在本地还未存在,拉取最新内容到分支:" + gitRepoVo.getBranchName());
    }
    costWatch.stop();
    LogHelper.DEFAULT.info("拉取仓库模板,gitUrl={}, 耗时={}ms ", gitRepoVo.getGitUrl(), costWatch.getCost(TimeUnit.MILLISECONDS));
    result.addModel(MoliCodeConstant.ResultInfo.COST_TIME_KEY, costWatch.getCost(TimeUnit.SECONDS));
    result.succeed();
}
 
Example #20
Source File: ExtensionPointAction.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
private void doClone() throws GitAPIException, IOException {
    CloneCommand cloneCommand = Git.cloneRepository();

    cloneCommand.setURI(REPOSITORY_URL);

    File repositoryDir = new File(directory, name);
    cloneCommand.setDirectory(repositoryDir);
    cloneCommand.setProgressMonitor(new TextProgressMonitor());

    cloneCommand.call();
    System.out.println("Project directory for project created at " + repositoryDir);

    FileUtils.deleteDirectory(new File(repositoryDir, ".git"));
}
 
Example #21
Source File: RepositorioCartasServico.java    From portal-de-servicos with MIT License 5 votes vote down vote up
private File clonarRepositorio(File caminhoLocal) throws GitAPIException {
    log.debug("Clonando repositório de cartas de serviço de {} para {}", urlRepositorio, caminhoLocal);
    CloneCommand clone = Git.cloneRepository()
            .setURI(urlRepositorio)
            .setProgressMonitor(new LogstashProgressMonitor(log))
            .setDirectory(caminhoLocal);

    try (Git repositorio = clone.call()) {
        String head = repositorio.log().call().iterator().next().getName();
        log.info("Repositório de cartas de serviço clonado na versão {}", head);
        return repositorio.getRepository().getWorkTree();
    }
}
 
Example #22
Source File: GitWrapper.java    From Stringlate with MIT License 5 votes vote down vote up
public static boolean cloneRepo(final String uri, final File cloneTo,
                                final String branch,
                                final GitCloneProgressCallback callback) {
    Git result = null;

    try {
        final CloneCommand clone = Git.cloneRepository()
                .setURI(uri).setDirectory(cloneTo)
                .setBare(false).setRemote(REMOTE_NAME).setNoCheckout(false)
                .setCloneAllBranches(false).setCloneSubmodules(false)
                .setProgressMonitor(callback);

        if (!branch.isEmpty()) {
            if (branch.contains("/")) {
                clone.setBranch(branch.substring(branch.lastIndexOf('/') + 1));
            } else {
                clone.setBranch(branch);
            }
        }

        result = clone.call();
        return true;
    } catch (GitAPIException e) {
        e.printStackTrace();
    } finally {
        if (result != null) {
            result.close();
        }
    }
    return false;
}
 
Example #23
Source File: JGitEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
private Git cloneToBasedir() throws GitAPIException {
	CloneCommand clone = this.gitFactory.getCloneCommandByCloneRepository()
			.setURI(getUri()).setDirectory(getBasedir());
	configureCommand(clone);
	try {
		return clone.call();
	}
	catch (GitAPIException e) {
		this.logger.warn("Error occured cloning to base directory.", e);
		deleteBaseDirIfExists();
		throw e;
	}
}
 
Example #24
Source File: GitRepo.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private Git cloneToBasedir(URIish projectUrl, File destinationFolder)
		throws GitAPIException {
	CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository()
			.setURI(projectUrl.toString() + ".git")
			.setDirectory(humanishDestination(projectUrl, destinationFolder));
	try {
		return command.call();
	}
	catch (GitAPIException e) {
		deleteBaseDirIfExists();
		throw e;
	}
}
 
Example #25
Source File: Config.java    From github-bucket with ISC License 4 votes vote down vote up
default CloneCommand configure(CloneCommand cmd) {
    return cmd;
}
 
Example #26
Source File: MaestroAgent.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(final AgentSourceRequest note) {
    logger.info("Source request arrived");

    final String sourceUrl = note.getSourceUrl();
    final String branch = note.getBranch();

    if (branch == null) {
        logger.info("Preparing to download code from {}", sourceUrl);
    }
    else {
        logger.info("Preparing to download code from {} from branch {}", sourceUrl, branch);
    }
    final String projectDir = UUID.randomUUID().toString();

    final File repositoryDir = new File(sourceRoot + File.separator + projectDir + File.separator);

    if (!repositoryDir.exists()) {
        if (!repositoryDir.mkdirs()) {
            logger.warn("Unable to create directory: {}", repositoryDir);
        }
    }

    CloneCommand cloneCommand = Git.cloneRepository();

    cloneCommand.setURI(sourceUrl);
    cloneCommand.setDirectory(repositoryDir);
    cloneCommand.setProgressMonitor(NullProgressMonitor.INSTANCE);


    if (branch != null) {
        cloneCommand.setBranch(branch);
    }

    try {
        cloneCommand.call();
        logger.info("Source directory for project created at {}", repositoryDir);
        extensionPoints.add(new ExtensionPoint(new File(repositoryDir, "requests"), true));

        getClient().replyOk(note);
    } catch (GitAPIException e) {
        logger.error("Unable to clone repository: {}", e.getMessage(), e);
        getClient().replyInternalError(note,"Unable to clone repository: %s", e.getMessage());
    }
}
 
Example #27
Source File: Clone.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(Wandora wandora, Context context) {
    if(cloneUI == null) {
        cloneUI = new CloneUI();
    }
    
    cloneUI.setUsername(getUsername());
    cloneUI.setPassword(getPassword());
    cloneUI.openInDialog();
    
    if(cloneUI.wasAccepted()) {
        setDefaultLogger();
        setLogTitle("Git clone");
        
        String cloneUrl = cloneUI.getCloneUrl();
        String destinationDirectory = cloneUI.getDestinationDirectory();
        String username = cloneUI.getUsername();
        String password = cloneUI.getPassword();
        
        setUsername(username);
        setPassword(password);

        log("Cloning git repository from "+cloneUrl);
        
        try {
            CloneCommand clone = Git.cloneRepository();
            clone.setURI(cloneUrl);
            clone.setDirectory(new File(destinationDirectory));
            
            if(isNotEmpty(username)) {
                CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( username, password );
                clone.setCredentialsProvider(credentialsProvider);
            }
            
            clone.call();
            
            if(cloneUI.getOpenProject()) {
                log("Opening project.");
                LoadWandoraProject loadProject = new LoadWandoraProject(destinationDirectory);
                loadProject.setToolLogger(this);
                loadProject.execute(wandora, context);
            }
            log("Ready.");
        } 
        catch (GitAPIException ex) {
            log(ex.toString());
        }
        catch (Exception e) {
            log(e);
        }
        setState(WAIT);
    }
}
 
Example #28
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
@Override
public CloneCommand getCloneCommandByCloneRepository() {
	return this.mockCloneCommand;
}
 
Example #29
Source File: JGitEnvironmentRepositoryTests.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
MockGitFactory(Git mockGit, CloneCommand mockCloneCommand) {
	this.mockGit = mockGit;
	this.mockCloneCommand = mockCloneCommand;
}
 
Example #30
Source File: GitRepo.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
CloneCommand getCloneCommandByCloneRepository() {
	return Git.cloneRepository().setCredentialsProvider(this.provider)
			.setTransportConfigCallback(this.callback);
}