Skip to content

Commit

Permalink
re #611 - current branch resolution simplification
Browse files Browse the repository at this point in the history
Updates the BuildServerBase to provide a default implementation of
GetCurrentBranch() that returns null, derived build servers can override
if needed, this simplifies the resolution of the current branch name
within ExecuteCore
  • Loading branch information
Philo committed Aug 26, 2015
1 parent 5ae5681 commit 628cb99
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 26 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: 12 additions & 7 deletions src/GitVersionCore/ExecuteCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +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();

currentBranch = string.IsNullOrWhiteSpace(currentBranch) ? targetBranch : currentBranch;
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 @@ -42,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 628cb99

Please sign in to comment.