Skip to content
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

Null reference exception when working copy has detached head #34

Open
davidwengier opened this issue Dec 13, 2018 · 4 comments
Open

Null reference exception when working copy has detached head #34

davidwengier opened this issue Dec 13, 2018 · 4 comments

Comments

@davidwengier
Copy link
Collaborator

not sure how long it ran but:

S:\VS>git pr --remote origin
Azure Repos
Found 5888 objects to send. (2349 ms)

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at GitPullRequest.Services.GitPullRequestService.FindPullRequests(IDictionary`2 gitRepositories, Branch branch) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest.Services\GitPullRequestService.cs:line 46
   at GitPullRequest.Program.<>c__DisplayClass21_0.<ListBranches>b__1(Branch b) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 118
   at System.Linq.Enumerable.SelectManyIterator[TSource,TCollection,TResult](IEnumerable`1 source, Func`2 collectionSelector, Func`3 resultSelector)+MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.ToList()
   at GitPullRequest.Program.ListBranches(GitPullRequestService service, Repository repo, String remoteName) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 116
   at GitPullRequest.Program.OnExecute() in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 60
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 86
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 64
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext() in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 25
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass131_0.<OnExecute>b__0() in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 600
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 31
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 105
   at GitPullRequest.Program.Main(String[] args) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 17
@davidwengier
Copy link
Collaborator Author

This isn't because of a detached head, or if it is then its the combination of that and something else

@rainersigwald
Copy link

Same repo state, 1.0.14:

S:\VS>powershell measure-command {git pr --remote origin}

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at GitPullRequest.Services.GitPullRequestService.FindPullRequests(RemoteRepositoryCache remoteRepositoryCache, IList`1 upstreamRepositories, Branch branch) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest.Services\GitPullRequestService.cs:line 41
   at GitPullRequest.Program.<>c__DisplayClass21_0.<ListBranches>b__1(Branch b) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 124
   at System.Linq.Enumerable.SelectManyIterator[TSource,TCollection,TResult](IEnumerable`1 source, Func`2 collectionSelector, Func`3 resultSelector)+MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.ToList()
   at GitPullRequest.Program.ListBranches(GitPullRequestService service, Repository repo, String remoteName, Action`1 exceptionLogger) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 122
   at GitPullRequest.Program.OnExecute() in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 63
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 86
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 64
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext() in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 25
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass131_0.<OnExecute>b__0() in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 600
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 31
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 105
   at GitPullRequest.Program.Main(String[] args) in C:\Source\github.com\jcansdale\GitPullRequest\GitPullRequest\Program.cs:line 18


Days              : 0
Hours             : 0
Minutes           : 5
Seconds           : 17
Milliseconds      : 297
Ticks             : 3172970569
TotalDays         : 0.0036724196400463
TotalHours        : 0.0881380713611111
TotalMinutes      : 5.28828428166667
TotalSeconds      : 317.2970569
TotalMilliseconds : 317297.0569

@jcansdale
Copy link
Owner

jcansdale commented Dec 18, 2018

Thanks for the trace. It does look like a branch doesn't have an Tip commit:
https://github.com/jcansdale/GitPullRequest/blob/master/GitPullRequest.Services/GitPullRequestService.cs#L41

I must have been looking at the wrong source when I checked the first time!

@jcansdale
Copy link
Owner

This is actually different to a detached head. A detached head would look like this:
image

The exception is showing a branch with no commits. Strange. 🤔

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

3 participants