Skip to content

Add -nonormalize option to disable normalize function #1762

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

Merged
merged 10 commits into from
Aug 16, 2019
4 changes: 3 additions & 1 deletion docs/build-server-support/build-server-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ GitVersion has support for quite a few build servers out of the box. Currently w
- [TeamCity](build-server/teamcity.md)
- [Team Build (TFS)](build-server/teambuild.md)
- [TFS Build vNext](build-server/tfs-build-vnext.md)

When GitVersion.exe is run with the `/output buildserver` flag instead of outputting Json it will export variables to the current build server.
For instance if you are running in TeamCity after you run `GitVersion /output buildserver` you will have the `%system.GitVersion.SemVer%` available for you to use

When running in MSBuild either from the [MSBuild Task](/usage/msbuild-task) or by using the `/proj myproject.sln` parameter, GitVersion will make the MSBuild variables available in the format `$(GitVersion_SemVer)`.

Standard GitVersion.exe normalize the branches if there is a build server detected. This behavior can be disabled with the `/nonormalize` option.
6 changes: 4 additions & 2 deletions src/GitVersionCore/ExecuteCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ public ExecuteCore(IFileSystem fileSystem, ConfigFileLocator configFileLocator =
gitVersionCache = new GitVersionCache(fileSystem);
}

public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false)
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false, bool noNormalize = false)
{
// Normalise if we are running on build server
var applicableBuildServers = BuildServerList.GetApplicableBuildServers();
var buildServer = applicableBuildServers.FirstOrDefault();
bool normaliseGitDirectory = !noNormalize && (buildServer != null);
var fetch = noFetch || (buildServer != null && buildServer.PreventFetch());
var shouldCleanUpRemotes = buildServer != null && buildServer.ShouldCleanUpRemotes();
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory);
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)), shouldCleanUpRemotes);

gitPreparer.Initialise(normaliseGitDirectory, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)), shouldCleanUpRemotes);
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
var projectRoot = gitPreparer.GetProjectRootDirectory();

Expand Down
7 changes: 7 additions & 0 deletions src/GitVersionExe.Tests/ArgumentParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ public void Nofetch_true_when_defined()
arguments.NoFetch.ShouldBe(true);
}

[Test]
public void Nonormilize_true_when_defined()
{
var arguments = ArgumentParser.ParseArguments("-nonormalize");
arguments.NoNormalize.ShouldBe(true);
}

[Test]
public void Other_arguments_can_be_parsed_before_nofetch()
{
Expand Down
6 changes: 6 additions & 0 deletions src/GitVersionExe/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
continue;
}

if (name.IsSwitch("nonormalize"))
{
arguments.NoNormalize = true;
continue;
}

if (name.IsSwitch("ensureassemblyinfo"))
{
if (value.IsTrue())
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionExe/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public Arguments()
public bool ShowConfig;
public bool NoFetch;
public bool NoCache;
public bool NoNormalize;

public VerbosityLevel Verbosity;

Expand Down
1 change: 1 addition & 0 deletions src/GitVersionExe/HelpWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ path The directory containing .git. If not defined current directory
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig tag-prefix=Foo)
Currently supported config overrides: tag-prefix
/nocache Bypasses the cache, result will not be written to the cache.
/nonormalize Disables normalize step on a build server.

# AssemblyInfo updating
/updateassemblyinfo
Expand Down
3 changes: 2 additions & 1 deletion src/GitVersionExe/SpecifiedArgumentRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
var commitId = arguments.CommitId;
var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
var noCache = arguments.NoCache;
bool noNormalize = arguments.NoNormalize;

var executeCore = new ExecuteCore(fileSystem, arguments.ConfigFileLocator);
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache);
var variables = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache, noNormalize);

if (arguments.Output == OutputType.BuildServer)
{
Expand Down