List of usage examples for org.eclipse.jgit.api LsRemoteCommand setHeads
public LsRemoteCommand setHeads(boolean heads)
From source file:bluej.groupwork.git.GitProvider.java
License:Open Source License
@Override public TeamworkCommandResult checkConnection(TeamSettings settings) { try {//from w ww. ja va 2 s.c o m String gitUrl = makeGitUrl(settings); //perform a lsRemote on the remote git repo. LsRemoteCommand lsRemoteCommand = Git.lsRemoteRepository(); UsernamePasswordCredentialsProvider cp = new UsernamePasswordCredentialsProvider(settings.getUserName(), settings.getPassword()); // set a configuration with username and password. lsRemoteCommand.setRemote(gitUrl); //configure remote repository address. lsRemoteCommand.setCredentialsProvider(cp); //associate the repository to the username and password. lsRemoteCommand.setTags(false); //disable refs/tags in reference results lsRemoteCommand.setHeads(false); //disable refs/heads in reference results //It seems that ssh host fingerprint check is not working properly. //Disable it in a ssh connection. if (gitUrl.startsWith("ssh")) { SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() { @Override protected void configure(OpenSshConfig.Host host, Session sn) { java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); sn.setConfig(config); } @Override protected JSch createDefaultJSch(FS fs) throws JSchException { return super.createDefaultJSch(fs); } }; lsRemoteCommand.setTransportConfigCallback((Transport t) -> { SshTransport sshTransport = (SshTransport) t; sshTransport.setSshSessionFactory(sshSessionFactory); }); } lsRemoteCommand.call(); //executes the lsRemote commnand. } catch (GitAPIException ex) { return new TeamworkCommandError(ex.getMessage(), ex.getLocalizedMessage()); } catch (UnsupportedSettingException ex) { return new TeamworkCommandUnsupportedSetting(ex.getMessage()); } //if we got here, it means the command was successful. return new TeamworkCommandResult(); }
From source file:org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand.java
License:Apache License
@Override public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException { GitScmProviderRepository repo = (GitScmProviderRepository) repository; Git git = null;/*w ww . j a v a 2 s .c o m*/ try { git = Git.open(fileSet.getBasedir()); CredentialsProvider credentials = JGitUtils.getCredentials(repo); LsRemoteCommand lsCommand = git.lsRemote().setRemote(repo.getPushUrl()) .setCredentialsProvider(credentials); Map<String, String> tag = new HashMap<String, String>(); Collection<Ref> allTags = lsCommand.setHeads(false).setTags(true).call(); for (Ref ref : allTags) { tag.put(Repository.shortenRefName(ref.getName()), ref.getObjectId().name()); } Map<String, String> heads = new HashMap<String, String>(); Collection<Ref> allHeads = lsCommand.setHeads(true).setTags(false).call(); for (Ref ref : allHeads) { heads.put(Repository.shortenRefName(ref.getName()), ref.getObjectId().name()); } return new RemoteInfoScmResult("JGit remoteinfo", heads, tag); } catch (Exception e) { throw new ScmException("JGit remoteinfo failure!", e); } finally { JGitUtils.closeRepo(git); } }