Example usage for org.eclipse.jgit.lib Repository getDirectory

List of usage examples for org.eclipse.jgit.lib Repository getDirectory

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getDirectory.

Prototype


public File getDirectory() 

Source Link

Document

Get local metadata directory

Usage

From source file:fr.obeo.ariadne.ide.connector.git.internal.explorer.GitExplorer.java

License:Open Source License

/**
 * Returns the Ariadne repository that we will use to map the Git repository analyzed.
 * /* ww  w . j av a 2  s.c  o m*/
 * @param gitRepository
 *            The Git repository
 * @param monitor
 *            The progress monitor
 * @return The Ariadne repository that we will use to map the Git repository analyzed.
 */
private fr.obeo.ariadne.model.scm.Repository getOrCreateRepository(Repository gitRepository,
        IProgressMonitor monitor) {
    monitor.subTask(AriadneGitConnectorMessage.getString("GitExplorer.InitializingRepository")); //$NON-NLS-1$
    monitor.worked(1);

    fr.obeo.ariadne.model.scm.Repository ariadneRepository = null;
    String repositoryName = gitRepository.getDirectory().getParentFile().getName();

    Category category = this.ariadneProject.getCategory();
    Organization organization = category.getOrganization();

    if (organization != null) {
        List<fr.obeo.ariadne.model.scm.Repository> repositories = organization.getRepositories();
        for (fr.obeo.ariadne.model.scm.Repository aRepository : repositories) {
            if (repositoryName.equals(aRepository.getName())) {
                ariadneRepository = aRepository;

                // Clear everything
                List<Branch> branches = aRepository.getBranches();
                for (Branch branch : branches) {
                    EcoreUtil.remove(branch);
                }
                List<Commit> commits = aRepository.getCommits();
                for (Commit commit : commits) {
                    EcoreUtil.remove(commit);
                }

                List<Tag> tags = aRepository.getTags();
                for (Tag tag : tags) {
                    EcoreUtil.remove(tag);
                }
            }
        }
    }

    if (ariadneRepository == null) {
        ariadneRepository = ScmFactory.eINSTANCE.createRepository();
        ariadneRepository.setName(repositoryName);
        if (organization != null) {
            if (!this.shouldSaveInProjectResource) {
                final String fileExtension = "ariadnescm"; //$NON-NLS-1$
                URI uri = EcoreUtil.getURI(this.ariadneProject).trimFragment().trimFileExtension()
                        .appendFileExtension(fileExtension);
                Resource resource = this.resourceSet.createResource(uri);
                resource.getContents().add(ariadneRepository);
            }

            organization.getRepositories().add(ariadneRepository);
            this.ariadneProject.getRepositories().add(ariadneRepository);
        }
    }
    return ariadneRepository;
}

From source file:i5.las2peer.services.gamificationGamifierService.GamificationGamifierService.java

License:Open Source License

@POST
@Path("/repo")
@Produces(MediaType.APPLICATION_JSON)//from ww w  . j ava2  s  .  com
@ApiOperation(value = "memberLoginValidation", notes = "Simple function to validate a member login.")
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Member is registered"),
        @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized"),
        @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "User data error to be retrieved"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Cannot connect to database"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "User data error to be retrieved. Not JSON object") })
public HttpResponse updateRepository(
        @ApiParam(value = "Data in JSON", required = true) @ContentParam byte[] contentB) {
    // Request log
    L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "POST " + "gamification/gamifier/repo");
    long randomLong = new Random().nextLong(); //To be able to match
    UserAgent userAgent = (UserAgent) getContext().getMainAgent();
    // take username as default name
    String name = userAgent.getLoginName();
    System.out.println("User name : " + name);
    if (name.equals("anonymous")) {
        return unauthorizedMessage();
    }

    L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_9, "" + randomLong);

    JSONObject objResponse = new JSONObject();
    String content = new String(contentB);
    if (content.equals(null)) {
        objResponse.put("message", "Cannot update repository. Cannot parse json data into string");
        //L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        L2pLogger.logEvent(this, Event.AGENT_UPLOAD_FAILED, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    }

    //      if(!initializeDBConnection()){
    //         objResponse.put("message", "Cannot connect to database");
    //         L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
    //         return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    //      }

    JSONObject obj;
    String originRepositoryName;
    String newRepositoryName;
    String fileContent;
    String appId;
    String epURL;
    String aopScript;

    try {
        obj = (JSONObject) JSONValue.parseWithException(content);
        originRepositoryName = stringfromJSON(obj, "originRepositoryName");
        newRepositoryName = stringfromJSON(obj, "newRepositoryName");
        //fileContent = stringfromJSON(obj,"fileContent");
        appId = stringfromJSON(obj, "appId");
        epURL = stringfromJSON(obj, "epURL");
        aopScript = stringfromJSON(obj, "aopScript");
    } catch (ParseException e) {
        e.printStackTrace();
        objResponse.put("message",
                "Cannot update repository. Cannot parse json data into string. " + e.getMessage());
        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    } catch (IOException e) {
        e.printStackTrace();
        objResponse.put("message",
                "Cannot update repository. Cannot parse json data into string. " + e.getMessage());
        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    }
    // check if repo exist
    TreeWalk treeWalk = null;
    Repository newRepository = null;
    Repository originRepository = null;

    // helper variables
    // variables holding content to be modified and added to repository later
    String widget = null;
    try {
        RepositoryHelper.deleteRemoteRepository(newRepositoryName, gitHubOrganizationNewRepo, gitHubUserNewRepo,
                gitHubPasswordNewRepo);
    } catch (GitHubException e) {
        //e.printStackTrace();      
    }

    try {

        PersonIdent caeUser = new PersonIdent(gitHubUserNewRepo, gitHubUserMailNewRepo);

        originRepository = RepositoryHelper.getRemoteRepository(originRepositoryName, gitHubOrganizationOrigin);
        newRepository = RepositoryHelper.generateNewRepository(newRepositoryName, gitHubOrganizationNewRepo,
                gitHubUserNewRepo, gitHubPasswordNewRepo);
        File originDir = originRepository.getDirectory();
        // now load the TreeWalk containing the origin repository content
        treeWalk = RepositoryHelper.getRepositoryContent(originRepositoryName, gitHubOrganizationOrigin);

        //System.out.println("PATH " + treeWalk.getPathString());
        System.out.println("PATH2 " + originDir.getParent());
        System.out.println("PATH3 " + newRepository.getDirectory().getParent());
        // treeWalk.setFilter(PathFilter.create("frontend/"));
        ObjectReader reader = treeWalk.getObjectReader();
        // walk through the tree and retrieve the needed templates
        while (treeWalk.next()) {
            ObjectId objectId = treeWalk.getObjectId(0);
            ObjectLoader loader = reader.open(objectId);
            switch (treeWalk.getNameString()) {
            case "widget.xml":
                widget = new String(loader.getBytes(), "UTF-8");
                break;
            }
        }

        // replace widget.xml 
        //widget = createWidgetCode(widget, htmlElementTemplate, yjsImports, gitHubOrganization, repositoryName, frontendComponent);
        widget = RepositoryHelper.appendWidget(widget, gitHubOrganizationNewRepo, newRepositoryName);

        RepositoryHelper.copyFolder(originRepository.getDirectory().getParentFile(),
                newRepository.getDirectory().getParentFile());

        String aopfilestring = RepositoryHelper.readFile("../GamificationGamifierService/jsfiles/aop.pack.js",
                Charset.forName("UTF-8"));
        String oidcwidgetfilestring = RepositoryHelper
                .readFile("../GamificationGamifierService/jsfiles/oidc-widget.js", Charset.forName("UTF-8"));
        String gamifierstring = RepositoryHelper.readFile("../GamificationGamifierService/jsfiles/gamifier.js",
                Charset.forName("UTF-8"));

        gamifierstring = gamifierstring.replace("$Application_Id$", appId);
        gamifierstring = gamifierstring.replace("$Endpoint_URL$", epURL);
        gamifierstring = gamifierstring.replace("$AOP_Script$", aopScript);

        // add files to new repository
        newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "", "widget.xml", widget);
        newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "gamification/",
                "aop.pack.js", aopfilestring);
        newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "gamification/",
                "oidc-widget.js", oidcwidgetfilestring);
        newRepository = RepositoryHelper.createTextFileInRepository(newRepository, "gamification/",
                "gamifier.js", gamifierstring);

        // stage file
        Git.wrap(newRepository).add().addFilepattern(".").call();

        // commit files
        Git.wrap(newRepository).commit().setMessage("Generated new repo  ").setCommitter(caeUser).call();

        // push (local) repository content to GitHub repository "gh-pages" branch
        RepositoryHelper.pushToRemoteRepository(newRepository, gitHubUserNewRepo, gitHubPasswordNewRepo,
                "master", "gh-pages");

        // close all open resources
    } catch (GitHubException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        objResponse.put("message", "Cannot update repository. Github exception. " + e1.getMessage());
        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    } catch (IOException e1) {
        e1.printStackTrace();
        objResponse.put("message", "Cannot update repository. Github exception. " + e1.getMessage());
        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    } catch (Exception e) {
        objResponse.put("message", "Cannot update repository. Github exception. " + e.getMessage());
        L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message"));
        return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR);
    } finally {
        newRepository.close();
        originRepository.close();
        treeWalk.close();
    }

    objResponse.put("message", "Updated");
    L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_10, "" + randomLong);
    L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_22, "" + appId);
    L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_23, "" + name);

    return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK);

}

From source file:info.plichta.maven.plugins.changelog.RepositoryProcessor.java

License:Apache License

public List<TagWrapper> process(Repository repository) throws IOException {
    final List<TagWrapper> tags = new ArrayList<>();
    log.info("Processing git repository " + repository.getDirectory());

    final ObjectId head = repository.resolve(toRef);
    if (head == null) {
        return tags;
    }//w  w  w.j a v a 2 s  .c  o  m
    try (RevWalk walk = new RevWalk(repository)) {
        walk.sort(RevSort.TOPO);
        final Map<ObjectId, TagWrapper> tagMapping = extractTags(repository, walk);

        TagWrapper currentTag = new TagWrapper(nextRelease);
        tags.add(currentTag);

        RevCommit commit = walk.parseCommit(head);
        while (commit != null) {
            currentTag = tagMapping.getOrDefault(commit.getId(), currentTag);
            if (tagMapping.containsKey(commit.getId())) {
                tags.add(currentTag);
            }
            final CommitWrapper commitWrapper = processCommit(commit);

            if (commitFilter.test(commit) && isInPath(repository, walk, commit)) {
                currentTag.getCommits().add(commitWrapper);
            }
            final RevCommit[] parents = commit.getParents();
            if (parents != null && parents.length > 0) {
                final RevCommit parent = walk.parseCommit(parents[0]);

                try (RevWalk childWalk = new RevWalk(repository)) {
                    childWalk.markStart(childWalk.parseCommit(commit));
                    childWalk.markUninteresting(childWalk.parseCommit(parent));
                    childWalk.next();
                    for (RevCommit childCommit : childWalk) {
                        final CommitWrapper childWrapper = processCommit(childCommit);
                        if (commitFilter.test(childCommit) && isInPath(repository, walk, commit)
                                && !(deduplicateChildCommits
                                        && Objects.equals(commitWrapper.getTitle(), childWrapper.getTitle()))) {
                            commitWrapper.getChildren().add(childWrapper);
                        }
                    }

                }
                commit = parent;
            } else {
                commit = null;
            }
        }
    }

    return tags;
}

From source file:io.fabric8.collector.git.GitBuildConfigProcessor.java

License:Apache License

protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent,
        UserDetails userDetails) {//from   ww  w .j a v  a 2s.c  o  m
    try {
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();

        Git git = new Git(repository);

        File projectFolder = repository.getDirectory();

        StoredConfig config = repository.getConfig();
        String url = config.getString("remote", userDetails.getRemote(), "url");
        if (Strings.isNullOrBlank(url)) {
            LOG.warn("No remote repository url for " + branch + " defined for the git repository at "
                    + projectFolder.getCanonicalPath() + " so cannot pull");
            //return;
        }
        String mergeUrl = config.getString("branch", branch, "merge");
        if (Strings.isNullOrBlank(mergeUrl)) {
            LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at "
                    + projectFolder.getCanonicalPath() + " so not doing a pull");
            //return;
        }

        LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: "
                + url);
        PullCommand pull = git.pull();
        GitHelpers.configureCommand(pull, userDetails);
        pull.setRebase(true).call();
    } catch (Throwable e) {
        LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage()
                + ". This exception is ignored.", e);
    }
}

From source file:io.fabric8.forge.generator.pipeline.JenkinsPipelineLibrary.java

License:Apache License

protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent,
        UserDetails userDetails) {//from www.  j  ava  2s  .  com
    StopWatch watch = new StopWatch();
    try {
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();

        Git git = new Git(repository);

        File projectFolder = repository.getDirectory();

        StoredConfig config = repository.getConfig();
        String url = config.getString("remote", remote, "url");
        if (io.fabric8.utils.Strings.isNullOrBlank(url)) {
            LOG.warn("No remote repository url for " + branch + " defined for the git repository at "
                    + projectFolder.getCanonicalPath() + " so cannot pull");
            //return;
        }
        String mergeUrl = config.getString("branch", branch, "merge");
        if (io.fabric8.utils.Strings.isNullOrBlank(mergeUrl)) {
            LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at "
                    + projectFolder.getCanonicalPath() + " so not doing a pull");
            //return;
        }

        // lets trash any failed changes
        LOG.debug("Stashing local changes to the repo");
        boolean hasHead = true;
        try {
            git.log().all().call();
            hasHead = git.getRepository().getAllRefs().containsKey("HEAD");
        } catch (NoHeadException e) {
            hasHead = false;
        }
        if (hasHead) {
            // lets stash any local changes just in case..
            try {
                git.stashCreate().setPerson(personIdent).setWorkingDirectoryMessage("Stash before a write")
                        .setRef("HEAD").call();
            } catch (Throwable e) {
                LOG.error("Failed to stash changes: " + e, e);
                Throwable cause = e.getCause();
                if (cause != null && cause != e) {
                    LOG.error("Cause: " + cause, cause);
                }
            }
        }

        //LOG.debug("Resetting the repo");
        //git.reset().setMode(ResetCommand.ResetType.HARD).call();

        LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: "
                + url);
        PullCommand pull = git.pull();
        GitUtils.configureCommand(pull, userDetails);
        pull.setRebase(true).call();
    } catch (Throwable e) {
        LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage()
                + ". This exception is ignored.", e);
    } finally {
        LOG.debug("doPull took " + watch.taken());
    }
}

From source file:io.fabric8.forge.rest.CommandsResource.java

License:Apache License

protected <T> T withUIContext(final String namespace, final String projectName, String resourcePath,
        boolean write, final RestUIFunction<T> function, final GitContext gitContext) throws Exception {
    final ResourceFactory resourceFactory = getResourceFactory();
    if (Strings.isNotBlank(namespace) && Strings.isNotBlank(projectName) && resourceFactory != null) {
        RepositoriesResource repositoriesResource = new RepositoriesResource(gitUserHelper, repositoryCache,
                projectFileSystem, lockManager, kubernetes);
        repositoriesResource.setRequest(request);
        final RepositoryResource projectResource = repositoriesResource.projectRepositoryResource(namespace,
                projectName);//ww w .  j  a  va 2 s. c  om
        if (projectResource == null) {
            throw new NotFoundException("Could not find git project for namespace: " + namespace
                    + " and projectName: " + projectName);
        } else {
            GitOperation<T> operation = new GitOperation<T>() {
                @Override
                public T call(Git git, GitContext gitContext) throws Exception {
                    Repository repository = git.getRepository();
                    File gitDir = repository.getDirectory();
                    File directory = gitDir.getParentFile();
                    LOG.debug("using repository directory: " + directory.getAbsolutePath());
                    Resource<?> selection = resourceFactory.create(directory);
                    String cloneUrl = projectResource.getCloneUrl();
                    try (RestUIContext context = new RestUIContext(selection, namespace, projectName,
                            cloneUrl)) {
                        T answer = function.apply(context);
                        String commitMessage = context.getCommitMessage();
                        if (Strings.isNotBlank(commitMessage)) {
                            projectResource.setMessage(commitMessage);
                        }
                        return answer;
                    }
                }
            };
            if (write) {
                return projectResource.gitWriteOperation(operation);
            } else {
                return projectResource.gitReadOperation(operation);
            }
        }
    } else {
        try (RestUIContext context = new RestUIContext(null)) {
            return function.apply(context);
        }
    }
}

From source file:io.fabric8.forge.rest.main.ProjectFileSystem.java

License:Apache License

protected void doPull(File gitFolder, CredentialsProvider cp, String branch) {
    try {//from  ww w .  j a  v a  2  s .  co m
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables
                .findGitDir() // scan up the file system tree
                .build();

        Git git = new Git(repository);

        File projectFolder = repository.getDirectory();

        StoredConfig config = repository.getConfig();
        String url = config.getString("remote", remote, "url");
        if (Strings.isNullOrBlank(url)) {
            LOG.warn("No remote repository url for " + branch + " defined for the git repository at "
                    + projectFolder.getCanonicalPath() + " so cannot pull");
            //return;
        }
        String mergeUrl = config.getString("branch", branch, "merge");
        if (Strings.isNullOrBlank(mergeUrl)) {
            LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at "
                    + projectFolder.getCanonicalPath() + " so not doing a pull");
            //return;
        }

        // lets trash any failed changes
        LOG.info("Resetting the repo");
        git.reset().setMode(ResetCommand.ResetType.HARD).call();

        LOG.info("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: "
                + url);
        git.pull().setCredentialsProvider(cp).setRebase(true).call();
    } catch (Throwable e) {
        LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage()
                + ". This exception is ignored.", e);
    }
}

From source file:io.fabric8.maven.AbstractFabric8Mojo.java

License:Apache License

protected String getGitCommitId(String envVarName, File basedir) {
    Repository repository = getGitRepository(basedir, envVarName);
    try {/*from   w w w .  j a  va 2  s. c  o  m*/
        if (repository != null) {
            getLog().info("Looking at repo with directory " + repository.getDirectory());
            Iterable<RevCommit> logs = new Git(repository).log().call();
            for (RevCommit rev : logs) {
                return rev.getName();
            }
            warnIfInCDBuild("Cannot default " + envVarName + " no commits could be found");
        } else {
            warnIfInCDBuild("Cannot default " + envVarName + " as no git repository could be found");
        }
    } catch (Exception e) {
        warnIfInCDBuild("Failed to find git commit id. " + e, e);
    } finally {
        if (repository != null) {
            try {
                repository.close();
            } catch (Exception e) {
                // ignore
            }
        }
    }
    return null;
}

From source file:io.jenkins.blueocean.blueocean_git_pipeline.GitCacheCloneReadSaveRequest.java

License:Open Source License

@Override
byte[] read() throws IOException {
    return invokeOnScm(new GitSCMFileSystem.FSFunction<byte[]>() {
        @Override//from ww w  . j a v  a2  s.  c o m
        public byte[] invoke(Repository repository) throws IOException, InterruptedException {
            Git activeRepo = getActiveRepository(repository);
            Repository repo = activeRepo.getRepository();
            File repoDir = repo.getDirectory().getParentFile();
            try {
                File f = new File(repoDir, filePath);
                if (f.canRead()) {
                    return IOUtils.toByteArray(new FileInputStream(f));
                }
                return null;
            } finally {
                FileUtils.deleteDirectory(repoDir);
            }
        }
    });
}

From source file:io.jenkins.blueocean.blueocean_git_pipeline.GitCacheCloneReadSaveRequest.java

License:Open Source License

@Override
void save() throws IOException {
    invokeOnScm(new GitSCMFileSystem.FSFunction<Void>() {
        @Override/* w  w  w .  j  a va 2 s.  c  o  m*/
        public Void invoke(Repository repository) throws IOException, InterruptedException {
            Git activeRepo = getActiveRepository(repository);
            Repository repo = activeRepo.getRepository();
            File repoDir = repo.getDirectory().getParentFile();
            log.fine("Repo cloned to: " + repoDir.getCanonicalPath());
            try {
                File f = new File(repoDir, filePath);
                if (!f.exists() || f.canWrite()) {
                    try (Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8")) {
                        w.write(new String(contents, "utf-8"));
                    }

                    try {
                        AddCommand add = activeRepo.add();
                        add.addFilepattern(filePath);
                        add.call();

                        CommitCommand commit = activeRepo.commit();
                        commit.setMessage(commitMessage);
                        commit.call();

                        // Push the changes
                        GitUtils.push(gitSource.getRemote(), repo, getCredential(),
                                LOCAL_REF_BASE + sourceBranch, REMOTE_REF_BASE + branch);
                    } catch (GitAPIException ex) {
                        throw new ServiceException.UnexpectedErrorException(ex.getMessage(), ex);
                    }

                    return null;
                }
                throw new ServiceException.UnexpectedErrorException("Unable to write " + filePath);
            } finally {
                FileUtils.deleteDirectory(repoDir);
            }
        }
    });
}