diff --git a/src/app/FakeLib/Git/Information.fs b/src/app/FakeLib/Git/Information.fs index 607a9c3fbb9..9bc88e2bf6a 100644 --- a/src/app/FakeLib/Git/Information.fs +++ b/src/app/FakeLib/Git/Information.fs @@ -24,26 +24,31 @@ let isGitVersionHigherOrEqual referenceVersion = /// Gets the git branch name let getBranchName repositoryDir = - if (repositoryDir = "" || repositoryDir = ".") && buildServer = TeamFoundation then - environVar "BUILD_SOURCEBRANCHNAME" - else - let ok,msg,errors = runGitCommand repositoryDir "status" - let s = msg |> Seq.head + try + let ok,msg,errors = runGitCommand repositoryDir "status" + let s = msg |> Seq.head - let mutable replaceBranchString = "On branch " - let mutable replaceNoBranchString = "Not currently on any branch." - let noBranch = "NoBranch" + let mutable replaceBranchString = "On branch " + let mutable replaceNoBranchString = "Not currently on any branch." + let noBranch = "NoBranch" - if isGitVersionHigherOrEqual "1.9" then replaceNoBranchString <- "HEAD detached" - if not <| isGitVersionHigherOrEqual "1.9" then replaceBranchString <- "# " + replaceBranchString + if isGitVersionHigherOrEqual "1.9" then replaceNoBranchString <- "HEAD detached" + if not <| isGitVersionHigherOrEqual "1.9" then replaceBranchString <- "# " + replaceBranchString - if startsWith replaceNoBranchString s then noBranch else s.Replace(replaceBranchString,"") + if startsWith replaceNoBranchString s then noBranch else s.Replace(replaceBranchString,"") + with _ when (repositoryDir = "" || repositoryDir = ".") && buildServer = TeamFoundation -> + match environVarOrNone "BUILD_SOURCEBRANCHNAME" with + | None -> reraise() + | Some s -> s /// Returns the SHA1 of the current HEAD let getCurrentSHA1 repositoryDir = - if (repositoryDir = "" || repositoryDir = ".") && buildServer = TeamFoundation then - environVar "BUILD_SOURCEVERSION" - else getSHA1 repositoryDir "HEAD" + try + getSHA1 repositoryDir "HEAD" + with _ when (repositoryDir = "" || repositoryDir = ".") && buildServer = TeamFoundation -> + match environVarOrNone "BUILD_SOURCEVERSION" with + | None -> reraise() + | Some s -> s /// Shows the git status let showStatus repositoryDir = showGitCommand repositoryDir "status" @@ -80,11 +85,13 @@ let getLastTag() = (describe "").Split('-') |> Seq.head /// Gets the current hash of the current repository let getCurrentHash() = - if buildServer = TeamFoundation then - environVar "BUILD_SOURCEVERSION" - else + try let tmp = (shortlog "").Split(' ') |> Seq.head |> fun s -> s.Split('m') - if tmp |> Array.length > 2 then tmp.[1].Substring(0,6) else tmp.[0].Substring(0,6) \ No newline at end of file + if tmp |> Array.length > 2 then tmp.[1].Substring(0,6) else tmp.[0].Substring(0,6) + with _ when buildServer = TeamFoundation -> + match environVarOrNone "BUILD_SOURCEVERSION" with + | None -> reraise() + | Some s -> s \ No newline at end of file