Skip to content

Commit 9379111

Browse files
David Korfkamparturcic
authored andcommitted
fix issue 2439
- checks buildagent to set NoFetch argument when invoked without any command line arguments
1 parent ac47ed9 commit 9379111

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using GitVersion;
3+
using GitVersion.OutputVariables;
4+
using GitVersionCore.Tests.Helpers;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using NUnit.Framework;
7+
using Shouldly;
8+
9+
namespace GitVersionExe.Tests
10+
{
11+
[TestFixture]
12+
public class ArgumentParserOnBuildServerTests : TestBase
13+
{
14+
private IArgumentParser argumentParser;
15+
16+
[SetUp]
17+
public void SetUp()
18+
{
19+
var sp = ConfigureServices(services =>
20+
{
21+
services.AddSingleton<IArgumentParser, ArgumentParser>();
22+
services.AddSingleton<IGlobbingResolver, GlobbingResolver>();
23+
services.AddSingleton<ICurrentBuildAgent, MockBuildAgent>();
24+
});
25+
argumentParser = sp.GetService<IArgumentParser>();
26+
}
27+
28+
[Test]
29+
public void EmptyOnFetchDisabledBuildServerMeansNoFetchIsTrue()
30+
{
31+
var arguments = argumentParser.ParseArguments("");
32+
arguments.NoFetch.ShouldBe(true);
33+
}
34+
35+
private class MockBuildAgent : ICurrentBuildAgent
36+
{
37+
public bool CanApplyToCurrentContext()
38+
{
39+
throw new NotImplementedException();
40+
}
41+
42+
public void WriteIntegration(Action<string> writer, VersionVariables variables, bool updateBuildNumber = true)
43+
{
44+
throw new NotImplementedException();
45+
}
46+
47+
public string GetCurrentBranch(bool usingDynamicRepos)
48+
{
49+
throw new NotImplementedException();
50+
}
51+
52+
public bool PreventFetch()
53+
{
54+
return true;
55+
}
56+
57+
public bool ShouldCleanUpRemotes()
58+
{
59+
throw new NotImplementedException();
60+
}
61+
}
62+
}
63+
}

src/GitVersionExe/ArgumentParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public Arguments ParseArguments(string[] commandLineArguments)
4949

5050
AddAuthentication(args);
5151

52+
args.NoFetch = buildAgent != null && buildAgent.PreventFetch();
53+
5254
return args;
5355
}
5456

0 commit comments

Comments
 (0)