use of org.eclipse.jgit.api.FetchCommand in project archi-modelrepository-plugin by archi-contribs.
the class ArchiRepository method fetchFromRemote.
@Override
public FetchResult fetchFromRemote(UsernamePassword npw, ProgressMonitor monitor, boolean isDryrun) throws IOException, GitAPIException {
try (Git git = Git.open(getLocalRepositoryFolder())) {
// Check and set tracked master branch
setTrackedBranch(git.getRepository(), IGraficoConstants.MASTER);
FetchCommand fetchCommand = git.fetch();
fetchCommand.setTransportConfigCallback(CredentialsAuthenticator.getTransportConfigCallback(getOnlineRepositoryURL(), npw));
fetchCommand.setProgressMonitor(monitor);
fetchCommand.setDryRun(isDryrun);
return fetchCommand.call();
}
}
use of org.eclipse.jgit.api.FetchCommand in project egit by eclipse.
the class FetchOperation method run.
/**
* @param monitor
* @throws InvocationTargetException
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException {
if (operationResult != null)
throw new IllegalStateException(CoreText.OperationAlreadyExecuted);
EclipseGitProgressTransformer gitMonitor = new EclipseGitProgressTransformer(monitor);
try (Git git = new Git(repository)) {
FetchCommand command;
if (rc == null)
command = git.fetch().setRemote(uri.toPrivateString()).setRefSpecs(specs);
else
command = git.fetch().setRemote(rc.getName());
command.setCredentialsProvider(credentialsProvider).setTimeout(timeout).setDryRun(dryRun).setProgressMonitor(gitMonitor);
if (tagOpt != null)
command.setTagOpt(tagOpt);
try {
operationResult = command.call();
} catch (JGitInternalException e) {
throw new InvocationTargetException(e.getCause() != null ? e.getCause() : e);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
}
use of org.eclipse.jgit.api.FetchCommand in project gitblit by gitblit.
the class GitblitManager method fork.
/*
* IGITBLIT
*/
/**
* Creates a personal fork of the specified repository. The clone is view
* restricted by default and the owner of the source repository is given
* access to the clone.
*
* @param repository
* @param user
* @return the repository model of the fork, if successful
* @throws GitBlitException
*/
@Override
public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException {
String cloneName = MessageFormat.format("{0}/{1}.git", user.getPersonalPath(), StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
String fromUrl = MessageFormat.format("file://{0}/{1}", repositoryManager.getRepositoriesFolder().getAbsolutePath(), repository.name);
// clone the repository
try {
Repository canonical = getRepository(repository.name);
File folder = new File(repositoryManager.getRepositoriesFolder(), cloneName);
CloneCommand clone = new CloneCommand();
clone.setBare(true);
// fetch branches with exclusions
Collection<Ref> branches = canonical.getRefDatabase().getRefs(Constants.R_HEADS).values();
List<String> branchesToClone = new ArrayList<String>();
for (Ref branch : branches) {
String name = branch.getName();
if (name.startsWith(Constants.R_TICKET)) {
// exclude ticket branches
continue;
}
branchesToClone.add(name);
}
clone.setBranchesToClone(branchesToClone);
clone.setURI(fromUrl);
clone.setDirectory(folder);
Git git = clone.call();
// fetch tags
FetchCommand fetch = git.fetch();
fetch.setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*"));
fetch.call();
git.getRepository().close();
} catch (Exception e) {
throw new GitBlitException(e);
}
// create a Gitblit repository model for the clone
RepositoryModel cloneModel = repository.cloneAs(cloneName);
// owner has REWIND/RW+ permissions
cloneModel.addOwner(user.username);
// is not lower than the source repository (issue-495/ticket-167)
if (repository.accessRestriction.exceeds(cloneModel.accessRestriction)) {
cloneModel.accessRestriction = repository.accessRestriction;
}
repositoryManager.updateRepositoryModel(cloneName, cloneModel, false);
// add the owner of the source repository to the clone's access list
if (!ArrayUtils.isEmpty(repository.owners)) {
for (String owner : repository.owners) {
UserModel originOwner = userManager.getUserModel(owner);
if (originOwner != null && !originOwner.canClone(cloneModel)) {
// origin owner can't yet clone fork, grant explicit clone access
originOwner.setRepositoryPermission(cloneName, AccessPermission.CLONE);
reviseUser(originOwner.username, originOwner);
}
}
}
// grant origin's user list clone permission to fork
List<String> users = repositoryManager.getRepositoryUsers(repository);
List<UserModel> cloneUsers = new ArrayList<UserModel>();
for (String name : users) {
if (!name.equalsIgnoreCase(user.username)) {
UserModel cloneUser = userManager.getUserModel(name);
if (cloneUser.canClone(repository) && !cloneUser.canClone(cloneModel)) {
// origin user can't yet clone fork, grant explicit clone access
cloneUser.setRepositoryPermission(cloneName, AccessPermission.CLONE);
}
cloneUsers.add(cloneUser);
}
}
userManager.updateUserModels(cloneUsers);
// grant origin's team list clone permission to fork
List<String> teams = repositoryManager.getRepositoryTeams(repository);
List<TeamModel> cloneTeams = new ArrayList<TeamModel>();
for (String name : teams) {
TeamModel cloneTeam = userManager.getTeamModel(name);
if (cloneTeam.canClone(repository) && !cloneTeam.canClone(cloneModel)) {
// origin team can't yet clone fork, grant explicit clone access
cloneTeam.setRepositoryPermission(cloneName, AccessPermission.CLONE);
}
cloneTeams.add(cloneTeam);
}
userManager.updateTeamModels(cloneTeams);
// add this clone to the cached model
repositoryManager.addToCachedRepositoryList(cloneModel);
if (pluginManager != null) {
for (RepositoryLifeCycleListener listener : pluginManager.getExtensions(RepositoryLifeCycleListener.class)) {
try {
listener.onFork(repository, cloneModel);
} catch (Throwable t) {
logger.error(String.format("failed to call plugin onFork %s", repository.name), t);
}
}
}
return cloneModel;
}
use of org.eclipse.jgit.api.FetchCommand in project gitblit by gitblit.
the class JGitUtils method fetchRepository.
/**
* Fetch updates from the remote repository. If refSpecs is unspecifed,
* remote heads, tags, and notes are retrieved.
*
* @param credentialsProvider
* @param repository
* @param refSpecs
* @return FetchResult
* @throws Exception
*/
public static FetchResult fetchRepository(CredentialsProvider credentialsProvider, Repository repository, RefSpec... refSpecs) throws Exception {
Git git = new Git(repository);
FetchCommand fetch = git.fetch();
List<RefSpec> specs = new ArrayList<RefSpec>();
if (refSpecs == null || refSpecs.length == 0) {
specs.add(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
specs.add(new RefSpec("+refs/tags/*:refs/tags/*"));
specs.add(new RefSpec("+refs/notes/*:refs/notes/*"));
} else {
specs.addAll(Arrays.asList(refSpecs));
}
if (credentialsProvider != null) {
fetch.setCredentialsProvider(credentialsProvider);
}
fetch.setRefSpecs(specs);
FetchResult fetchRes = fetch.call();
return fetchRes;
}
Aggregations