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
}

GitVersionExe/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int Run()
8888

8989
foreach (var buildServer in applicableBuildServers)
9090
{
91-
buildServer.PerformPreProcessingSteps(gitDirectory);
91+
buildServer.PerformPreProcessingSteps(gitDirectory, arguments.NoFetch);
9292
}
9393
VersionVariables variables;
9494
var versionFinder = new GitVersionFinder();

GitVersionTask.Tests/VersionAndBranchFinderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void ShouldBeAbleGetVersionFromGitDir()
2020
}
2121

2222
Tuple<CachedVersion, GitVersionContext> versionAndBranch;
23-
VersionAndBranchFinder.TryGetVersion(ASBMTestRepoWorkingDirPath, out versionAndBranch, new Config());
23+
VersionAndBranchFinder.TryGetVersion(ASBMTestRepoWorkingDirPath, out versionAndBranch, new Config(), false);
2424
Assert.IsNotNull(versionAndBranch);
2525
}
2626
}

GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class UpdateAssemblyInfo : Task
2525
[Output]
2626
public string AssemblyInfoTempFilePath { get; set; }
2727

28+
public bool NoFetch { get; set; }
29+
2830
TaskLogger logger;
2931
IFileSystem fileSystem;
3032

@@ -73,7 +75,7 @@ public void InnerExecute()
7375
var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);
7476

7577
Tuple<CachedVersion, GitVersionContext> semanticVersion;
76-
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, configuration))
78+
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out semanticVersion, configuration, NoFetch))
7779
{
7880
return;
7981
}

GitVersionTask/GetVersion.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class GetVersion : Task
1212
[Required]
1313
public string SolutionDirectory { get; set; }
1414

15+
public bool NoFetch { get; set; }
16+
1517
[Output]
1618
public string Major { get; set; }
1719

@@ -85,7 +87,7 @@ public override bool Execute()
8587
var gitDirectory = GitDirFinder.TreeWalkForGitDir(SolutionDirectory);
8688
var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);
8789

88-
if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration))
90+
if (VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionAndBranch, configuration, NoFetch))
8991
{
9092
var thisType = typeof(GetVersion);
9193
var cachedVersion = versionAndBranch.Item1;

GitVersionTask/VersionAndBranchFinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public static class VersionAndBranchFinder
66
{
77
static List<string> processedDirectories = new List<string>();
8-
public static bool TryGetVersion(string directory, out Tuple<CachedVersion, GitVersionContext> versionAndBranch, Config configuration)
8+
public static bool TryGetVersion(string directory, out Tuple<CachedVersion, GitVersionContext> versionAndBranch, Config configuration, bool noFetch)
99
{
1010
var gitDirectory = GitDirFinder.TreeWalkForGitDir(directory);
1111

@@ -28,7 +28,7 @@ public static bool TryGetVersion(string directory, out Tuple<CachedVersion, GitV
2828
foreach (var buildServer in BuildServerList.GetApplicableBuildServers(authentication))
2929
{
3030
Logger.WriteInfo(string.Format("Executing PerformPreProcessingSteps for '{0}'.", buildServer.GetType().Name));
31-
buildServer.PerformPreProcessingSteps(gitDirectory);
31+
buildServer.PerformPreProcessingSteps(gitDirectory, noFetch);
3232
}
3333
}
3434
versionAndBranch = VersionCache.GetVersion(gitDirectory, configuration);

GitVersionTask/WriteVersionInfoToBuildLog.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class WriteVersionInfoToBuildLog : Task
1313
[Required]
1414
public string SolutionDirectory { get; set; }
1515

16+
public bool NoFetch { get; set; }
17+
1618
TaskLogger logger;
1719
IFileSystem fileSystem;
1820

@@ -52,7 +54,7 @@ public void InnerExecute()
5254
Tuple<CachedVersion, GitVersionContext> result;
5355
var gitDirectory = GitDirFinder.TreeWalkForGitDir(SolutionDirectory);
5456
var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);
55-
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, configuration))
57+
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, configuration, NoFetch))
5658
{
5759
return;
5860
}

0 commit comments

Comments
 (0)