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

Allow cloning of repositories into empty directories #2316

Merged

Conversation

@YuPeiHenry
Copy link
Contributor

@YuPeiHenry YuPeiHenry commented Apr 4, 2019

Ready for review
fixes #2250

The fix modifies CanClone and CanOpen on RepositoryCloneViewModel, and modified RepositoryCloneService CloneOrOpenRepository method to factor for empty directories.

YuPeiHenry added 2 commits Apr 4, 2019
- Currently clone button is disabled and open button is enabled
on empty directories.
- Desired behavior should support cloning to empty directories.
- Non-empty directory message is not shown when the directory is empty.
Copy link
Collaborator

@jcansdale jcansdale left a comment

This is looking good!

Could you add some unit tests? Something similar to this...
https://github.com/github/VisualStudio/blob/master/test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositoryCloneViewModelTests.cs#L317

Maybe add the following tests:

Clone_Is_Enabled_When_Path_EmptyDirectoryExists
PathWarning_Is_Not_Set_When_EmptyDirectoryExists_Selected

I've just realized this is a draft PR. Sorry if I've jumped the gun reviewing it. ;-)

@YuPeiHenry YuPeiHenry marked this pull request as ready for review Apr 4, 2019
@YuPeiHenry YuPeiHenry force-pushed the YuPeiHenry:2250-allow-cloning-to-empty-dir branch from 80198b4 to 43b5ef6 Apr 4, 2019
@meaghanlewis meaghanlewis requested a review from jcansdale Apr 4, 2019
Copy link
Collaborator

@jcansdale jcansdale left a comment

The code for this looks good! 😄 We just need someone to confirm the functionality.

Thanks for the PR!

StanleyGoldman and others added 2 commits Apr 5, 2019
Copy link
Contributor

@StanleyGoldman StanleyGoldman left a comment

We probably need to make the error/warning messages clearer...

For instance when I'm trying to clone into a directory that is not empty and does not have a git repo
The message says "There is already a repository at this location, but it does not contain a repository".

That's not entirely accurate, I haven't looked but I think we have to re-evaluate the messages output by the view model in this and probably some other cases.

image

@StanleyGoldman
Copy link
Contributor

@StanleyGoldman StanleyGoldman commented Apr 5, 2019

image

@StanleyGoldman
Copy link
Contributor

@StanleyGoldman StanleyGoldman commented Apr 5, 2019

The more I look at it, it's just that one message that would no longer be accurate...
I don't even think it was right to begin with..

If the directory is not empty, and is not a git repo that could be scanned.
The error message probably should have been. "A directory exists at the destination path."
Similar to "A file exists at the destination path."

Based on the current logic in this Pull Request.
The new error message should be: "The directory at the destination path is not empty."
The chain of logic should be... (in pseudocode)

if file_exists_at_destination:
   return "A file exists at the destination path"

else:
   if directory_exists_at_destination AND directory_at_destination_not_empty:

      if directory_exists_at_destination_is_git_repo:
         if git_repo_has_no_origin:
            return "A repository already exists at this location, but it doesn't have a remote named `origin`."
         end if

         if git_repo_origin_is_different:
            return "A repository already exists at this location, but it doesn't have a remote named `origin`."
         end if

      else:
         return "The directory at the destination path is not empty."
      end if

   end if
end if
@StanleyGoldman
Copy link
Contributor

@StanleyGoldman StanleyGoldman commented Apr 5, 2019

Let @meaghanlewis weigh in before you change anything...

@meaghanlewis
Copy link
Contributor

@meaghanlewis meaghanlewis commented Apr 5, 2019

I agree with what @StanleyGoldman proposed: The directory at the destination path is not empty. Its straightforward and covers cases where there might be a git directory for the destination or not.

YuPeiHenry added 2 commits Apr 7, 2019
@YuPeiHenry
Copy link
Contributor Author

@YuPeiHenry YuPeiHenry commented Apr 7, 2019

@StanleyGoldman I have updated the error message for non-empty directory. Should something be done about the translation to other languages in this PR?

…led on directories that don't exist
@StanleyGoldman StanleyGoldman force-pushed the YuPeiHenry:2250-allow-cloning-to-empty-dir branch from a29268a to ef0ed57 Apr 8, 2019
@StanleyGoldman
Copy link
Contributor

@StanleyGoldman StanleyGoldman commented Apr 8, 2019

Hey @YuPeiHenry I pushed some commits. It felt easier than nit picking at you. 😈

So I copied the English text to all the language files, we have a 3rd party resource that translates things for us. So we just put the English in place until they get around to it.

I also realized I reordered the logic funny in my pseudocode. You changed the flow to match my ramblings. I undid the damage I caused. Sorry to put you through my spaghetti brain.

And I tweaked DestinationDirectoryEmpty. Everywhere that the function is used, we explicitly check if the directory exists. It makes sense to check if the directory exists inside DestinationDirectoryEmpty to prevent an error, but it's also redundant to all the code that uses DestinationDirectoryEmpty. The only correct choice is to assume the function with be used properly.

All nit picks. I didn't wanna bug you with it. 😅

Since my hands have been all in this, I'm going to let @meaghanlewis test this and give us both the final approval.

@StanleyGoldman StanleyGoldman requested a review from meaghanlewis Apr 8, 2019
@meaghanlewis
Copy link
Contributor

@meaghanlewis meaghanlewis commented Apr 8, 2019

thank you @YuPeiHenry for your contribution! 🎉

@meaghanlewis meaghanlewis merged commit 285c8a5 into github:master Apr 8, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
github.VisualStudio Build #20190408.9 succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.