Skip to content

Commit 7c4b172

Browse files
authored
Merge pull request #2146 from gitfool/gh2139
GH2139: GitVersion logging does not include newlines
2 parents 5385735 + 1d16eed commit 7c4b172

File tree

20 files changed

+56
-26
lines changed

20 files changed

+56
-26
lines changed

src/GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void RegexIsRequired()
9696
tag: bugfix";
9797
SetupConfigFileContent(text);
9898
var ex = Should.Throw<GitVersionConfigurationException>(() => configProvider.Provide(repoPath));
99-
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'regex'\n\n" +
99+
ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'regex'{System.Environment.NewLine}" +
100100
"See https://gitversion.net/docs/configuration/ for more info");
101101
}
102102

@@ -111,7 +111,7 @@ public void SourceBranchIsRequired()
111111
tag: bugfix";
112112
SetupConfigFileContent(text);
113113
var ex = Should.Throw<GitVersionConfigurationException>(() => configProvider.Provide(repoPath));
114-
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'source-branches'\n\n" +
114+
ex.Message.ShouldBe($"Branch configuration 'bug' is missing required configuration 'source-branches'{System.Environment.NewLine}" +
115115
"See https://gitversion.net/docs/configuration/ for more info");
116116
}
117117

src/GitVersionCore.Tests/VariableProviderTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public void ShouldLogWarningWhenUsingDefaultInformationalVersionInCustomFormat()
4343
Patch = 3,
4444
};
4545

46+
#pragma warning disable CS0618 // Type or member is obsolete
4647
var propertyName = nameof(SemanticVersionFormatValues.DefaultInformationalVersion);
48+
#pragma warning restore CS0618 // Type or member is obsolete
4749
var config = new TestEffectiveConfiguration(assemblyInformationalFormat: $"{{{propertyName}}}");
4850
variableProvider.GetVariablesFor(semVer, config, false);
4951
logMessages.ShouldContain(message => message.Trim().StartsWith("WARN") && message.Contains(propertyName), 1, $"Expected a warning to be logged when using the variable {propertyName} in a configuration format template");

src/GitVersionCore/BuildServers/TeamCity.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ public override string GetCurrentBranch(bool usingDynamicRepos)
3434
private void WriteBranchEnvVariableWarning()
3535
{
3636
Log.Warning(@"TeamCity doesn't make the current branch available through environmental variables.
37-
3837
Depending on your authentication and transport setup of your git VCS root things may work. In that case, ignore this warning.
39-
4038
In your TeamCity build configuration, add a parameter called `env.Git_Branch` with value %teamcity.build.vcs.branch.<vcsid>%
41-
4239
See https://gitversion.net/docs/build-server-support/build-server/teamcity for more info");
4340
}
4441

src/GitVersionCore/Configuration/BranchConfigurationCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private BranchConfig InheritBranchConfiguration(Branch targetBranch, BranchConfi
145145
}
146146

147147
var branchName = chosenBranch.FriendlyName;
148-
log.Warning(errorMessage + System.Environment.NewLine + System.Environment.NewLine + "Falling back to " + branchName + " branch config");
148+
log.Warning(errorMessage + System.Environment.NewLine + "Falling back to " + branchName + " branch config");
149149

150150
// To prevent infinite loops, make sure that a new branch was chosen.
151151
if (targetBranch.IsSameBranch(chosenBranch))

src/GitVersionCore/Configuration/ConfigExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ public static void Reset(this Config config)
8888
var regex = branchConfig.Value.Regex;
8989
if (regex == null)
9090
{
91-
throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'regex'\n\n" +
91+
throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'regex'{System.Environment.NewLine}" +
9292
"See https://gitversion.net/docs/configuration/ for more info");
9393
}
9494

9595
var sourceBranches = branchConfig.Value.SourceBranches;
9696
if (sourceBranches == null)
9797
{
98-
throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'source-branches'\n\n" +
98+
throw new GitVersionConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'source-branches'{System.Environment.NewLine}" +
9999
"See https://gitversion.net/docs/configuration/ for more info");
100100
}
101101

@@ -189,7 +189,7 @@ public static BranchConfig GetConfigForBranch(this Config config, string branchN
189189
}
190190
catch (InvalidOperationException)
191191
{
192-
var matchingConfigs = String.Concat(matches.Select(m => $"\n - {m.Key}"));
192+
var matchingConfigs = String.Concat(matches.Select(m => $"{System.Environment.NewLine} - {m.Key}"));
193193
var picked = matches
194194
.Select(kvp => kvp.Value)
195195
.First();

src/GitVersionCore/Configuration/Init/SetConfig/ConfigureBranches.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected override string GetPrompt(Config config, string workingDirectory)
4646
return @"Which branch would you like to configure:
4747
4848
0) Go Back
49-
" + string.Join("\r\n", OrderedBranches(config).Select((c, i) => $"{i + 1}) {c.Key}"));
49+
" + string.Join(System.Environment.NewLine, OrderedBranches(config).Select((c, i) => $"{i + 1}) {c.Key}"));
5050
}
5151

5252
private static IOrderedEnumerable<KeyValuePair<string, BranchConfig>> OrderedBranches(Config config)

src/GitVersionCore/Configuration/Init/Wizard/FinishedSetupStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public FinishedSetupStep(IConsole console, IFileSystem fileSystem, ILog log, ICo
1010

1111
protected override string GetPrompt(Config config, string workingDirectory)
1212
{
13-
return "Questions are all done, you can now edit GitVersion's configuration further\r\n" + base.GetPrompt(config, workingDirectory);
13+
return $"Questions are all done, you can now edit GitVersion's configuration further{System.Environment.NewLine}" + base.GetPrompt(config, workingDirectory);
1414
}
1515
}
1616
}

src/GitVersionCore/Configuration/Init/Wizard/GitFlowSetupStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public GitFlowSetupStep(IConsole console, IFileSystem fileSystem, ILog log, ICon
1111

1212
protected override string GetPrompt(Config config, string workingDirectory)
1313
{
14-
return "By default GitVersion will only increment the version of the 'develop' branch every commit, all other branches will increment when tagged\r\n\r\n" +
14+
return $"By default GitVersion will only increment the version of the 'develop' branch every commit, all other branches will increment when tagged{System.Environment.NewLine}{System.Environment.NewLine}" +
1515
base.GetPrompt(config, workingDirectory);
1616
}
1717
}

src/GitVersionCore/Configuration/Init/Wizard/GitHubFlowStep.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public GitHubFlowStep(IConsole console, IFileSystem fileSystem, ILog log, IConfi
1111

1212
protected override string GetPrompt(Config config, string workingDirectory)
1313
{
14-
return "By default GitVersion will only increment the version when tagged\r\n\r\n" + base.GetPrompt(config, workingDirectory);
14+
return $"By default GitVersion will only increment the version when tagged{System.Environment.NewLine}{System.Environment.NewLine}" + base.GetPrompt(config, workingDirectory);
1515
}
1616
}
1717
}

src/GitVersionCore/GitRepoMetadataProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch
218218
if (possibleBranches.Count > 1)
219219
{
220220
var first = possibleBranches.First();
221-
log.Info($"Multiple source branches have been found, picking the first one ({first.Branch.FriendlyName}).\n" +
222-
"This may result in incorrect commit counting.\nOptions were:\n " +
221+
log.Info($"Multiple source branches have been found, picking the first one ({first.Branch.FriendlyName}).{System.Environment.NewLine}" +
222+
$"This may result in incorrect commit counting.{System.Environment.NewLine}Options were:{System.Environment.NewLine}" +
223223
string.Join(", ", possibleBranches.Select(b => b.Branch.FriendlyName)));
224224
return first;
225225
}

src/GitVersionCore/Helpers/GitRepositoryHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void NormalizeGitDirectory(ILog log, IEnvironment environment, str
6262
}
6363

6464
log.Info($"HEAD is detached and points at commit '{headSha}'.");
65-
log.Info(string.Format("Local Refs:\r\n" + string.Join(System.Environment.NewLine, repo.Refs.FromGlob("*").Select(r => $"{r.CanonicalName} ({r.TargetIdentifier})"))));
65+
log.Info($"Local Refs:{System.Environment.NewLine}" + string.Join(System.Environment.NewLine, repo.Refs.FromGlob("*").Select(r => $"{r.CanonicalName} ({r.TargetIdentifier})")));
6666

6767
// In order to decide whether a fake branch is required or not, first check to see if any local branches have the same commit SHA of the head SHA.
6868
// If they do, go ahead and checkout that branch
@@ -203,7 +203,7 @@ private static void CreateFakeBranchPointingAtThePullRequestTip(ILog log, Reposi
203203
GetRemoteTipsUsingUsernamePasswordCredentials(repo, remote, authentication.Username, authentication.Password))
204204
.ToList();
205205

206-
log.Info("Remote Refs:\r\n" + string.Join(System.Environment.NewLine, remoteTips.Select(r => r.CanonicalName)));
206+
log.Info($"Remote Refs:{System.Environment.NewLine}" + string.Join(System.Environment.NewLine, remoteTips.Select(r => r.CanonicalName)));
207207

208208
var headTipSha = repo.Head.Tip.Sha;
209209

src/GitVersionCore/Logging/FileAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void WriteTo(LogLevel level, string message)
3737

3838
private static void WriteLogEntry(string logFilePath, string str)
3939
{
40-
var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}\r\n";
40+
var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}{System.Environment.NewLine}";
4141
File.AppendAllText(logFilePath, contents);
4242
}
4343
}

src/GitVersionCore/Logging/Log.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void Write(Verbosity verbosity, LogLevel level, string format, params obj
4141
appender.WriteTo(level, formattedString);
4242
}
4343

44-
sb.Append(formattedString);
44+
sb.AppendLine(formattedString);
4545
}
4646

4747
public IDisposable IndentLog(string operationDescription)

src/GitVersionCore/OutputVariables/VariableProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ private string CheckAndFormatString<T>(string formatString, T source, IEnvironme
154154

155155
private void WarnIfUsingObsoleteFormatValues(string formatString)
156156
{
157+
#pragma warning disable CS0618 // Type or member is obsolete
157158
var obsoletePropertyName = nameof(SemanticVersionFormatValues.DefaultInformationalVersion);
159+
#pragma warning restore CS0618 // Type or member is obsolete
158160
if (formatString.Contains($"{{{obsoletePropertyName}}}"))
159161
{
160162
log.Write(LogLevel.Warn, $"Use format variable '{nameof(SemanticVersionFormatValues.InformationalVersion)}' instead of '{obsoletePropertyName}' which is obsolete and will be removed in a future release.");

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public void HMeansIsHelp()
5959
public void Exec()
6060
{
6161
var arguments = argumentParser.ParseArguments("-exec rake");
62+
#pragma warning disable CS0612 // Type or member is obsolete
6263
arguments.Exec.ShouldBe("rake");
64+
#pragma warning restore CS0612 // Type or member is obsolete
6365
}
6466

6567
[Test]
@@ -72,15 +74,19 @@ public void ExecWithArgs()
7274
"-execargs",
7375
"clean build"
7476
});
77+
#pragma warning disable CS0612 // Type or member is obsolete
7578
arguments.Exec.ShouldBe("rake");
7679
arguments.ExecArgs.ShouldBe("clean build");
80+
#pragma warning restore CS0612 // Type or member is obsolete
7781
}
7882

7983
[Test]
8084
public void Msbuild()
8185
{
8286
var arguments = argumentParser.ParseArguments("-proj msbuild.proj");
87+
#pragma warning disable CS0612 // Type or member is obsolete
8388
arguments.Proj.ShouldBe("msbuild.proj");
89+
#pragma warning restore CS0612 // Type or member is obsolete
8490
}
8591

8692
[Test]
@@ -93,16 +99,20 @@ public void MsbuildWithArgs()
9399
"-projargs",
94100
"/p:Configuration=Debug /p:Platform=AnyCPU"
95101
});
102+
#pragma warning disable CS0612 // Type or member is obsolete
96103
arguments.Proj.ShouldBe("msbuild.proj");
97104
arguments.ProjArgs.ShouldBe("/p:Configuration=Debug /p:Platform=AnyCPU");
105+
#pragma warning restore CS0612 // Type or member is obsolete
98106
}
99107

100108
[Test]
101109
public void ExecwithTargetdirectory()
102110
{
103111
var arguments = argumentParser.ParseArguments("targetDirectoryPath -exec rake");
104112
arguments.TargetPath.ShouldBe("targetDirectoryPath");
113+
#pragma warning disable CS0612 // Type or member is obsolete
105114
arguments.Exec.ShouldBe("rake");
115+
#pragma warning restore CS0612 // Type or member is obsolete
106116
}
107117

108118
[Test]
@@ -374,23 +384,29 @@ public void OtherArgumentsCanBeParsedAfterNofetch()
374384
{
375385
var arguments = argumentParser.ParseArguments("-nofetch -proj foo.sln");
376386
arguments.NoFetch.ShouldBe(true);
387+
#pragma warning disable CS0612 // Type or member is obsolete
377388
arguments.Proj.ShouldBe("foo.sln");
389+
#pragma warning restore CS0612 // Type or member is obsolete
378390
}
379391

380392
[Test]
381393
public void OtherArgumentsCanBeParsedAfterNonormalize()
382394
{
383395
var arguments = argumentParser.ParseArguments("-nonormalize -proj foo.sln");
384396
arguments.NoNormalize.ShouldBe(true);
397+
#pragma warning disable CS0612 // Type or member is obsolete
385398
arguments.Proj.ShouldBe("foo.sln");
399+
#pragma warning restore CS0612 // Type or member is obsolete
386400
}
387401

388402
[Test]
389403
public void OtherArgumentsCanBeParsedAfterNocache()
390404
{
391405
var arguments = argumentParser.ParseArguments("-nocache -proj foo.sln");
392406
arguments.NoCache.ShouldBe(true);
407+
#pragma warning disable CS0612 // Type or member is obsolete
393408
arguments.Proj.ShouldBe("foo.sln");
409+
#pragma warning restore CS0612 // Type or member is obsolete
394410
}
395411

396412
[TestCase("-nofetch -nonormalize -nocache")]

src/GitVersionExe/ArgumentParser.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,37 @@ public Arguments ParseArguments(string[] commandLineArguments)
149149
if (name.IsSwitch("exec"))
150150
{
151151
EnsureArgumentValueCount(values);
152+
#pragma warning disable CS0612 // Type or member is obsolete
152153
arguments.Exec = value;
154+
#pragma warning restore CS0612 // Type or member is obsolete
153155
continue;
154156
}
155157

156158

157159
if (name.IsSwitch("execargs"))
158160
{
159161
EnsureArgumentValueCount(values);
162+
#pragma warning disable CS0612 // Type or member is obsolete
160163
arguments.ExecArgs = value;
164+
#pragma warning restore CS0612 // Type or member is obsolete
161165
continue;
162166
}
163167

164168
if (name.IsSwitch("proj"))
165169
{
166170
EnsureArgumentValueCount(values);
171+
#pragma warning disable CS0612 // Type or member is obsolete
167172
arguments.Proj = value;
173+
#pragma warning restore CS0612 // Type or member is obsolete
168174
continue;
169175
}
170176

171177
if (name.IsSwitch("projargs"))
172178
{
173179
EnsureArgumentValueCount(values);
180+
#pragma warning disable CS0612 // Type or member is obsolete
174181
arguments.ProjArgs = value;
182+
#pragma warning restore CS0612 // Type or member is obsolete
175183
continue;
176184
}
177185

@@ -238,8 +246,8 @@ public Arguments ParseArguments(string[] commandLineArguments)
238246

239247
if (versionVariable == null)
240248
{
241-
var messageFormat = "{0} requires a valid version variable. Available variables are:\n{1}";
242-
var message = string.Format(messageFormat, name, string.Join(", ", VersionVariables.AvailableVariables.Select(x => string.Concat("'", x, "'"))));
249+
var message = $"{name} requires a valid version variable. Available variables are:{System.Environment.NewLine}" +
250+
string.Join(", ", VersionVariables.AvailableVariables.Select(x => string.Concat("'", x, "'")));
243251
throw new WarningException(message);
244252
}
245253

src/GitVersionExe/ExecCommand.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,19 @@ public void Execute()
8383

8484
private static bool RunMsBuildIfNeeded(Arguments args, string workingDirectory, VersionVariables variables, ILog log)
8585
{
86+
#pragma warning disable CS0612 // Type or member is obsolete
8687
if (string.IsNullOrEmpty(args.Proj)) return false;
8788

8889
args.Exec = "dotnet";
8990
args.ExecArgs = $"msbuild \"{args.Proj}\" {args.ProjArgs}";
91+
#pragma warning restore CS0612 // Type or member is obsolete
9092

9193
return RunExecCommandIfNeeded(args, workingDirectory, variables, log);
9294
}
9395

9496
private static bool RunExecCommandIfNeeded(Arguments args, string workingDirectory, VersionVariables variables, ILog log)
9597
{
98+
#pragma warning disable CS0612 // Type or member is obsolete
9699
if (string.IsNullOrEmpty(args.Exec)) return false;
97100

98101
log.Info($"Launching {args.Exec} {args.ExecArgs}");
@@ -103,6 +106,7 @@ private static bool RunExecCommandIfNeeded(Arguments args, string workingDirecto
103106

104107
if (results != 0)
105108
throw new WarningException($"Execution of {args.Exec} failed, non-zero return code");
109+
#pragma warning restore CS0612 // Type or member is obsolete
106110

107111
return true;
108112
}

src/GitVersionExe/GitVersionExecutor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ private int VerifyArgumentsAndRun(Arguments arguments)
7676
arguments.Output.Add(OutputType.BuildServer);
7777
}
7878

79+
#pragma warning disable CS0612 // Type or member is obsolete
7980
if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec))
81+
#pragma warning restore CS0612 // Type or member is obsolete
8082
{
8183
arguments.Output.Add(OutputType.BuildServer);
8284
}
@@ -118,18 +120,17 @@ private int VerifyArgumentsAndRun(Arguments arguments)
118120
}
119121
catch (WarningException exception)
120122
{
121-
var error = $"An error occurred:\r\n{exception.Message}";
123+
var error = $"An error occurred:{System.Environment.NewLine}{exception.Message}";
122124
log.Warning(error);
123125
return 1;
124126
}
125127
catch (Exception exception)
126128
{
127-
var error = $"An unexpected error occurred:\r\n{exception}";
129+
var error = $"An unexpected error occurred:{System.Environment.NewLine}{exception}";
128130
log.Error(error);
129131

130132
if (arguments == null) return 1;
131133

132-
log.Info(string.Empty);
133134
log.Info("Attempting to show the current git graph (please include in issue): ");
134135
log.Info("Showing max of 100 commits");
135136

src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
11-
<PackageReference Include="Microsoft.Build" Version="16.4.0" />
11+
<PackageReference Include="Microsoft.Build" Version="16.4.0" NoWarn="NU1701" />
1212
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.4.0" />
1313
</ItemGroup>
1414

src/GitVersionTask/MsBuildAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void WriteTo(LogLevel level, string message)
2929

3030
private void WriteLogEntry(LogLevel level, string str)
3131
{
32-
var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}\r\n";
32+
var contents = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}\t\t{str}{System.Environment.NewLine}";
3333
switch (level)
3434
{
3535
case LogLevel.None:

0 commit comments

Comments
 (0)