@Signature public Memory remoteList() throws GitAPIException { RemoteListCommand command = getWrappedObject().remoteList(); List<RemoteConfig> call = command.call(); return GitUtils.valueOfRemoteConfigs(call); }
public RemoteListCommand _remoteList() { return git.remoteList(); }
protected void doRemoteList(Exchange exchange, String operation) throws Exception { List<RemoteConfig> result = null; try { result = git.remoteList().call(); } catch (Exception e) { LOG.error("There was an error in Git {} operation", operation); throw e; } updateExchange(exchange, result); }
private RemoteConfig getRemote(Git git, String name) { List<RemoteConfig> remotes; try { remotes = git.remoteList().call(); } catch (GitAPIException e) { throw new IllegalStateException(e); } for (RemoteConfig remote: remotes) { if (remote.getName().equals(name)) { return remote; } } return null; }
/** * Checks if the upstream repo exist and if there is a proper URL */ private boolean isUpstreamRepoCreated(Git git, String path) throws Exception { try { List<RemoteConfig> remotes = git.remoteList().call(); for(RemoteConfig remote : remotes){ if(remote.getName().equals(UPSTREAM)){ for(URIish uri : remote.getURIs()){ if(uri.toString().equals(getRemoteRepoUrlFromPom(path))){ return true; }else { deleteUpstreamRepo(git); } } } } } catch (GitAPIException e) { throw new Exception(CREATING_REMOTE_UPSTREAM_REASON, e); } return false; }
final List<RemoteConfig> remotes = git.remoteList().call(); final boolean isRemoteExist = remotes.stream().anyMatch(remote -> remote.getName().equals(remoteToPush)); if (!isRemoteExist) {
public static BackupService prepare(File localDir, URIish remoteUri, int backupTimeInMinutes) throws GitAPIException, IOException { Git local; try { local = Git.open(localDir); } catch (RepositoryNotFoundException e) { log.info("Initialising " + fullPath(localDir) + " as a git repo for backup purposes"); local = Git.init().setDirectory(localDir).setBare(false).call(); } log.info("Setting backup URL to " + remoteUri); if (local.remoteList().call().stream().anyMatch(remoteConfig -> remoteConfig.getName().equals("origin"))) { RemoteSetUrlCommand remoteSetUrlCommand = local.remoteSetUrl(); remoteSetUrlCommand.setName("origin"); remoteSetUrlCommand.setUri(remoteUri); remoteSetUrlCommand.call(); } else { RemoteAddCommand remoteAddCommand = local.remoteAdd(); remoteAddCommand.setName("origin"); remoteAddCommand.setUri(remoteUri); remoteAddCommand.call(); } URL inputUrl = BackupService.class.getResource("/dataDirGitIgnore.txt"); FileUtils.copyURLToFile(inputUrl, new File(localDir, ".gitignore")); return new BackupService(local, remoteUri.toString(), backupTimeInMinutes); } }
private void addOrigin() throws URISyntaxException, GitAPIException { RemoteAddCommand add = git.remoteAdd(); add.setName("origin"); String uri = "https://example.org/repo"; add.setUri(new URIish(uri)); add.call(); assertEquals("origin", git.remoteList().call().iterator().next().getName()); assertEquals(uri, git.remoteList().call().iterator().next().getURIs().iterator().next().toString()); } }
@Test public void testEmptyCredentials() throws IOException, GitAPIException { final File parentFolder = createTempDirectory(); final File directory = new File(parentFolder, TARGET_GIT); new Clone(directory, ORIGIN, false, null, null, null).execute(); final Git cloned = Git.open(directory); assertThat(cloned).isNotNull(); assertThat(new ListRefs(cloned.getRepository()).execute()).is(new Condition<List<? extends Ref>>() { @Override public boolean matches(final List<? extends Ref> refs) { return refs.size() > 0; } }); assertThat(new ListRefs(cloned.getRepository()).execute().get(0).getName()).isEqualTo("refs/heads/master"); URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0); String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath(); assertThat(remoteUrl).isEqualTo(ORIGIN); }
@Test public void testEmptyCredentials() throws IOException, GitAPIException { final File parentFolder = createTempDirectory(); final File directory = new File(parentFolder, TARGET_GIT); new Clone(directory, ORIGIN, false, null, null, null).execute(); final Git cloned = Git.open(directory); assertThat(cloned).isNotNull(); assertThat(new ListRefs(cloned.getRepository()).execute()).is(new Condition<List<? extends Ref>>() { @Override public boolean matches(final List<? extends Ref> refs) { return refs.size() > 0; } }); assertThat(new ListRefs(cloned.getRepository()).execute().get(0).getName()).isEqualTo("refs/heads/master"); URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0); String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath(); assertThat(remoteUrl).isEqualTo(ORIGIN); }
URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0); String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath(); assertThat(remoteUrl).isEqualTo(ORIGIN);
@Test public void testToHTTPMirrorSuccess() throws IOException, GitAPIException { final File parentFolder = createTempDirectory(); final File directory = new File(parentFolder, TARGET_GIT); new Clone(directory, ORIGIN, true, CredentialsProvider.getDefault(), null, null).execute(); final Git cloned = Git.open(directory); assertThat(cloned).isNotNull(); assertThat(cloned.getRepository().getAllRefs()).is(new Condition<Map<String, Ref>>() { @Override public boolean matches(final Map<String, Ref> refs) { final boolean hasMasterRef = refs.get("refs/heads/master") != null; final boolean hasPullRequestRef = refs.get("refs/pull/1/head") != null; return hasMasterRef && hasPullRequestRef; } }); final boolean isMirror = cloned.getRepository().getConfig().getBoolean("remote", "origin", "mirror", false); assertTrue(isMirror); URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0); String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath(); assertThat(remoteUrl).isEqualTo(ORIGIN); }
@Test public void testToHTTPMirrorSuccess() throws IOException, GitAPIException { final File parentFolder = createTempDirectory(); final File directory = new File(parentFolder, TARGET_GIT); new Clone(directory, ORIGIN, true, CredentialsProvider.getDefault(), null, null).execute(); final Git cloned = Git.open(directory); assertThat(cloned).isNotNull(); assertThat(cloned.getRepository().getAllRefs()).is(new Condition<Map<String, Ref>>() { @Override public boolean matches(final Map<String, Ref> refs) { final boolean hasMasterRef = refs.get("refs/heads/master") != null; final boolean hasPullRequestRef = refs.get("refs/pull/1/head") != null; return hasMasterRef && hasPullRequestRef; } }); final boolean isMirror = cloned.getRepository().getConfig().getBoolean("remote", "origin", "mirror", false); assertTrue(isMirror); URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0); String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath(); assertThat(remoteUrl).isEqualTo(ORIGIN); }
URIish remoteUri = cloned.remoteList().call().get(0).getURIs().get(0); String remoteUrl = remoteUri.getScheme() + "://" + remoteUri.getHost() + remoteUri.getPath(); assertThat(remoteUrl).isEqualTo(ORIGIN);