Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Unified Clone / Open from GitHub UI #1919

Merged
merged 46 commits into from
Sep 27, 2018
Merged

Conversation

jcansdale
Copy link
Collaborator

@jcansdale jcansdale commented Sep 13, 2018

What this PR does

  • Allow user to Open a repository when the target path already exists
  • View/open cloned repositories on Team Explorer Home (same as built in clone)
  • In Visual Studio 2017 open cloned repositories in Folder view (same as built in clone)
  • Fix GitHub button on Start Page
  • Add Add File / Open / Open from GitHub... button
  • Pre-populate Url from clipboard/command args when available
  • Only show warning banner when a file is in the way of the target path
  • Use Clone/Open dialog for existing GitHub.OpenFromUrl command

TODO

  • Add metrics

What this PR doesn't do

The GitHub.OpenFromUrl command will no longer attempt to navigate the the file and line number from a target Url. This was done to trim the scope of this PR to simply cloning/opening a repository.

The next step will be to incorporate functionality from the Open from clipboard command. This will be more complex to test and will be done as a separate PR.

At the moment these two commands can be combined manually:

  1. Copy a GitHub URL to the clipboard
  2. Use Add File / Open / Open from GitHub...
  3. Use GitHub > Open from clipboard

How to test

Here is an example workflow

  1. Copy a GitHub URL
    image

  2. Select File > Open > Open from GitHub...
    image

  3. URL is copied into username/repository field and path is populated with a default location
    image

  4. Click Open if local repository already exists or update path and Clone to create a new repository
    image

  5. Repository folder is loaded into Solution Explorer and Team Explorer - Home appears
    image

  6. Select from list of solutions

Use clone from URL as the UI for GitHub.OpenFromUrl.
Now we have a proper UI, re-enable the `File / Open / Open from
GitHub...` button.
Add method for cloning or opening a repository.
Add method to open a repository and view it on Team Explorer Home.
Use VSServices.TryOpenRepository on Visual Studio 2015 where solution
folders aren't available. This creates a temporary solution to make
Team Explorer change its active repository.
When a directory already exists we can open the repository, so only
show a path error when a file exists at the target path.
IVSServices is only used in Visual Studio 2015 so retrieve it on demand.
Be flexible about the type of Url that CloneDialogResult can return.
Convert ToRepositoryUrl inside this method.
This command is now only responsible for opening the clone and calling
CloneOrOpenRepository.
@jcansdale jcansdale changed the title [spike] Unified Clone / Open from GitHub UI Unified Clone / Open from GitHub UI Sep 18, 2018
@meaghanlewis
Copy link
Contributor

This LGTM @jcansdale

await CloneRepository(cloneUrl, repositoryPath, progress);
}

teamExplorerServices.OpenRepository(repositoryPath);
Copy link
Collaborator Author

@jcansdale jcansdale Sep 24, 2018

Choose a reason for hiding this comment

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

We don't need to do this when cloning (it happens as part of the clone). But we should still switch to Team Explorer - Home.

It appears that CloneRepository is also called when a new repository is
created. Only increment the new counters during CloneOrOpenRepository.
Increment new NumberOfGitHubClones and NumberOfEnterpriseClones
counters in CloneOrOpenRepository but not CloneRepository.
Expect to fail on this commit.
Increment NumberOfGitHubOpens and NumberOfEnterpriseOpens counters when
CloneOrOpenRepository is called.
@@ -121,20 +172,7 @@ public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress ad
try
{
await vsGitServices.Clone(cloneUrl, repositoryPath, true, progress);

await usageTracker.IncrementCounter(x => x.NumberOfClones);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method is being called by CreateRepository here:

.Select(repository => cloneService.CloneRepository(repository.CloneUrl, Path.Combine(directory, repository.Name)))

Change to "A file exists at the destination path."
@jcansdale jcansdale force-pushed the feature/open-from-uri-clone-ui branch from 430fb34 to 9f8757a Compare September 25, 2018 14:48
jcansdale and others added 7 commits September 25, 2018 16:20
Check the following conditions:
- Local repository exists at path
- Local repository has an 'origin' remote
- Local repository's URL matches selected repository
There was an issue with PathError appearing at the top. When the error
appeared, the repository list would move down causing a different
repository to be selected. This would clause flickering between two
repositories.

This commit consolidates PathError into PathWarning (which appears
above the path which is being validated).  This avoids the flicker and
puts the warning next to the text box which it applies to.

The logic to block clone or open when there is a file in the way has
been moved to the commands' `canExecute` observable.
@jcansdale
Copy link
Collaborator Author

jcansdale commented Sep 27, 2018

@grokys re: #1919 (comment)

Should we be checking whether the repository at this path has the same clone URL? I'm thinking of the case where e.g. the user wants to clone a fork and they already have the parent repository at this location.

I've added checks for this and also for when there is no repository at the target path or when the repository doesn't have a remote named origin.

I've moved the warning banner to above the Local path text box that it's validating. This was for a couple of reasons.

  1. Having it appear above the tree view meant that when it appeared, it moved the tree view control that the user might have clicked on. This lead to rapid cycling between two selections.

  2. Moving it to above the field that it's validating means the context is obvious and the warnings can be more concise (we're somewhat restricted for space).

Here are the warnings:

  • When there is no repository at the local path (e.g. an empty folder):
    image

  • When the remote URL of the local repository is different to the URL selected:
    image

  • When there is a file in the way of the local path (in this case there is a file called PReview:
    image

  • When the target repository doesn't have a remote named origin and won't be recognized by GHfVS:
    image

"You have already cloned to this location. Click 'Open' to open the
local repository."
@jcansdale
Copy link
Collaborator Author

  • It will now always this this when a local clone already exists:
    image

@jcansdale
Copy link
Collaborator Author

jcansdale commented Sep 27, 2018

Here are the updated warning messages:

image

image

image

image

Add Open_Is_Enabled_When_Path_DirectoryExists test
Fix/update some other tests
Copy link
Contributor

@StanleyGoldman StanleyGoldman left a comment

Choose a reason for hiding this comment

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

Should the user message here change?


usageTracker.IncrementCounter(x => x.NumberOfGitHubConnectSectionClones).Forget();
}
catch (Exception e)
{
var teServices = ServiceProvider.TryGetService<ITeamExplorerServices>();
teServices.ShowError(e.GetUserFriendlyErrorMessage(ErrorType.ClonedFailed, result.Repository.Name));
teServices.ShowError(e.GetUserFriendlyErrorMessage(ErrorType.ClonedFailed, result.Url.RepositoryName));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the user message here change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. Commit incoming. 🚀

PathWarning_Is_Set_For_Existing_Clone_At_Destination
PathWarning_Is_Set_For_Repository_With_No_Origin
PathWarning_Is_Set_For_Directory_With_No_Repository
PathWarning_Is_Set_For_Existing_Repository_At_Destination_With_Different_Remote
Changed ClonedFailed to CloneOrOpenFailed.
@jcansdale jcansdale mentioned this pull request Sep 27, 2018
@jcansdale jcansdale merged commit b582064 into master Sep 27, 2018
@jcansdale jcansdale deleted the feature/open-from-uri-clone-ui branch September 27, 2018 17:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants