package org.nibor.git_merge_repos;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.transport.URIish;

/**
 * Main class for merging repositories via command-line.
 */
public class Main {

	private static Pattern REPO_AND_DIR = Pattern.compile("(.*):([^:]+)");

	public static void main(String[] args) throws IOException, GitAPIException, URISyntaxException {
		List<SubtreeConfig> subtreeConfigs = new ArrayList<SubtreeConfig>();

		for (String arg : args) {
			Matcher matcher = REPO_AND_DIR.matcher(arg);
			if (matcher.matches()) {
				String repositoryUrl = matcher.group(1);
				String directory = matcher.group(2);
				SubtreeConfig config = new SubtreeConfig(directory, new URIish(repositoryUrl));
				subtreeConfigs.add(config);
			} else {
				exitInvalidUsage("invalid argument '" + arg
						+ "', expected '<repository_url>:<target_directory>'");
			}
		}

		if (subtreeConfigs.isEmpty()) {
			exitInvalidUsage("usage: program <repository_url>:<target_directory>...");
		}

		RepoMerger merger = new RepoMerger("output", subtreeConfigs);
		merger.run();
	}

	private static void exitInvalidUsage(String message) {
		System.err.println(message);
		System.exit(64);
	}
}

@@ -29,16 +29,37 @@
 repos;%0A%0A
+import java.io.File;%0A
 import j
@@ -1209,16 +1209,297 @@
 );%0A%09%09%7D%0A%0A
+%09%09File outputDirectory = new File(%22merged-repo%22);%0A%09%09String outputPath = outputDirectory.getAbsolutePath();%0A%09%09System.out.println(%22Started merging %22 + subtreeConfigs.size()%0A%09%09%09%09+ %22 repositories into one, output directory: %22 + outputPath);%0A%0A%09%09long start = System.currentTimeMillis();%0A
 %09%09RepoMe
@@ -1531,16 +1531,18 @@
 ger(
-%22
 output
-%22
+Path
 , su
@@ -1572,16 +1572,201 @@
 .run();%0A
+%09%09long end = System.currentTimeMillis();%0A%0A%09%09long timeMs = (end - start);%0A%09%09System.out.println(%22Done, took %22 + timeMs + %22 ms%22);%0A%09%09System.out.println(%22Merged repository: %22 + outputPath);%0A
 %09%7D%0A%0A%09pri

Add more output: how long it took, where the merged repo is