Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use TFS variables as fallback, fixes #933 #937

Merged
merged 1 commit into from Sep 2, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 25 additions & 18 deletions src/app/FakeLib/Git/Information.fs
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
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