类org.eclipse.jgit.transport.RemoteConfig源码实例Demo

下面列出了怎么用org.eclipse.jgit.transport.RemoteConfig的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Jpom   文件: GitUtil.java
/**
 * 检查本地的remote是否存在对应的url
 *
 * @param url  要检查的url
 * @param file 本地仓库文件
 * @return true 存在对应url
 * @throws IOException     IO
 * @throws GitAPIException E
 */
private static boolean checkRemoteUrl(String url, File file) throws IOException, GitAPIException {
    try (Git git = Git.open(file)) {
        RemoteListCommand remoteListCommand = git.remoteList();
        boolean urlTrue = false;
        List<RemoteConfig> list = remoteListCommand.call();
        end:
        for (RemoteConfig remoteConfig : list) {
            for (URIish urIish : remoteConfig.getURIs()) {
                if (urIish.toString().equals(url)) {
                    urlTrue = true;
                    break end;
                }
            }
        }
        return urlTrue;
    }
}
 
源代码2 项目: netbeans   文件: TransportCommand.java
protected final URIish getUri (boolean pushUri) throws URISyntaxException {
    RemoteConfig config = getRemoteConfig();
    List<URIish> uris;
    if (config == null) {
        uris = Collections.emptyList();
    } else {
        if (pushUri) {
            uris = config.getPushURIs();
            if (uris.isEmpty()) {
                uris = config.getURIs();
            }
        } else {
            uris = config.getURIs();
        }
    }
    if (uris.isEmpty()) {
        return new URIish(remote);
    } else {
        return uris.get(0);
    }
}
 
源代码3 项目: netbeans   文件: TransportCommand.java
protected Transport openTransport (boolean openPush) throws URISyntaxException, NotSupportedException, TransportException {
    URIish uri = getUriWithUsername(openPush);
    // WA for #200693, jgit fails to initialize ftp protocol
    for (TransportProtocol proto : Transport.getTransportProtocols()) {
        if (proto.getSchemes().contains("ftp")) { //NOI18N
            Transport.unregister(proto);
        }
    }
    try {
        Transport transport = Transport.open(getRepository(), uri);
        RemoteConfig config = getRemoteConfig();
        if (config != null) {
            transport.applyConfig(config);
        }
        if (transport.getTimeout() <= 0) {
            transport.setTimeout(45);
        }
        transport.setCredentialsProvider(getCredentialsProvider());
        return transport;
    } catch (IllegalArgumentException ex) {
        throw new TransportException(ex.getLocalizedMessage(), ex);
    }
}
 
源代码4 项目: jphp   文件: GitUtils.java
public static ArrayMemory valueOf(RemoteConfig value) {
    ArrayMemory memory = new ArrayMemory();
    memory.refOfIndex("name").assign(value.getName());
    memory.refOfIndex("receivePack").assign(value.getReceivePack());
    memory.refOfIndex("uploadPack").assign(value.getUploadPack());
    memory.refOfIndex("mirror").assign(value.isMirror());
    memory.refOfIndex("timeout").assign(value.getTimeout());
    memory.refOfIndex("tagOpt").assign(value.getTagOpt().name());
    ArrayMemory uris = ArrayMemory.createListed(value.getURIs().size());

    for (URIish urIish : value.getURIs()) {
        uris.add(urIish.toPrivateString());
    }

    memory.refOfIndex("uris").assign(uris);

    return memory;
}
 
源代码5 项目: netbeans   文件: RemotesTest.java
public void testAddRemote () throws Exception {
    StoredConfig config = repository.getConfig();
    assertEquals(0, config.getSubsections("remote").size());
    
    GitClient client = getClient(workDir);
    GitRemoteConfig remoteConfig = new GitRemoteConfig("origin",
            Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()),
            Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()),
            Arrays.asList("+refs/heads/*:refs/remotes/origin/*"),
            Arrays.asList("refs/remotes/origin/*:+refs/heads/*"));
    client.setRemote(remoteConfig, NULL_PROGRESS_MONITOR);
    
    config.load();
    RemoteConfig cfg = new RemoteConfig(config, "origin");
    assertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getURIs());
    assertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getPushURIs());
    assertEquals(Arrays.asList(new RefSpec("+refs/heads/*:refs/remotes/origin/*")), cfg.getFetchRefSpecs());
    assertEquals(Arrays.asList(new RefSpec("refs/remotes/origin/*:+refs/heads/*")), cfg.getPushRefSpecs());
}
 
源代码6 项目: netbeans   文件: PullTest.java
@Override
protected void setUp() throws Exception {
    super.setUp();
    workDir = getWorkingDirectory();
    repository = getRepository(getLocalGitRepository());
    
    otherWT = new File(workDir.getParentFile(), "repo2");
    GitClient client = getClient(otherWT);
    client.init(NULL_PROGRESS_MONITOR);
    f = new File(otherWT, "f");
    write(f, "init");
    f2 = new File(otherWT, "f2");
    write(f2, "init");
    client.add(new File[] { f, f2 }, NULL_PROGRESS_MONITOR);
    masterInfo = client.commit(new File[] { f, f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR);
    branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
    RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
    cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
    cfg.update(repository.getConfig());
    repository.getConfig().save();
}
 
源代码7 项目: netbeans   文件: FetchTest.java
@Override
protected void setUp() throws Exception {
    super.setUp();
    workDir = getWorkingDirectory();
    repository = getRepository(getLocalGitRepository());
    
    otherWT = new File(workDir.getParentFile(), "repo2");
    GitClient client = getClient(otherWT);
    client.init(NULL_PROGRESS_MONITOR);
    f = new File(otherWT, "f");
    write(f, "init");
    client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
    masterInfo = client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
    branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
    RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
    cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
    cfg.update(repository.getConfig());
    repository.getConfig().save();
}
 
源代码8 项目: orion.server   文件: Branch.java
@PropertyDescription(name = GitConstants.KEY_REMOTE)
private JSONArray getRemotes() throws URISyntaxException, JSONException, IOException, CoreException {
	String branchName = Repository.shortenRefName(ref.getName());
	String remoteName = getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE);
	List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
	ArrayList<JSONObject> remotes = new ArrayList<JSONObject>();
	for (RemoteConfig remoteConfig : remoteConfigs) {
		if (!remoteConfig.getFetchRefSpecs().isEmpty()) {
			Remote r = new Remote(cloneLocation, db, remoteConfig.getName());
			r.setNewBranch(branchName);
			// Ensure that the remote tracking branch is the first in the list.
			// Insert at the beginning of the list as well when the remote tracking branch is not set but the branch has been pushed to the remote
			if (remoteConfig.getName().equals(remoteName) || (remoteName == null && db.resolve(Constants.R_REMOTES + remoteConfig.getName() + "/" + branchName) != null)) {
				remotes.add(0, r.toJSON());
			} else {
				remotes.add(r.toJSON());
			}
		}
	}
	JSONArray result = new JSONArray();
	for (JSONObject remote : remotes) {
		result.put(remote);
	}
	return result;
}
 
源代码9 项目: spring-cloud-contract   文件: AbstractGitTest.java
void setOriginOnProjectToTmp(File origin, File project, boolean push)
		throws GitAPIException, IOException, URISyntaxException {
	try (Git git = openGitProject(project)) {
		RemoteRemoveCommand remove = git.remoteRemove();
		remove.setName("origin");
		remove.call();
		RemoteSetUrlCommand command = git.remoteSetUrl();
		command.setUri(new URIish(origin.toURI().toURL()));
		command.setName("origin");
		command.setPush(push);
		command.call();
		StoredConfig config = git.getRepository().getConfig();
		RemoteConfig originConfig = new RemoteConfig(config, "origin");
		originConfig
				.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
		originConfig.update(config);
		config.save();
	}
}
 
private void configureRemote(Git git, String repoUrl) throws URISyntaxException, IOException, GitAPIException {
    StoredConfig config = git.getRepository().getConfig();
    config.clear();
    config.setString("remote", "origin" ,"fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.setString("remote", "origin" ,"push", "+refs/heads/*:refs/remotes/origin/*");
    config.setString("branch", "master", "remote", "origin");
    config.setString("baseBranch", "master", "merge", "refs/heads/master");
    config.setString("push", null, "default", "current");

    // disable all gc
    // http://download.eclipse.org/jgit/site/5.2.1.201812262042-r/apidocs/org/eclipse/jgit/internal/storage/file/GC.html#setAuto-boolean-
    config.setString("gc", null, "auto", "0");
    config.setString("gc", null, "autoPackLimit", "0");
    config.setBoolean("receive", null, "autogc", false);

    RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
    URIish uri = new URIish(repoUrl);
    remoteConfig.addURI(uri);
    remoteConfig.addFetchRefSpec(new RefSpec("refs/heads/master:refs/heads/master"));
    remoteConfig.addPushRefSpec(new RefSpec("refs/heads/master:refs/heads/master"));
    remoteConfig.update(config);

    config.save();
}
 
public Map<String, URIish> getCommitRepoMap() throws Exception {
    List<RemoteConfig> repoList = this.gitScm.getRepositories();
    if (repoList.size() < 1) {
        throw new Exception("No repos found");
    }

    HashMap<String, URIish> commitRepoMap = new HashMap<String, URIish>();
    BuildData buildData = build.getAction(BuildData.class);
    if (buildData == null || buildData.getLastBuiltRevision() == null) {
        logger.warning("Build data could not be found");
    } else {
        commitRepoMap.put(buildData.getLastBuiltRevision().getSha1String(), repoList.get(0).getURIs().get(0));
    }

    return commitRepoMap;
}
 
源代码12 项目: git-client-plugin   文件: JGitAPIImpl.java
/** {@inheritDoc} */
@Override
public void prune(RemoteConfig repository) throws GitException {
    try (Repository gitRepo = getRepository()) {
        String remote = repository.getName();
        String prefix = "refs/remotes/" + remote + "/";

        Set<String> branches = listRemoteBranches(remote);

        for (Ref r : new ArrayList<>(gitRepo.getAllRefs().values())) {
            if (r.getName().startsWith(prefix) && !branches.contains(r.getName())) {
                // delete this ref
                RefUpdate update = gitRepo.updateRef(r.getName());
                update.setRefLogMessage("remote branch pruned", false);
                update.setForceUpdate(true);
                update.delete();
            }
        }
    } catch (URISyntaxException | IOException e) {
        throw new GitException(e);
    }
}
 
@Test
@Deprecated
public void testCloneRemoteConfig() throws URISyntaxException, InterruptedException, IOException, ConfigInvalidException {
    if (gitImpl.equals("jgit")) {
        return;
    }
    Config config = new Config();
    /* Use local git-client-plugin repository as source for clone test */
    String remoteName = "localCopy";
    String localRepoPath = (new File(".")).getCanonicalPath().replace("\\", "/");
    String configText = "[remote \"" + remoteName + "\"]\n"
            + "url = " + localRepoPath + "\n"
            + "fetch = +refs/heads/*:refs/remotes/" + remoteName + "/*\n";
    config.fromText(configText);
    RemoteConfig remoteConfig = new RemoteConfig(config, remoteName);
    List<URIish> list = remoteConfig.getURIs();
    git.clone(remoteConfig);
    File[] files = git.workspace.listFiles();
    assertEquals(files.length + "files in " + Arrays.toString(files), 1, files.length);
    assertEquals("Wrong file name", ".git", files[0].getName());
}
 
源代码14 项目: hop   文件: UIGit.java
@Override
public String getRemote() {
  try {
    StoredConfig config = git.getRepository().getConfig();
    RemoteConfig remoteConfig = new RemoteConfig( config, Constants.DEFAULT_REMOTE_NAME );
    return remoteConfig.getURIs().iterator().next().toString();
  } catch ( Exception e ) {
    return "";
  }
}
 
源代码15 项目: hop   文件: UIGitTest.java
@Test
public void testAddRemoveRemote() throws Exception {
  URIish uri = new URIish( db2.getDirectory().toURI().toURL().toString() );
  uiGit.addRemote( uri.toString() );
  assertEquals( uri.toString(), uiGit.getRemote() );

  uiGit.removeRemote();
  // assert that there are no remotes left
  assertTrue( RemoteConfig.getAllRemoteConfigs( db.getConfig() ).isEmpty() );
}
 
源代码16 项目: hop   文件: UIGitTest.java
private RemoteConfig setupRemote() throws Exception {
  URIish uri = new URIish(
      db2.getDirectory().toURI().toURL() );
  RemoteAddCommand cmd = git.remoteAdd();
  cmd.setName( Constants.DEFAULT_REMOTE_NAME );
  cmd.setUri( uri );
  return cmd.call();
}
 
源代码17 项目: halo   文件: GitTest.java
@Test
public void remoteAddTest() throws GitAPIException, URISyntaxException {
    Git git = Git.init().setDirectory(tempPath.toFile()).call();
    git.remoteRemove().setRemoteName("theme-provider").call();
    git.remoteAdd().setName("theme-provider").setUri(new URIish("https://github.com/halo-dev/halo-theme-pinghsu.git")).call();
    List<RemoteConfig> remoteConfigs = git.remoteList().call();
    remoteConfigs.forEach(remoteConfig -> log.debug("name: [{}], url: [{}]", remoteConfig.getName(), remoteConfig.getURIs()));
}
 
@Theory
public void createRevisionParameterAction_pushCommitRequest(GitLabPushRequestSamples samples) throws Exception {
    PushHook hook = samples.pushCommitRequest();

    RevisionParameterAction revisionParameterAction = new PushHookTriggerHandlerImpl(false).createRevisionParameter(hook, null);

    assertThat(revisionParameterAction, is(notNullValue()));
    assertThat(revisionParameterAction.commit, is(hook.getAfter()));
    assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList<RemoteConfig>()));
}
 
源代码19 项目: netbeans   文件: TransportCommand.java
protected final RemoteConfig getRemoteConfig () throws URISyntaxException {
    RemoteConfig config = new RemoteConfig(getRepository().getConfig(), remote);
    if (config.getURIs().isEmpty() && config.getPushURIs().isEmpty()) {
        return null;
    } else {
        return config;
    }
}
 
源代码20 项目: netbeans   文件: GitRemoteConfig.java
static GitRemoteConfig fromRemoteConfig (RemoteConfig config) {
    return new GitRemoteConfig(config.getName(),
            getAsStrings(config.getURIs()),
            getAsStrings(config.getPushURIs()),
            getAsStrings(config.getFetchRefSpecs()),
            getAsStrings(config.getPushRefSpecs()));
}
 
源代码21 项目: netbeans   文件: RemotesTest.java
public void testRemoveRemote () throws Exception {
    File otherWT = new File(workDir.getParentFile(), "repo2");
    GitClient client = getClient(otherWT);
    client.init(NULL_PROGRESS_MONITOR);
    File f = new File(otherWT, "f");
    write(f, "init");
    client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
    client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
    
    RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
    cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
    cfg.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
    cfg.update(repository.getConfig());
    repository.getConfig().save();
    
    client = getClient(workDir);
    client.fetch("origin", NULL_PROGRESS_MONITOR);
    client.createBranch("master", "origin/master", NULL_PROGRESS_MONITOR);
    client.createBranch("nova", "origin/master", NULL_PROGRESS_MONITOR);
    
    StoredConfig config = repository.getConfig();
    assertEquals("+refs/heads/*:refs/remotes/origin/*", config.getString("remote", "origin", "fetch"));
    assertEquals("origin", config.getString("branch", "master", "remote"));
    assertEquals("refs/heads/master", config.getString("branch", "master", "merge"));
    assertEquals("origin", config.getString("branch", "nova", "remote"));
    assertEquals("refs/heads/master", config.getString("branch", "nova", "merge"));
    
    // now try to remove the remote
    client.removeRemote("origin", NULL_PROGRESS_MONITOR);
    config = repository.getConfig();
    config.load();
    // is everything deleted?
    assertEquals(0, config.getSubsections("remote").size());
    assertNull(config.getString("branch", "master", "remote"));
    assertNull(config.getString("branch", "master", "merge"));
    assertNull(config.getString("branch", "nova", "remote"));
    assertNull(config.getString("branch", "nova", "merge"));
}
 
源代码22 项目: netbeans   文件: GetRemotesTest.java
public void testGetRemotes () throws Exception {
    GitClient client = getClient(workDir);
    StoredConfig cfg = repository.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(cfg, "origin");
    
    Map<String, GitRemoteConfig> remotes = client.getRemotes(NULL_PROGRESS_MONITOR);
    assertEquals(0, remotes.size());
    remoteConfig.update(cfg);
    cfg.save();
    
    remotes = client.getRemotes(NULL_PROGRESS_MONITOR);
    assertEquals(0, remotes.size());
    
    remoteConfig.addURI(new URIish("file:///home/repository"));
    remoteConfig.addURI(new URIish("file:///home/repository2"));
    remoteConfig.addPushURI(new URIish("file:///home/repository"));
    remoteConfig.addPushURI(new URIish("file:///home/repository3"));
    remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
    remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/master:refs/remotes/origin/my-master"));
    remoteConfig.addPushRefSpec(new RefSpec("refs/remotes/origin/*:refs/heads/*"));
    remoteConfig.update(cfg);
    cfg.save();
    
    remotes = client.getRemotes(NULL_PROGRESS_MONITOR);
    assertEquals(1, remotes.size());
    assertEquals("origin", remotes.get("origin").getRemoteName());
    assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository2" }), remotes.get("origin").getUris());
    assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository3" }), remotes.get("origin").getPushUris());
    assertEquals(Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*", "+refs/heads/master:refs/remotes/origin/my-master" }), remotes.get("origin").getFetchRefSpecs());
    assertEquals(Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" }), remotes.get("origin").getPushRefSpecs());
    
    GitRemoteConfig remote = client.getRemote("origin", NULL_PROGRESS_MONITOR);
    assertEquals("origin", remote.getRemoteName());
    assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository2" }), remote.getUris());
    assertEquals(Arrays.asList(new String[] { "file:///home/repository", "file:///home/repository3" }), remote.getPushUris());
    assertEquals(Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*", "+refs/heads/master:refs/remotes/origin/my-master" }), remote.getFetchRefSpecs());
    assertEquals(Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" }), remote.getPushRefSpecs());
}
 
源代码23 项目: git-client-plugin   文件: CredentialsTest.java
@Test
@Issue("JENKINS-50573")
public void testFetchWithCredentials() throws Exception {
    assumeTrue(testPeriodNotExpired());
    assumeFalse(lfsSpecificTest);
    File clonedFile = new File(repo, fileToCheck);
    git.init_().workspace(repo.getAbsolutePath()).execute();
    assertFalse("file " + fileToCheck + " in " + repo + ", has " + listDir(repo), clonedFile.exists());
    addCredential();
    /* Fetch with remote URL */
    doFetch(gitRepoURL);
    git.setRemoteUrl("origin", gitRepoURL);
    /* Fetch with remote name "origin" instead of remote URL */
    doFetch("origin");
    ObjectId master = git.getHeadRev(gitRepoURL, "master");
    git.checkout().branch("master").ref(master.getName()).deleteBranchIfExist(true).execute();
    if (submodules) {
        git.submoduleInit();
        SubmoduleUpdateCommand subcmd = git.submoduleUpdate().parentCredentials(useParentCreds);
        subcmd.execute();
    }
    assertTrue("master: " + master + " not in repo", git.isCommitInRepo(master));
    assertEquals("Master != HEAD", master, git.withRepository((gitRepo, unusedChannel)-> gitRepo.findRef("master").getObjectId()));
    assertEquals("Wrong branch", "master", git.withRepository((gitRepo, unusedChanel) -> gitRepo.getBranch()));
    assertTrue("No file " + fileToCheck + ", has " + listDir(repo), clonedFile.exists());
    /* prune opens a remote connection to list remote branches */
    git.prune(new RemoteConfig(git.withRepository((gitRepo, unusedChannel) -> gitRepo.getConfig()), "origin"));
}
 
源代码24 项目: orion.server   文件: Log.java
private Remote findRemote(String refName) throws URISyntaxException {
	Assert.isLegal(refName.startsWith(Constants.R_REMOTES), NLS.bind("Expected Ref starting with {0} was {1}", Constants.R_REMOTES, refName));
	IPath remoteNameCandidate = new Path(refName).removeFirstSegments(2);
	List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
	for (int i = 1; i < remoteNameCandidate.segmentCount(); i++) {
		for (RemoteConfig remoteConfig : remoteConfigs) {
			IPath uptoSegment = remoteNameCandidate.uptoSegment(i);
			if (remoteConfig.getName().equals(uptoSegment.toString()))
				return new Remote(cloneLocation, db, remoteConfig.getName());
		}
	}
	Assert.isTrue(false, NLS.bind("Could not find Remote for {0}", refName));
	return null;
}
 
源代码25 项目: orion.server   文件: GitRemoteTest.java
@Test
public void testRemoteProperties() throws IOException, SAXException, JSONException, CoreException, URISyntaxException {
	createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
	String workspaceId = workspaceIdFromLocation(workspaceLocation);
	JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null);
	IPath clonePath = getClonePath(workspaceId, project);
	JSONObject clone = clone(clonePath);
	String remotesLocation = clone.getString(GitConstants.KEY_REMOTE);
	project.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

	// create remote
	final String remoteName = "remote1";
	final String remoteUri = "http://remote1.com";
	final String fetchRefSpec = "+refs/heads/*:refs/remotes/%s/*";
	final String pushUri = "http://remote2.com";
	final String pushRefSpec = "refs/heads/*:refs/heads/*";
	addRemote(remotesLocation, remoteName, remoteUri, fetchRefSpec, pushUri, pushRefSpec);

	Repository db2 = FileRepositoryBuilder.create(GitUtils.getGitDir(new Path(toRelativeURI(clonePath.toString()))));
	toClose.add(db2);
	StoredConfig config = db2.getConfig();
	RemoteConfig rc = new RemoteConfig(config, remoteName);

	assertNotNull(rc);
	// main uri
	assertEquals(1, rc.getURIs().size());
	assertEquals(new URIish(remoteUri).toString(), rc.getURIs().get(0).toString());
	// fetchRefSpec
	assertEquals(1, rc.getFetchRefSpecs().size());
	assertEquals(new RefSpec(fetchRefSpec), rc.getFetchRefSpecs().get(0));
	// pushUri
	assertEquals(1, rc.getPushURIs().size());
	assertEquals(new URIish(pushUri).toString(), rc.getPushURIs().get(0).toString());
	// pushRefSpec
	assertEquals(1, rc.getPushRefSpecs().size());
	assertEquals(new RefSpec(pushRefSpec), rc.getPushRefSpecs().get(0));
}
 
private boolean matchesGitSCM(final Event event, final SCM scmProvider) {
    if (!(scmProvider instanceof GitSCM)) {
        return false;
    }

    final GitSCM git = (GitSCM) scmProvider;
    final List<RemoteConfig> configs = git.getRepositories();

    boolean matched = this.matchesConfigs(event, configs);
    matched = matched && this.matchBranch(event, git.getBranches());
    return matched;
}
 
/** {@inheritDoc} */
@Deprecated
public void clone(RemoteConfig rc, boolean useShallowClone) throws GitException, InterruptedException {
    // Assume only 1 URL for this repository
    final String source = rc.getURIs().get(0).toPrivateString();
    clone(source, rc.getName(), useShallowClone, null);
}
 
private URIish getMatchesConfig(final Event event, final RemoteConfig config) {
    List<URIish> uris = config.getURIs();
    for (final URIish uri : uris) {
        log.debug("Event-arn= %s ; uri= %s", event.getArn(), uri);
        if (event.isMatch(uri)) {//TODO use here matchBranch(event, branchSpec)
            log.info("Event matched uri %s", uri);
            return uri;
        }
    }

    log.info("Found no event matched config: ", event.getArn(), config.getName());
    return null;
}
 
源代码29 项目: aws-codecommit-trigger-plugin   文件: RepoInfo.java
public static RepoInfo fromSqsJob(SQSJob sqsJob) {
    if (sqsJob == null) {
        return null;
    }

    RepoInfo repoInfo = new RepoInfo();

    List<SCM> scms = sqsJob.getScmList();
    List<String> codeCommitUrls = new ArrayList<>();
    List<String> nonCodeCommitUrls = new ArrayList<>();
    List<String> branches = new ArrayList<>();

    for (SCM scm : scms) {
        if (scm instanceof GitSCM) {//TODO refactor to visitor
            GitSCM git = (GitSCM) scm;
            List<RemoteConfig> repos = git.getRepositories();
            for (RemoteConfig repo : repos) {
                for (URIish urIish : repo.getURIs()) {
                    String url = urIish.toString();
                    if (StringUtils.isCodeCommitRepo(url)) {
                        codeCommitUrls.add(url);
                    }
                    else {
                        nonCodeCommitUrls.add(url);
                    }
                }
            }

            for (BranchSpec branchSpec : git.getBranches()) {
                branches.add(branchSpec.getName());
            }
        }
    }

    repoInfo.nonCodeCommitUrls = nonCodeCommitUrls;
    repoInfo.codeCommitUrls = codeCommitUrls;
    repoInfo.branches = branches;
    return repoInfo;
}
 
源代码30 项目: gitlab-plugin   文件: ProjectBranchesProvider.java
private URIish getFirstRepoURL(List<RemoteConfig> repositories) {
    if (!repositories.isEmpty()) {
        List<URIish> uris = repositories.get(repositories.size() - 1).getURIs();
        if (!uris.isEmpty()) {
            return uris.get(uris.size() - 1);
        }
    }
    throw new IllegalStateException(Messages.GitLabPushTrigger_NoSourceRepository());
}