Skip to content

Commit ee25e98

Browse files
committed
Merge branch 'master' into loadLibGitFromFiles
2 parents 3796e35 + f39188a commit ee25e98

File tree

137 files changed

+575
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+575
-454
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ForSample/
3939
*NugetTaskBuild*
4040
*NugetRefBuild*
4141
*NugetExeBuild*
42+
*GitVersionVsoTaskBuild*
4243
*GemBuild*
4344

4445
# Visual Studio profiler

appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ build_script:
2424
- cmd: 7z a "GitVersion_%GitVersion_NuGetVersion%.zip" .\build\NuGetCommandLineBuild\Tools\*.*
2525
- cmd: appveyor PushArtifact "GitVersion_%GitVersion_NuGetVersion%.zip"
2626

27+
- ps: .\build\Update-GitVersionVsoTaskVersion.ps1 .\build\GitVersionVsoTaskBuild\task.json $env:GitVersion_Major $env:GitVersion_Minor $env:GitVersion_Patch
28+
- cmd: 7z a "GitVersionVsoBuildTask_%GitVersion_NuGetVersion%.zip" .\build\GitVersionVsoTaskBuild\*.*
29+
- cmd: appveyor PushArtifact "GitVersionVsoBuildTask_%GitVersion_NuGetVersion%.zip"
30+
2731
test_script:
2832
- nunit-console "src\GitVersionTask.Tests\bin\%CONFIGURATION%\GitVersionTask.Tests.dll" "src\GitVersionExe.Tests\bin\%CONFIGURATION%\GitVersionExe.Tests.dll" "src\GitVersionCore.Tests\bin\%CONFIGURATION%\GitVersionCore.Tests.dll" /noshadow
2933

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
param (
2+
[string] $filePath,
3+
[string] $major,
4+
[string] $minor,
5+
[string] $patch
6+
)
7+
8+
# Get the task.json as a powershell object
9+
$task = Get-Content -Raw -Path $filePath | ConvertFrom-Json
10+
11+
$task.version.Major = $major
12+
$task.version.Minor = $minor
13+
$task.version.Patch = $patch
14+
15+
# get this as a string again
16+
17+
ConvertTo-Json $task | Set-Content -Path $filePath

docs/build-server-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ When running in MSBuild either from the MSBuild Task or by using the `/proj mypr
2020
- [Continua CI](more-info/build-server-setup/continua.md))
2121
- [Team Build (TFS)](more-info/build-server-setup/teambuild.md)
2222
- [TFS Build vNext](more-info/build-server-setup/tfs-build-vnext.md)
23+
- [Octopus Deploy](more-info/build-server-setup/octopus-deploy.md)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Visual Studio Online (Build vNext) Setup
2+
## Basic Usage
3+
In [Visual Studio Online](https://www.visualstudio.com/) build vNext (the web based build system) you can add GitVersion as a Build Step. This requires a one-time setup to import the GitVersion task into your VSO instance.
4+
5+
## Installing/updating the VSO Build Step
6+
1. Install the `tfx` command line tool as shown [here](https://github.com/Microsoft/tfs-cli/blob/master/docs/buildtasks.md)
7+
2. Download the GitVersion VSO extension from the latest release on the [GitVersion releases page](https://github.com/GitTools/GitVersion/releases) and unzip.
8+
3. Run `tfx login` if you haven't yet, make sure to use `https://<server>.visualstudio.com/DefaultCollection` as the URL and provide a Personal Access Token
9+
4. From the directory outside of where you unzipped the task, run `tfx upload .\GitVersionVsoTask` where GitVersionVsoTask is the directory containing the files.
10+
5. It should successfully install
11+
12+
## Using the GitVersion VSO Build Step
13+
From a VSO vNext Build Definition, select "Add a Step" and then in the Build category, choose GitVersion and Click Add. You'll probably want to drag the task to be at or near the top to ensure it executes before your other build steps.
14+
15+
If you want the GitVersionTask to update AssemblyInfo files, check the box in the task configuration. For advanced usage, you can pass additional options to the GitVersion exe in the Additional arguments section.
16+
17+
## Using the GitVersion Variables
18+
GitVersion writes build parameters into VSO, so they will automatically be passed to your build scripts to use. It also writes GITVERSION_* environment variables that are available for any subsequent build step.
19+
20+
Note that due to [current limitations in VSO](https://github.com/Microsoft/vso-agent-tasks/issues/380) it's currently not possible to set the build version inside of VSO to one of the GITVERSION_* variables.
21+
22+
## Running inside Visual Studio Online
23+
* We output the individual values of the GitVersion version as the build parameter: `GitVersion.*` (Eg: `GitVersion.Major`) if you need access to them in your build script
24+
25+
### NuGet in VSO
26+
* If you use a command script to build your NuPkg, use `%GITVERSION_NUGETVERSION%` as the version parameter: `nuget.exe pack path\to\my.nuspec -version %GITVERSION_NUGETVERSION%`

src/GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public override string[] GenerateSetParameterMessage(string name, string value)
4444
{
4545
return new string[0];
4646
}
47+
48+
public override string GetCurrentBranch()
49+
{
50+
throw new NotImplementedException();
51+
}
4752
}
4853
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using GitVersion;
2+
using NUnit.Framework;
3+
using Shouldly;
4+
5+
[TestFixture]
6+
public class VsoAgentTests
7+
{
8+
[Test]
9+
public void Develop_branch()
10+
{
11+
var versionBuilder = new VsoAgent();
12+
var vsVersion = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4");
13+
// Assert.AreEqual("##vso[task.setvariable variable=GitBuildNumber;]0.0.0-Unstable4", vsVersion);
14+
15+
vsVersion.ShouldBe(null);
16+
}
17+
18+
[Test]
19+
public void EscapeValues()
20+
{
21+
var versionBuilder = new VsoAgent();
22+
var vsVersion = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
23+
24+
vsVersion[0].ShouldBe("##vso[task.setvariable variable=GitVersion.Foo;]0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
25+
}
26+
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using GitVersion;
2+
using LibGit2Sharp;
3+
4+
public class LocalRepositoryFixture : RepositoryFixtureBase
5+
{
6+
public LocalRepositoryFixture(Config configuration, IRepository repository) : base(configuration, repository)
7+
{
8+
}
9+
}
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
using System;
2-
3-
using GitVersion;
4-
using LibGit2Sharp;
2+
using GitVersion;
3+
using LibGit2Sharp;
54

65
public class RemoteRepositoryFixture : RepositoryFixtureBase
76
{
8-
public string LocalRepositoryPath;
9-
public IRepository LocalRepository;
10-
117
public RemoteRepositoryFixture(Func<string, IRepository> builder, Config configuration)
128
: base(builder, configuration)
139
{
14-
CloneRepository();
10+
CreateLocalRepository();
1511
}
1612

1713
public RemoteRepositoryFixture(Config configuration)
1814
: base(CreateNewRepository, configuration)
1915
{
20-
CloneRepository();
16+
CreateLocalRepository();
2117
}
2218

19+
public LocalRepositoryFixture LocalRepositoryFixture { get; private set; }
20+
21+
2322
/// <summary>
2423
/// Simulates running on build server
2524
/// </summary>
2625
public void InitialiseRepo()
2726
{
28-
new GitPreparer(null, null, new Authentication(), null, false, LocalRepositoryPath).Initialise(true);
27+
new GitPreparer(null, null, new Authentication(), null, false, LocalRepositoryFixture.RepositoryPath).Initialise(true, null);
2928
}
3029

3130
static IRepository CreateNewRepository(string path)
@@ -38,25 +37,14 @@ static IRepository CreateNewRepository(string path)
3837
return repo;
3938
}
4039

41-
void CloneRepository()
40+
void CreateLocalRepository()
4241
{
43-
LocalRepositoryPath = PathHelper.GetTempPath();
44-
LibGit2Sharp.Repository.Clone(RepositoryPath, LocalRepositoryPath);
45-
LocalRepository = new Repository(LocalRepositoryPath);
42+
LocalRepositoryFixture = CloneRepository();
4643
}
4744

4845
public override void Dispose()
4946
{
50-
LocalRepository.Dispose();
51-
try
52-
{
53-
DirectoryHelper.DeleteDirectory(LocalRepositoryPath);
54-
}
55-
catch (Exception e)
56-
{
57-
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message);
58-
}
59-
47+
LocalRepositoryFixture.Dispose();
6048
base.Dispose();
6149
}
6250
}

src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@
99
public abstract class RepositoryFixtureBase : IDisposable
1010
{
1111
Dictionary<string, string> participants = new Dictionary<string, string>();
12-
public string RepositoryPath;
13-
public IRepository Repository;
1412
Config configuration;
1513
StringBuilder diagramBuilder;
1614

1715
protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder, Config configuration)
16+
: this(configuration, repoBuilder(PathHelper.GetTempPath()))
17+
{
18+
}
19+
20+
protected RepositoryFixtureBase(Config configuration, IRepository repository)
1821
{
1922
ConfigurationProvider.ApplyDefaultsTo(configuration);
2023
diagramBuilder = new StringBuilder();
2124
diagramBuilder.AppendLine("@startuml");
2225
this.configuration = configuration;
23-
RepositoryPath = PathHelper.GetTempPath();
24-
Repository = repoBuilder(RepositoryPath);
26+
Repository = repository;
2527
Repository.Config.Set("user.name", "Test");
2628
Repository.Config.Set("user.email", "[email protected]");
2729
IsForTrackedBranchOnly = true;
2830
}
2931

3032
public bool IsForTrackedBranchOnly { private get; set; }
33+
public IRepository Repository { get; private set; }
34+
public string RepositoryPath { get { return Repository.Info.WorkingDirectory.TrimEnd('\\'); } }
3135

3236
public void Checkout(string branch)
3337
{
@@ -190,4 +194,11 @@ public virtual void Dispose()
190194
Trace.WriteLine(string.Empty);
191195
Trace.WriteLine(diagramBuilder.ToString());
192196
}
197+
198+
public LocalRepositoryFixture CloneRepository(Config config = null)
199+
{
200+
var localPath = PathHelper.GetTempPath();
201+
LibGit2Sharp.Repository.Clone(RepositoryPath, localPath);
202+
return new LocalRepositoryFixture(config ?? new Config(), new Repository(localPath));
203+
}
193204
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
namespace GitVersionCore.Tests
2+
{
3+
using GitVersion;
4+
using LibGit2Sharp;
5+
using NUnit.Framework;
6+
using Shouldly;
7+
8+
public class GitHelperTests
9+
{
10+
[Test]
11+
public void NormalisationOfPullRequestsWithFetch()
12+
{
13+
using (var fixture = new EmptyRepositoryFixture(new Config()))
14+
{
15+
fixture.Repository.MakeACommit();
16+
17+
fixture.Repository.CreateBranch("feature/foo").Checkout();
18+
fixture.Repository.MakeACommit();
19+
var commit = fixture.Repository.CreatePullRequestRef("feature/foo", "master", prNumber: 3);
20+
using (var localFixture = fixture.CloneRepository())
21+
{
22+
localFixture.Checkout(commit.Sha);
23+
GitHelper.NormalizeGitDirectory(localFixture.RepositoryPath, new Authentication(), noFetch: false, currentBranch: string.Empty);
24+
25+
var normalisedPullBranch = localFixture.Repository.FindBranch("pull/3/merge");
26+
normalisedPullBranch.ShouldNotBe(null);
27+
}
28+
}
29+
}
30+
31+
[Test]
32+
public void NormalisationOfPullRequestsWithoutFetch()
33+
{
34+
using (var fixture = new EmptyRepositoryFixture(new Config()))
35+
{
36+
fixture.Repository.MakeACommit();
37+
38+
fixture.Repository.CreateBranch("feature/foo").Checkout();
39+
fixture.Repository.MakeACommit();
40+
var commit = fixture.Repository.CreatePullRequestRef("feature/foo", "master", prNumber: 3, allowFastFowardMerge: true);
41+
using (var localFixture = fixture.CloneRepository())
42+
{
43+
localFixture.Checkout(commit.Sha);
44+
GitHelper.NormalizeGitDirectory(localFixture.RepositoryPath, new Authentication(), noFetch: true, currentBranch: "refs/pull/3/merge");
45+
46+
var normalisedPullBranch = localFixture.Repository.FindBranch("pull/3/merge");
47+
normalisedPullBranch.ShouldNotBe(null);
48+
}
49+
}
50+
}
51+
52+
[Test]
53+
public void UpdatesLocalBranchesWhen()
54+
{
55+
using (var fixture = new EmptyRepositoryFixture(new Config()))
56+
{
57+
fixture.Repository.MakeACommit();
58+
59+
fixture.Repository.CreateBranch("feature/foo").Checkout();
60+
fixture.Repository.MakeACommit();
61+
using (var localFixture = fixture.CloneRepository())
62+
{
63+
localFixture.Checkout("feature/foo");
64+
// Advance remote
65+
var advancedCommit = fixture.Repository.MakeACommit();
66+
GitHelper.NormalizeGitDirectory(localFixture.RepositoryPath, new Authentication(), noFetch: false, currentBranch: null);
67+
68+
var normalisedBranch = localFixture.Repository.FindBranch("feature/foo");
69+
normalisedBranch.ShouldNotBe(null);
70+
normalisedBranch.Tip.Sha.ShouldBe(advancedCommit.Sha);
71+
}
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)