Skip to content

Commit 92231b6

Browse files
author
Sebastian Nemeth
committed
Added support for -nofetch command line argument and 'NoFetch' MSBuild Task parameter, to suppress fetching from remotes during execution.
1 parent 5415748 commit 92231b6

File tree

16 files changed

+50
-18
lines changed

16 files changed

+50
-18
lines changed

GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override bool CanApplyToCurrentContext()
3535
throw new NotImplementedException();
3636
}
3737

38-
public override void PerformPreProcessingSteps(string gitDirectory)
38+
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
3939
{
4040
throw new NotImplementedException();
4141
}

GitVersionCore/BuildServers/AppVeyor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ public override bool CanApplyToCurrentContext()
1818
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPVEYOR"));
1919
}
2020

21-
public override void PerformPreProcessingSteps(string gitDirectory)
21+
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
2222
{
2323
if (string.IsNullOrEmpty(gitDirectory))
2424
{
2525
throw new WarningException("Failed to find .git directory on agent.");
2626
}
2727

28-
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
28+
if (!noFetch)
29+
{
30+
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
31+
}
2932
}
3033

3134
public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)

GitVersionCore/BuildServers/BuildServerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public abstract class BuildServerBase : IBuildServer
66
{
77
public abstract bool CanApplyToCurrentContext();
8-
public abstract void PerformPreProcessingSteps(string gitDirectory);
8+
public abstract void PerformPreProcessingSteps(string gitDirectory, bool noFetch);
99
public abstract string GenerateSetVersionMessage(string versionToUseForBuildNumber);
1010
public abstract string[] GenerateSetParameterMessage(string name, string value);
1111

GitVersionCore/BuildServers/ContinuaCi.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ public override bool CanApplyToCurrentContext()
2828
return false;
2929
}
3030

31-
public override void PerformPreProcessingSteps(string gitDirectory)
31+
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
3232
{
3333
if (string.IsNullOrEmpty(gitDirectory))
3434
{
3535
throw new WarningException("Failed to find .git directory on agent");
3636
}
3737

38-
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
38+
if (!noFetch)
39+
{
40+
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
41+
}
3942
}
4043

4144
public override string[] GenerateSetParameterMessage(string name, string value)

GitVersionCore/BuildServers/IBuildServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public interface IBuildServer
66
{
77
bool CanApplyToCurrentContext();
8-
void PerformPreProcessingSteps(string gitDirectory);
8+
void PerformPreProcessingSteps(string gitDirectory, bool noFetch);
99
string GenerateSetVersionMessage(string versionToUseForBuildNumber);
1010
string[] GenerateSetParameterMessage(string name, string value);
1111

GitVersionCore/BuildServers/MyGet.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ public override bool CanApplyToCurrentContext()
2020
&& buildRunner.Equals("MyGet", StringComparison.InvariantCultureIgnoreCase);
2121
}
2222

23-
public override void PerformPreProcessingSteps(string gitDirectory)
23+
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
2424
{
2525
if (string.IsNullOrEmpty(gitDirectory))
2626
{
2727
throw new WarningException("Failed to find .git directory on agent.");
2828
}
2929

30-
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
30+
if (!noFetch)
31+
{
32+
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
33+
}
3134
}
3235

3336
public override string[] GenerateSetParameterMessage(string name, string value)

GitVersionCore/BuildServers/TeamCity.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ public override bool CanApplyToCurrentContext()
1616
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION"));
1717
}
1818

19-
public override void PerformPreProcessingSteps(string gitDirectory)
19+
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
2020
{
2121
if (string.IsNullOrEmpty(gitDirectory))
2222
{
2323
throw new WarningException("Failed to find .git directory on agent. Please make sure agent checkout mode is enabled for you VCS roots - http://confluence.jetbrains.com/display/TCD8/VCS+Checkout+Mode");
2424
}
2525

26-
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
26+
if (!noFetch)
27+
{
28+
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
29+
}
2730
}
2831

2932
public override string[] GenerateSetParameterMessage(string name, string value)

GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,11 @@ public void can_log_to_console()
211211
var arguments = ArgumentParser.ParseArguments("-l console -proj foo.sln");
212212
arguments.LogFilePath.ShouldBe("console");
213213
}
214+
215+
[Test]
216+
public void nofetch_true_when_defined()
217+
{
218+
var arguments = ArgumentParser.ParseArguments("-nofetch");
219+
arguments.NoFetch = true;
220+
}
214221
}

GitVersionExe/ArgumentParser.cs

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

205+
if (IsSwitch("nofetch", name))
206+
{
207+
arguments.NoFetch = true;
208+
continue;
209+
}
210+
205211
throw new WarningException(string.Format("Could not parse command line parameter '{0}'.", name));
206212
}
207213

GitVersionExe/Arguments.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ public Arguments()
3333
public string UpdateAssemblyInfoFileName;
3434

3535
public bool ShowConfig;
36+
public bool NoFetch { get; set; }
3637
}
3738
}

0 commit comments

Comments
 (0)