From 175f08e1e4c524e986d9ecaa5dacdcca733e73cb Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 7 Nov 2011 07:33:35 -0500 Subject: [PATCH] Stefan Zeiger's fixes to not NPE when checking for windows. Additional cleanup to put windows git-run checks in one function. --- main/Build.scala | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/main/Build.scala b/main/Build.scala index 217dbe813..6bb0b7f5a 100644 --- a/main/Build.scala +++ b/main/Build.scala @@ -88,22 +88,19 @@ object RetrieveUnit } def dropFragment(base: URI): URI = if(base.getFragment eq null) base else new URI(base.getScheme, base.getSchemeSpecificPart, null) - lazy val isWindowsShell = - ((!System.getenv("SHELL").contains("cygwin")) && - (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0)) - def gitClone(base: URI, tempDir: File): Unit = - if(isWindowsShell) { - run("cmd" :: "/c" :: "git" :: "clone" :: dropFragment(base).toASCIIString :: tempDir.getAbsolutePath :: Nil, tempDir) ; - } else { - run("git" :: "clone" :: dropFragment(base).toASCIIString :: tempDir.getAbsolutePath :: Nil, tempDir) ; - } + git("clone" :: dropFragment(base).toASCIIString :: tempDir.getAbsolutePath :: Nil, tempDir) ; def gitCheckout(tempDir: File, branch: String): Unit = - if(isWindowsShell) { - run("cmd" :: "/c" :: "git" :: "checkout" :: "-q" :: branch :: Nil, tempDir) ; - } else { - run("git" :: "checkout" :: "-q" :: branch :: Nil, tempDir) ; - } + git("checkout" :: "-q" :: branch :: Nil, tempDir) + def git(args: List[String], cwd: File): Unit = + if(isWindowsShell) run(List("cmd", "/c", "git") ++ args, cwd) + else run("git" +: args, cwd) + lazy val isWindowsShell = { + val ostype = System.getenv("OSTYPE") + val isCygwin = ostype != null && ostype.toLowerCase.contains("cygwin") + val isWindows = System.getProperty("os.name", "").toLowerCase.contains("windows") + isWindows && !isCygwin + } def run(command: List[String], cwd: File): Unit = { val result = Process(command, cwd) ! ;