diff --git a/README.md b/README.md index bcecc8b..42a629a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# distribugit -Tool for performing operations on many git repositories at once. +# DistribuGit +Tool for performing operations on many git repositories at once. It works by cloning a set of repositories, and applying an action to each repository. + +The easiest way to use this toolset for automating git operations is to include it as a maven dependency. diff --git a/src/main/java/nl/andrewl/distribugit/DistribuGit.java b/src/main/java/nl/andrewl/distribugit/DistribuGit.java index c7ac9c7..0fd668c 100644 --- a/src/main/java/nl/andrewl/distribugit/DistribuGit.java +++ b/src/main/java/nl/andrewl/distribugit/DistribuGit.java @@ -166,13 +166,14 @@ public class DistribuGit { } public static void main(String[] args) throws IOException { - new Builder() + new DistribuGit.Builder() .selector(RepositorySelector.from( "https://github.com/andrewlalis/RandomHotbar.git", "https://github.com/andrewlalis/CoyoteCredit.git", "https://github.com/andrewlalis/SignalsAndSystems2021.git" )) - .action(git -> System.out.println("Cloned!")) + .credentials(GitCredentials.ofUsernamePassword("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", "")) + .action(RepositoryAction.ofCommand("/bin/bash", "../../test.sh")) .statusListener(new StatusListener() { @Override public void progressUpdated(float percentage) { @@ -184,8 +185,8 @@ public class DistribuGit { System.out.println("Message: " + message); } }) - .strictFail(true) - .cleanup(true) + .strictFail(false) + .cleanup(false) .build().doActions(); } } diff --git a/src/main/java/nl/andrewl/distribugit/RepositoryAction.java b/src/main/java/nl/andrewl/distribugit/RepositoryAction.java index 93c4f0d..43b4fe9 100644 --- a/src/main/java/nl/andrewl/distribugit/RepositoryAction.java +++ b/src/main/java/nl/andrewl/distribugit/RepositoryAction.java @@ -5,5 +5,21 @@ import org.eclipse.jgit.api.Git; public interface RepositoryAction { void doAction(Git git) throws Exception; - + /** + * An action which executes a system command, as handled by + * {@link ProcessBuilder}. Note that the working directory of the command + * is set to the directory of the repository. + * @param command The command to run. + * @return The command action. + */ + static RepositoryAction ofCommand(String... command) { + return git -> { + ProcessBuilder pb = new ProcessBuilder(command); + pb.directory(git.getRepository().getWorkTree()); + pb.inheritIO(); + Process p = pb.start(); + int result = p.waitFor(); + if (result != 0) throw new IllegalStateException("Non-zero exit code from script."); + }; + } }