Created
July 24, 2012 20:24
-
-
Save philcali/3172412 to your computer and use it in GitHub Desktop.
Massaging submodule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source.{fromFile => open} | |
import scala.sys.process._ | |
if (args.length < 1) { | |
println("Give me an existing .gitmodules file to copy") | |
exit(0) | |
} | |
val Submodule = """\[submodule "(.*)"\]""".r | |
val Url = """\s+url = (.*)""".r | |
def write(text: String) = { | |
val writer = new java.io.FileWriter("submodule_errors", true) | |
writer.write(text) | |
writer.close() | |
} | |
def log(lines: Seq[String], path: String) = { | |
ProcessLogger(str => str match { | |
case str if str.contains("fatal") => | |
write(lines.mkString("\n")) | |
// Cleanup submodule add network failure | |
("rm -rf .git/modules/%s" format path) run() | |
("rm -rf %s" format path) run() | |
case str => println(str) | |
}) | |
} | |
open(args(0)).getLines.sliding(3, 3).foreach (lines => lines match { | |
case Submodule(path) :: _ :: Url(url) :: Nil => | |
("git submodule add %s %s" format (url, path)) ! (log(lines, path)) | |
case ls => println(ls.mkString("\n")) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment