Java Code Examples for org.eclipse.jgit.api.RemoteSetUrlCommand#call()

The following examples show how to use org.eclipse.jgit.api.RemoteSetUrlCommand#call() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackupService.java    From app-runner with MIT License 7 votes vote down vote up
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.setRemoteName("origin");
        remoteSetUrlCommand.setRemoteUri(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);
}
 
Example 2
Source File: AbstractGitTest.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
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();
	}
}
 
Example 3
Source File: GitTestUtils.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
public static void setOriginOnProjectToTmp(File origin, File project)
		throws GitAPIException, MalformedURLException {
	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(true);
		command.call();
	}
}
 
Example 4
Source File: GitTestUtils.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
public static void setOriginOnProjectToTmp(File origin, File project)
		throws GitAPIException, MalformedURLException {
	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(true);
		command.call();
	}
}
 
Example 5
Source File: GitTestUtils.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
public static void setOriginOnProjectToTmp(File origin, File project)
		throws GitAPIException, MalformedURLException {
	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(true);
		command.call();
	}
}