Skip to content

NullReferenceException when using dynamic repositories #782

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
laped opened this issue Feb 9, 2016 · 7 comments
Closed

NullReferenceException when using dynamic repositories #782

laped opened this issue Feb 9, 2016 · 7 comments

Comments

@laped
Copy link

laped commented Feb 9, 2016

I'm trying to use this with TeamCity, but locally I can't get it to work either when calling GitVersion with the arguments specified on this page: http://gitversion.readthedocs.org/en/latest/more-info/dynamic-repositories/

This is the command line:

GitVersion.exe /url http://gitlab/project/backend.git /u user /p password /b branchName /c ad43e4e51b9

System.NullReferenceException: Object reference not set to an instance of an object.
   at GitVersion.GitPreparer.GetDotGitDirectory()
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId)
   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
   at GitVersion.Program.VerifyArgumentsAndRun()

Which is the following line (94) in GetDotGitDirectory() when debugging locally:

var dotGitDirectory = Repository.Discover(targetPath).TrimEnd('/', '\\');

From what I can tell from looking at the code in GetDotGitDirectory(), the property IsDynamicRepository will never return true because it checks if DynamicGitRepositoryPath is empty and it is until the Initialise method has been called in GitPreparer class - which happens after the call to GetDotGitDirectory.
Even in all the unit tests the Initialise method is called first, before calling GetDotGitDirectory.

If I modify the source code in ExecuteCore.cs in line 28 (ExecuteGitVersion) from this:

var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory);
var dotGitDirectory = gitPreparer.GetDotGitDirectory();

to this:

var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory);
gitPreparer.Initialise(false, targetBranch);
var dotGitDirectory = gitPreparer.GetDotGitDirectory();

it works as expected.

But since I'm not familiar enough with the codebase I'm not sure it's the right fix to this problem. Maybe I'm just calling with the wrong arguments, although it doesn't look like it when reading the docs.

@chappoo
Copy link

chappoo commented Feb 12, 2016

I was seeing exactly the same symptoms earlier; ended up rolling back to v3.3.0 from Chocolatey feed to get our builds working again. PR is unlikely from me as well for similar reasons.

@JakeGinnivan
Copy link
Contributor

No problems guys, thanks for the report. I will fix as soon as I get a chance.

@rubenmamo
Copy link
Contributor

In version 3.5.3 I get the following error instead:

Can't find the .git directory in C:\Development\Project
   at GitVersion.GitPreparer.GetDotGitDirectory() in C:\Development\GitVersion\src\GitVersionCore\GitPreparer.cs:line 105
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig) in C:\Development\GitVersion\src\GitVersionCore\ExecuteCore.cs:line 30
   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem) in C:\Development\GitVersion\src\GitVersionExe\SpecifiedArgumentRunner.cs:line 29
   at GitVersion.Program.VerifyArgumentsAndRun() in C:\Development\GitVersion\src\GitVersionExe\Program.cs:line 91

@asbjornu
Copy link
Member

@rubenmamo Yes, the NullReferenceException was changed to a more informative DirectoryNotFoundException in #860. Does C:\Development\Project actually contain a .git directory?

@rubenmamo
Copy link
Contributor

@asbjornu no the folder does not have a .git directory.

I'm using dynamic repositories in team city and tried to debug it by using the source code, I call GitVersion from the build agent and pass the /url /b /c /u /p parameters to it. What seems to be happening is that when GitPreparer.GetDotGitDirectory() is called from execute core in these cases DynamicGitRepositoryPath is not initialised and hence the following code is skipped

            if (IsDynamicGitRepository)
                return DynamicGitRepositoryPath;

As @laped mentioned in the original comment the problem seems to be a missing call to gitPreparer.Initialise(false, targetBranch); in ExecuteCore, however this seems to do a number of things and hence might cause additional issues?

I'm happy to add the missing method call and create a PR

@rubenmamo
Copy link
Contributor

I added Pull Request #874 which should resolve this.

@pascalberger
Copy link
Member

#874 was released with version 3.6.0

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

6 participants