Skip to content

Commit

Permalink
Merge pull request #612 from Philo/feature/dynamic-repo-branch-teamcity
Browse files Browse the repository at this point in the history
re #611 - Ensures branch with dynamic repositories and buildserver
  • Loading branch information
JakeGinnivan committed Aug 26, 2015
2 parents 29f2362 + 628cb99 commit 93e36a9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 25 deletions.
5 changes: 0 additions & 5 deletions src/GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,5 @@ public override string[] GenerateSetParameterMessage(string name, string value)
{
return new string[0];
}

public override string GetCurrentBranch()
{
throw new NotImplementedException();
}
}
}
5 changes: 0 additions & 5 deletions src/GitVersionCore/BuildServers/AppVeyor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,5 @@ public override string[] GenerateSetParameterMessage(string name, string value)
string.Format("Adding Environment Variable. name='GitVersion_{0}' value='{1}']", name, value)
};
}

public override string GetCurrentBranch()
{
return null;
}
}
}
6 changes: 5 additions & 1 deletion src/GitVersionCore/BuildServers/BuildServerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ public abstract class BuildServerBase : IBuildServer
public abstract bool CanApplyToCurrentContext();
public abstract string GenerateSetVersionMessage(string versionToUseForBuildNumber);
public abstract string[] GenerateSetParameterMessage(string name, string value);
public abstract string GetCurrentBranch();

public virtual string GetCurrentBranch()
{
return null;
}

public virtual void WriteIntegration(Action<string> writer, VersionVariables variables)
{
Expand Down
2 changes: 0 additions & 2 deletions src/GitVersionCore/BuildServers/ContinuaCi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public override string[] GenerateSetParameterMessage(string name, string value)
};
}

public override string GetCurrentBranch() { return string.Empty; }

public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
{
return string.Format("@@continua[setBuildVersion value='{0}']", versionToUseForBuildNumber);
Expand Down
2 changes: 0 additions & 2 deletions src/GitVersionCore/BuildServers/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public override string GenerateSetVersionMessage(string versionToUseForBuildNumb
return versionToUseForBuildNumber;
}

public override string GetCurrentBranch() { return string.Empty; }

public override string[] GenerateSetParameterMessage(string name, string value)
{
return new[]
Expand Down
2 changes: 0 additions & 2 deletions src/GitVersionCore/BuildServers/MyGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public override bool CanApplyToCurrentContext()
&& buildRunner.Equals("MyGet", StringComparison.InvariantCultureIgnoreCase);
}

public override string GetCurrentBranch() { return string.Empty; }

public override string[] GenerateSetParameterMessage(string name, string value)
{
var messages = new List<string>
Expand Down
2 changes: 0 additions & 2 deletions src/GitVersionCore/BuildServers/TeamCity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public override bool CanApplyToCurrentContext()
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION"));
}

public override string GetCurrentBranch() { return string.Empty; }

public override string[] GenerateSetParameterMessage(string name, string value)
{
return new[]
Expand Down
19 changes: 13 additions & 6 deletions src/GitVersionCore/ExecuteCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ public static VersionVariables ExecuteGitVersion(IFileSystem fileSystem, string
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, noFetch, workingDirectory);
var applicableBuildServers = BuildServerList.GetApplicableBuildServers();
var buildServer = applicableBuildServers.FirstOrDefault();
var currentBranch = buildServer == null ? null : buildServer.GetCurrentBranch();
if (!string.IsNullOrEmpty(currentBranch))
{
Logger.WriteInfo("Branch from build environment: " + currentBranch);
}
gitPreparer.Initialise(buildServer != null, currentBranch ?? targetBranch);

gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch));

var dotGitDirectory = gitPreparer.GetDotGitDirectory();
var projectRoot = gitPreparer.GetProjectRootDirectory();
Logger.WriteInfo(string.Format("Project root is: " + projectRoot));
Expand All @@ -40,5 +37,15 @@ public static VersionVariables ExecuteGitVersion(IFileSystem fileSystem, string

return variables;
}

private static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch)
{
if (buildServer == null) return targetBranch;

var currentBranch = buildServer.GetCurrentBranch() ?? targetBranch;
Logger.WriteInfo("Branch from build environment: " + currentBranch);

return currentBranch;
}
}
}

0 comments on commit 93e36a9

Please sign in to comment.