Skip to content

Instantly share code, notes, and snippets.

@philcali
Created July 24, 2012 20:24
Show Gist options
  • Save philcali/3172412 to your computer and use it in GitHub Desktop.
Save philcali/3172412 to your computer and use it in GitHub Desktop.
Massaging submodule
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