Skip to content

Commit f953257

Browse files
authored
Merge pull request #1762 from Bankers88/feature/noNormalize
Add -nonormalize option to disable normalize function
2 parents c014917 + 9c2d408 commit f953257

File tree

7 files changed

+24
-4
lines changed

7 files changed

+24
-4
lines changed

docs/build-server-support/build-server-support.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ GitVersion has support for quite a few build servers out of the box. Currently w
1111
- [TeamCity](build-server/teamcity.md)
1212
- [Team Build (TFS)](build-server/teambuild.md)
1313
- [TFS Build vNext](build-server/tfs-build-vnext.md)
14-
14+
1515
When GitVersion.exe is run with the `/output buildserver` flag instead of outputting Json it will export variables to the current build server.
1616
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
1717

1818
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)`.
19+
20+
Standard GitVersion.exe normalize the branches if there is a build server detected. This behavior can be disabled with the `/nonormalize` option.

src/GitVersionCore/ExecuteCore.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ public ExecuteCore(IFileSystem fileSystem, ConfigFileLocator configFileLocator =
1818
gitVersionCache = new GitVersionCache(fileSystem);
1919
}
2020

21-
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, Config overrideConfig = null, bool noCache = false)
21+
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)
2222
{
2323
// Normalise if we are running on build server
2424
var applicableBuildServers = BuildServerList.GetApplicableBuildServers();
2525
var buildServer = applicableBuildServers.FirstOrDefault();
26+
bool normaliseGitDirectory = !noNormalize && (buildServer != null);
2627
var fetch = noFetch || (buildServer != null && buildServer.PreventFetch());
2728
var shouldCleanUpRemotes = buildServer != null && buildServer.ShouldCleanUpRemotes();
2829
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory);
29-
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)), shouldCleanUpRemotes);
30+
31+
gitPreparer.Initialise(normaliseGitDirectory, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)), shouldCleanUpRemotes);
3032
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
3133
var projectRoot = gitPreparer.GetProjectRootDirectory();
3234

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ public void Nofetch_true_when_defined()
300300
arguments.NoFetch.ShouldBe(true);
301301
}
302302

303+
[Test]
304+
public void Nonormilize_true_when_defined()
305+
{
306+
var arguments = ArgumentParser.ParseArguments("-nonormalize");
307+
arguments.NoNormalize.ShouldBe(true);
308+
}
309+
303310
[Test]
304311
public void Other_arguments_can_be_parsed_before_nofetch()
305312
{

src/GitVersionExe/ArgumentParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
267267
continue;
268268
}
269269

270+
if (name.IsSwitch("nonormalize"))
271+
{
272+
arguments.NoNormalize = true;
273+
continue;
274+
}
275+
270276
if (name.IsSwitch("ensureassemblyinfo"))
271277
{
272278
if (value.IsTrue())

src/GitVersionExe/Arguments.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public Arguments()
4949
public bool ShowConfig;
5050
public bool NoFetch;
5151
public bool NoCache;
52+
public bool NoNormalize;
5253

5354
public VerbosityLevel Verbosity;
5455

src/GitVersionExe/HelpWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ path The directory containing .git. If not defined current directory
3838
/overrideconfig Overrides GitVersion config values inline (semicolon-separated key value pairs e.g. /overrideconfig tag-prefix=Foo)
3939
Currently supported config overrides: tag-prefix
4040
/nocache Bypasses the cache, result will not be written to the cache.
41+
/nonormalize Disables normalize step on a build server.
4142
4243
# AssemblyInfo updating
4344
/updateassemblyinfo

src/GitVersionExe/SpecifiedArgumentRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ public static void Run(Arguments arguments, IFileSystem fileSystem)
4141
var commitId = arguments.CommitId;
4242
var overrideConfig = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
4343
var noCache = arguments.NoCache;
44+
bool noNormalize = arguments.NoNormalize;
4445

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

4849
if (arguments.Output == OutputType.BuildServer)
4950
{

0 commit comments

Comments
 (0)