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

init-branch fails with NullReferenceException #374

Closed
SimplyGed opened this issue May 22, 2013 · 20 comments
Closed

init-branch fails with NullReferenceException #374

SimplyGed opened this issue May 22, 2013 · 20 comments

Comments

@SimplyGed
Copy link

I keep getting an error when attempting to execute init-branch on an existing TFS branch. It The branch I am tring to init was originally created as a folder in TFS, then the code was branched (from master), then the branch was converted to a TFS Branch.

This is similar to a closed issue (#304) but my branch has a parent and it has commits (~20). I am able to reproduce this issue consistently with the current 0.17.1 build (I am using the prebuilt binaries).

I have managed to init other branches without issue.

If you need any more information, let me know.

Command line:

git tfs init-branch $/xxx/yyy/zzz/Iteration50 Iteration50 -d

The stacktrace is:

git-tfs version 0.17.1.0 (TFS client library 11.0.0.0 (MS)) (32-bit)
No authors file used.
=> Working on TFS branch : $/xxx/yyy/zzz/Iteration50
The name of the local branch will be : Iteration50
Git local branch will be :Iteration50
Looking for all branches...
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 Sep.Git.Tfs.VsCommon.TfsHelperVs2010Base.GetRootChangesetForBranch(String tfsPathBranchToCreate, String tfsPathParentBranch)
   at Sep.Git.Tfs.Commands.InitBranch.CreateBranch(IGitTfsRemote defaultRemote, String tfsRepositoryPath, IEnumerable`1 allRemotes, String gitBranchNameExpected, String tfsRepositoryPathParentBranch)
   at Sep.Git.Tfs.Commands.InitBranch.Run(String tfsBranchPath, String gitBranchNameExpected)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Sep.Git.Tfs.Util.GitTfsCommandRunner.Run(GitTfsCommand command, IList`1 args)
   at Sep.Git.Tfs.GitTfs.Main(GitTfsCommand command, IList`1 unparsedArgs)
   at Sep.Git.Tfs.GitTfs.Run(IList`1 args)
   at Sep.Git.Tfs.Program.MainCore(String[] args)
   at Sep.Git.Tfs.Program.Main(String[] args)
Object reference not set to an instance of an object.
@pmiossec
Copy link
Member

Unfortunately the stacktrace is of no help. Perhaps, if you could jump in, fetch the sources of git-tfs, compile and run it to get more informations, it will help us a lot.

I have a little idea of what happens : the method QueryRootBranchObjects(RecursionType.Full) seems to return null instead of BranchObject[] array empty. No idea, why... :(

You say that you already successfully init-branches. Was it on this TFS folder or on another?

I don't see exactly what is the problem and don't know exactly how to solve this problem appart from detecting this problem and preventing git-tfs to crash. You surely have to find what is the problem yourself before we could try to fix it...

@SimplyGed
Copy link
Author

Sorry. Yes, init branches was done on other TFS Branches in the same repo. This one (Iteration50) always failed.

I shall endeavour to pull the source and debug it for more information.

@cincauhangus
Copy link

I too having the same problem. I've originally cloned a branch, but now I'd like to get the main/parent of the current branch and I hit this problem. not sure if this is actually the cause.

$ git tfs branch -d --init $/xxx/xyz main
git-tfs version 0.17.1.0 (TFS client library 10.0.0.0 (MS)) (32-bit)
No authors file used.
=> Working on TFS branch : $/xxx/xyz
The name of the local branch will be : main
Git local branch will be :main
Looking for all branches...
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 Sep.Git.Tfs.VsCommon.TfsHelperVs2010Base.GetRootChangesetForBranch(String tfsPathBranchToCreate, String tfsPathParentBranch)
   at Sep.Git.Tfs.Commands.InitBranch.CreateBranch(IGitTfsRemote defaultRemote, String tfsRepositoryPath, IEnumerable`1 allRemotes, String gitBranchNameExpected, String tfsRepositoryPathParentBranch)
   at Sep.Git.Tfs.Commands.InitBranch.Run(String tfsBranchPath, String gitBranchNameExpected)
   at Sep.Git.Tfs.Commands.Branch.Run(String param1, String param2)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Sep.Git.Tfs.Util.GitTfsCommandRunner.Run(GitTfsCommand command, IList`1 args)
   at Sep.Git.Tfs.GitTfs.Main(GitTfsCommand command, IList`1 unparsedArgs)
   at Sep.Git.Tfs.GitTfs.Run(IList`1 args)
   at Sep.Git.Tfs.Program.MainCore(String[] args)
   at Sep.Git.Tfs.Program.Main(String[] args)
Object reference not set to an instance of an object.

@pmiossec
Copy link
Member

pmiossec commented Jun 4, 2013

I have added trace log to help find out what is the problem and prevent the crash on a null reference.

@SimplyGed @cincauhangus :
Could you compile this version, run it and report the trace log here ?

https://github.com/pmiossec/git-tfs/tree/debug_init_branch

but @cincauhangus , your problem should come from the fact that you can't init a branch that is the parent off your default branch! Because we are looking for a changeset already fetch to create the branch from the correspondent commit. You should first clone the repository from the parent branch and after init the child branch.

@cincauhangus
Copy link

I was guessing that too as I was trying to branch off a quick-clone repo I received that error.

This is probably off topic already but is there a way to clone starting from a specific changeset? Like this SO question: http://stackoverflow.com/questions/3489173/how-to-clone-git-repository-with-specific-revision-changeset Harddisk space is a luxury here and cloning the entire repo is going to make me useless for the entire day (est 8 hours to clone entire repo)..

@pmiossec
Copy link
Member

pmiossec commented Jun 4, 2013

I never used it, but should work, there is an option for that on quick-clone :
-c, --changeset=VALUE The changeset to clone from (must be a number)

and after you do a fetch that should fetch the history starting from this changeset.

@cincauhangus
Copy link

👍 @pmiossec Thanks! will try it out.

Update:
So with -c it will only checkout that specific commit. In addition with a git tfs pull, it should fast forward to the latest changeset.

@pmiossec
Copy link
Member

pmiossec commented Jun 4, 2013

@cincauhangus
yes, a pull or a fetch should be OK...

If you have quite some times, I would be very happy if you could test the version with debug trace to track this null reference! Like that we could fix that bug...

@cincauhangus
Copy link

Sure, will give it a try once I've finished cloning the repo.

@pmiossec
Copy link
Member

pmiossec commented Jun 4, 2013

👍 Thanks a lot 👍 ;)

@cincauhangus
Copy link

Can't reproduce this issue after i've recloned my repo. It's probably the reason you mentioned earlier in #374 (comment)

@pmiossec
Copy link
Member

pmiossec commented Jun 5, 2013

I'm quite sure that was the problem. You tried to init the 'trunk' branch and when we init a branch, we try to find its parent. There is no so there is a null ref exception.
But the goal is to manage well this case and be able to display a message to help the user instead of a abstruse crash...
I just add that to my todo list and will investigate later...

@cincauhangus
Copy link

I think would also be helpful to display the changeset id of the root of each branch. For my case, I wanted to to get the trunk without cloning the entire repo (7000~ checkins) to sync up a branch with the trunk. Had to reclone 3 times to finally get the changeset id i needed to have both the trunk and the branch changesets.

Using git tfs branch eventually gave me the root changeset id required to be able to retrieve the branch, but since I'm too front ahead, I had to reclone at that root.

Not sure if there's a way to add older changesets to an existing repo if you did a quick-clone from a specific changeset.

Anyways, my problem's solved. 👍

@pmiossec
Copy link
Member

pmiossec commented Jun 5, 2013

the (initial) problem of @cincauhangus should be corrected by #390

@SimplyGed if you could (and anyone having that crash in the future) test with this version :
https://github.com/pmiossec/git-tfs/tree/debug_init_branch
and report debug trace....

@SimplyGed
Copy link
Author

The debug trace shows the same stacktrace as before.
I've run it in the debugger and the problem is caused at line 55 in the GetRootChangesetForBranch func.

tfsPathParentBranch = tfsBranchToCreate.Properties.ParentBranch.Item;

The ParentBranch object is NULL

@SimplyGed
Copy link
Author

The problem from the TFS pov is that the branch was done for subfolder, not the parent that has been marked as the branch. E.G.

/Branch/Project

Someone branched the mainline to "Project" whereas they should have done it at "Branch". But "Branch" has been marked as the branch folder and that is what I am trying to init. I'm not going to be able to solve this and will probably leave it be, but the GitTfs tool should probably ensure the ParentBranch is not NULL before trying to access the Item property.

Thanks for help with this

@pmiossec
Copy link
Member

pmiossec commented Jun 5, 2013

Yes that's what I understand and that's what I have corrected with the pull
request I made. That should be ok now...
On 6 Jun 2013 00:01, "SimplyGed" notifications@github.com wrote:

The problem from the TFS pov is that the branch was done for subfolder,
not the parent that has been marked as the branch. E.G.

/Branch/Project

Someone branched the mainline to "Project" whereas they should have done
it at "Branch". But "Branch" has been marked as the branch folder and that
is what I am trying to init. I'm not going to be able to solve this and
will probably leave it be, but the GitTfs tool should probably ensure the
ParentBranch is not NULL before trying to access the Item property.

Thanks for help with this


Reply to this email directly or view it on GitHubhttps://github.com//issues/374#issuecomment-19011947
.

@SimplyGed
Copy link
Author

Was that meant to be in the code I pulled and tested?

@pmiossec
Copy link
Member

pmiossec commented Jun 5, 2013

If you pull my pull request branch or the debug branch I tell you to test,
yes. But it seems that you have tested the git-tfs master... Without the
fix.

PS: TFS permit so much strange things that we don't have enough imagination
to handle all the cases...
On 6 Jun 2013 00:30, "SimplyGed" notifications@github.com wrote:

Was that meant to be in the code I pulled and tested?


Reply to this email directly or view it on GitHubhttps://github.com//issues/374#issuecomment-19013565
.

@SimplyGed
Copy link
Author

OK. My bad. I'll get the debug branch and give it a test.
As for the TFS issues, I know your pain. I've written some TFS tools in the past and I know the problems it can cause :(

Thanks again for your help!

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