Skip to content

Dynamic Repository with GitHubFlow throws an exception #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MacDennis76 opened this issue Jan 5, 2015 · 7 comments
Closed

Dynamic Repository with GitHubFlow throws an exception #336

MacDennis76 opened this issue Jan 5, 2015 · 7 comments

Comments

@MacDennis76
Copy link

I am testing the Dynamic Repository functionality in combination with GitHubFlow and the latest release of GitVersion 2.0.0

From the command line:
gitversion /url https://stash.test.nl/customer/project/repo.git /b feature-TOHISP-91 /u user /p passw

Result:

Trying to check out 'NextVersion.txt'
Working directory: D:\test_dynamicrepository
Running against branch: feature-TOHISP-91
GitHubFlow version strategy will be used
An unexpected error occurred:
System.ArgumentNullException: Value cannot be null.
Parameter name: path1
at System.IO.Path.Combine(String path1, String path2)
at GitVersion.NextVersionTxtFileFinder.TryGetNextVersion(SemanticVersion& semanticVersion) in c:\BuildAgent\work\68ea6bfb44e5afb\GitVersionCore\GitHubFlow\NextVersionTxtFileFinder.cs:line 19
at GitVersion.NextSemverCalculator.d__2.MoveNext() in c:\BuildAgent\work\68ea6bfb44e5afb\GitVersionCore\GitHubFlow\NextSemverCalculator.cs:line 62
at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at GitVersion.BuildNumberCalculator.GetBuildNumber(GitVersionContext context) in c:\BuildAgent\work\68ea6bfb44e5afb\GitVersionCore\GitHubFlow\BuildNumberCalculator.cs:line 26
at GitVersion.Program.Run()

It fails at:
public bool TryGetNextVersion(out SemanticVersion semanticVersion)
{
var filePath = Path.Combine(repositoryDirectory, "NextVersion.txt");

The repositoryDirectory is equal to null. The reason seems to be that the dynamic repository is a bare repository. This variable is set earlier on to:
context.Repository.Info.WorkingDirectory

WorkingDirectory is part of LibGit2Sharp.

From their code:
///

    /// Gets the normalized path to the working directory.
    /// <para>
    ///   If the repository is bare, null is returned.
    /// </para>
    /// </summary>


    public virtual string WorkingDirectory { get; private set; }

Is this a known issue?

@robdmoore
Copy link

I've seen that before. I got around it by removing the need for a dynamic repository by ensuring it's been fully checked out by the build server and omitting the /url /user and /password parameters.

Definitely is a bug that needs fixing though.

@MacDennis76
Copy link
Author

I encountered this on a TeamCity build agent (server) in combination with server side checkout.
I was able to fix this with the following patch:

public class GitHubFlowVersionFinder
{
    public SemanticVersion FindVersion(GitVersionContext context)
    {
        var repositoryDirectory = context.Repository.Info.WorkingDirectory ?? new DirectoryInfo(context.Repository.Info.Path).Parent.Parent.FullName;

After this patch the code was able to grab NextVersion.txt from the TeamCity checkout directory on the agent.

@dazinator
Copy link
Member

I also reported this same bug under #101

@GeertvanHorrik
Copy link
Contributor

Dynamic repositories should support NextVersion.txt in the root of the repository (I use it all the time with a custom build):

https://github.com/ParticularLabs/GitVersion/blob/ca002ed570b03f2f3a610523ab79adf34848fdc1/GitVersionExe/GitPreparer.cs#L105

@dazinator
Copy link
Member

The recently merged PR #350 should have fixed this problem. But please note #351 if NextVersion.txt isn't being honoured you may find that you need to pass in /b argument identifying the target branch.

@dazinator
Copy link
Member

@MacDennis76 - please can you try again with the latest release, this should now be working nicely.

@MacDennis76
Copy link
Author

Tested with 2.0.1 release. Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants