Skip to content

Add support for worktrees #1607

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

Merged
merged 15 commits into from
Dec 25, 2018

Conversation

mminns
Copy link
Contributor

@mminns mminns commented Sep 11, 2018

See #1471 for more details.

Adds wrappers and tests for the current worktree implementation in libgit2.

This is my first PR for libgit2, please pull apart and point out anything that should be done differently 👍

@mminns
Copy link
Contributor Author

mminns commented Sep 11, 2018

Damn, did I forget to commit some test resources? It all runs fine locally :) I will check.

@ethomson
Copy link
Member

Thanks @mminns! Looks like that might be the case, but I'm eager to have worktree support. :D

@mminns mminns force-pushed the mminns/issue-1471-worktrees branch 2 times, most recently from 6a24e12 to 05e0283 Compare September 17, 2018 10:54
@mminns
Copy link
Contributor Author

mminns commented Sep 17, 2018

There were some files making up part of the test repository that were being gitignored, thought I'd added them all in now, but it looks like not quite.... back to the drawing board...

@mminns
Copy link
Contributor Author

mminns commented Sep 18, 2018

Ah despite all the red, some progress. AFAICS the tests

  • Pass on Windows/AppVeyor. <- But I need to look at the leak stuff
  • Fail on travis <- But I think this might be a path \ vs / issue in the worktree gitdirs 🤞
  • Fail on azure <- not sure why but I'm hoping its the same as travis 🤞

Although maybe I should have checked the LEAKING before opening the PR :)

@bcmedeiros
Copy link

Hey, guys!

I'm currently working on a solution that would highly benefit from this feature, if you need some help, please, let me know!

@mminns
Copy link
Contributor Author

mminns commented Sep 27, 2018

I think I finally sorted out the LEAK stuff.... fingers crossed 🤞

@mminns
Copy link
Contributor Author

mminns commented Sep 28, 2018

1 step forward

  • Pass on Windows/AppVeyor Leaks fixed <- \need to check the publish stage
  • Fail on travis <- But I think this might be a path \ vs / issue in the worktree gitdirs 🤞
  • Fail on azure <- not sure why but I'm hoping its the same as travis 🤞

@mminns
Copy link
Contributor Author

mminns commented Sep 28, 2018

While I fix up the remaining build, if anyone has any comments about the way I've exposed the functionality let me know. I took the submodules work as a starting point and it seems to work OK, but I'm open to any suggestions.

@mminns
Copy link
Contributor Author

mminns commented Sep 28, 2018

Ah I left the LEAK constants defined in the csproj, rookie error.

@mminns
Copy link
Contributor Author

mminns commented Sep 28, 2018

Yes! 1 green, 2 to go. 👍

@mminns
Copy link
Contributor Author

mminns commented Sep 28, 2018

Hi

Ok, I seem to have fixed up the tests and the leaks, but I am at a loss about the Azure Build errors

2018-09-28T10:36:32.3866704Z ##[error]TF400813: The user '4180bb58-415f-47d4-955f-53f0887f795e' is not authorized to access this resource.

The error seems to be re-produced in other PRs

@bording
Copy link
Member

bording commented Sep 28, 2018

@mminns Don't worry about the Azure failures. I don't believe @ethomson has that working correctly yet.

@mminns
Copy link
Contributor Author

mminns commented Sep 28, 2018

In which case please let let rip on the code review itself ... 😰

👍

@dusan-tkac
Copy link

Hi @mminns! Thank you for working on this feature!
I have a use case where I find the current interface lacking:
If working folder of not-locked worktree is deleted, there is no way to prune that worktree.
The Prune method only accepts Worktree instance as a parameter, but you cannot get that instance, because repo.Worktrees["worktreeName"] throws RepositoryNotFoundException.
Maybe there should be an overload for the Prune method that takes a worktree name?

Alternatively, when getting a worktree reference and the worktree repository is not valid, it should not throw an exception. The worktree repository should simply be invalid.

@dusan-tkac
Copy link

@mminns ; there is also a problem I see in the last version (after the leaks fix) - I'm getting an AccessViolationException

at LibGit2Sharp.Core.NativeMethods.git_worktree_lookup(git_worktree*& reference, git_repository* repo, String name)
at LibGit2Sharp.Core.Proxy.git_worktree_lookup(RepositoryHandle repo, String name)
at LibGit2Sharp.Worktree.GetWorktreeHandle()
at LibGit2Sharp.Worktree.get_WorktreeRepository()

I have compiled your version for .Net Framework 4.7.2 and I'm debugging this in Visual Studio 2015 so it might be just something specific to this combination.
Previous version ([26db5b9]) worked fine.

@mminns
Copy link
Contributor Author

mminns commented Oct 1, 2018

@dusan-tkac thanks for the feedback, I've not seen the AccessViolation but let me know if you find anything more, and yes that is a good usecase catch when deleting the worktree outside of libgit, I'll have a think

@dusan-tkac
Copy link

I've not seen the AccessViolation but let me know if you find anything more

@mminns , the problem was on my side. I was accessing worktree.WorktreeRepository outside of the "using" block of the worktree parent repository.

@mminns
Copy link
Contributor Author

mminns commented Oct 8, 2018

Not forgotten about this, planning to look into the pruning a deleted worktree issue asap, once the day job calms down.

@mminns
Copy link
Contributor Author

mminns commented Oct 23, 2018

@dusan-tkac I've corrected the pruning, just need to rebase again....

@mminns mminns force-pushed the mminns/issue-1471-worktrees branch from 82e42a0 to bd98667 Compare October 23, 2018 20:06
@mminns
Copy link
Contributor Author

mminns commented Oct 23, 2018

so that rebase broke all the things....

@mminns
Copy link
Contributor Author

mminns commented Nov 3, 2018

OK, some progress again, tests passing again, 1 memory leak to fix.

@mminns
Copy link
Contributor Author

mminns commented Nov 6, 2018

OK, I think that is as green as the builds will get. 👍

FWIW this PR does not include the ability to specify the target branch etc when opening a Worktree as that option, libgit2/libgit2@a22f19e, wasn't available in the native libgit2 when I started writing this. Personally I do need that functionality so I intend to add it in a follow up PR, but I'd rather try and get this merged first if possible. Although I am open to suggestions on that order of event. 😄

@bcmedeiros
Copy link

Although I am open to suggestions on that order of event.

I'd say we should release this PR as it is if everyone is happy with that, then we put another one for the improvement.

@mminns
Copy link
Contributor Author

mminns commented Nov 17, 2018

Hi @ethomson what happens next, if anything, with this?

@danielang
Copy link

danielang commented Nov 26, 2018

Hi @ all,
first of all: Thank you @mminns for your great work! This PR works nicely in our current development.

When this PR will be merged and released in the nuget package?

@ethomson
Copy link
Member

Sorry for the delay in reviewing this @mminns - this is a great PR. Thanks so much for tackling this! I have just a few questions. 😀

Copy link
Member

@ethomson ethomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only questions are around the csproj changes - I'm not sure if they're intentional or if Visual Studio just added them itself (it does that sometimes). If they are intentional, could you help me understand what they do? And if they're not can we roll them back? Otherwise, this is an amazing pull request.

@@ -34,6 +41,10 @@
<PackageReference Include="Nerdbank.GitVersioning" Version="2.2.13" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I understand what this is...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

<Compile Update="Core\Handles\Objects.cs" DependentUpon="Objects.tt">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this changed - is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@mminns
Copy link
Contributor Author

mminns commented Nov 30, 2018

Thanks for getting back to me, and good questions. I fairly sure they can be reverted but I'll clarify in the next few days.

@mminns
Copy link
Contributor Author

mminns commented Dec 20, 2018

Hi, I know everyone is busy, but just checking in to see what the state of play is with this @ethomson ?

Enjoy the holidays everyone.

@ethomson
Copy link
Member

Cool, thanks for adding this @mminns!

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

Successfully merging this pull request may close these issues.

6 participants