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

Add list of repos to the connect page #32

Merged
merged 36 commits into from Sep 4, 2015
Merged

Add list of repos to the connect page #32

merged 36 commits into from Sep 4, 2015

Conversation

@shana
Copy link
Collaborator

@shana shana commented Aug 5, 2015

I'm not sure it's worth caching the known GitHub repositories list in our connection cache instead of just poking the registry every time the Connect page is loaded. I'll have to monitor the registry for changes so I can update our cache when new repos get added to VS (because there's no API to notify us of that)

shana added 2 commits Aug 5, 2015
Adds a list view showing the list of repositories
that VS knows about and that are associated with
the github connection (i.e., the remote url corresponds
to the github connection section information)
Conflicts:
	src/GitHub.Exports/Primitives/UriString.cs
	src/GitHub.Exports/Services/Services.cs
	src/GitHub.VisualStudio/Base/TeamExplorerItemBase.cs
@shana shana force-pushed the shana/list-git-repos branch from a69ab09 to eeceabe Aug 21, 2015
shana added 6 commits Aug 21, 2015
The repository list is loaded from the registry into ConnectionManager.
Don't save it in the cache for now, so it doesn't break compatibility
with the existing cache files and we don't really need to cache it right
now. Let's see how it works just loading directly from the registry for
now.
@shana shana force-pushed the shana/list-git-repos branch from 0054509 to fdc8a2e Aug 21, 2015
@shana shana changed the title [WIP] Add list of repos to the connnect page Add list of repos to the connnect page Aug 24, 2015
Offering to open a solution or project is the only way to switch the
context to the new repo. Since it's likely that that's what the user
wants to do anyway (why clone a repo otherwise), let's do that.
@shana
Copy link
Collaborator Author

@shana shana commented Aug 24, 2015

This is what it looks like now

screen shot 2015-08-24 at 11 35 11 pm

Highlighting

screen shot 2015-08-24 at 11 35 34 pm

Opening a repo

If an entry is double clicked or cloning is finished, file explorer with solution filter is run:

screen shot 2015-08-24 at 11 36 12 pm

@shana
Copy link
Collaborator Author

@shana shana commented Aug 24, 2015

Fixes #16

@shana shana added this to the 1.0.13 milestone Aug 24, 2015
@shana
Copy link
Collaborator Author

@shana shana commented Aug 24, 2015

Since I'm already hooking up into a property change that tells me the cloning is done, we can also do it for the repo creation and maybe switch out the message. Could be a nice thing to have.

@shana
Copy link
Collaborator Author

@shana shana commented Aug 24, 2015

🍍

I haven't added tests for the new classes yet, doing that tomorrow, probably on a separate branch off of this one.

/cc @haacked

@shana
Copy link
Collaborator Author

@shana shana commented Aug 24, 2015

Should I order the repo list?

@haacked
Copy link
Contributor

@haacked haacked commented Aug 25, 2015

If an entry is double clicked or cloning is finished, file explorer with solution filter is run:

Shouldn't we do the same thing that double clicking a repository listed in the "Local Git Repositories" section?

Should I order the repo list?

Yeah, I think so.

@shana
Copy link
Collaborator Author

@shana shana commented Aug 25, 2015

If an entry is double clicked or cloning is finished, file explorer with solution filter is run:

Shouldn't we do the same thing that double clicking a repository listed in the "Local Git Repositories" section?

I wish, but there's no API to trigger that at all. It's switching the source control context (closing opened solutions and changing to another repo) without actually opening anything in the new repo. It's all private logic that we have no access to.

TBH, I think offering to open a solution in the selected repo when you double click is better than blindly closing the current one and switching to the selected repo without doing anything else or asking the user. It's a very confusing experience, you don't know what happened and VS enters into this limbo state where nothing is loaded but there's some sort of source control context that's active, which changes all the default paths for things (and you only notice if you pay particular attention to the default path in the project creation dialog). The fact that it closes the currently opened solution without asking annoys me particularly, I don't like things happening without warning, but that's just me 😛

@haacked
Copy link
Contributor

@haacked haacked commented Aug 25, 2015

👍 to that reasoning.

shana added 2 commits Aug 25, 2015
The previous logic wouldn't work if there is no active repo in VS
[AllowNull]
public ISimpleRepositoryModel SelectedRepository {
[return: AllowNull] get { return selectedRepository; }
set { selectedRepository = value; this.RaisePropertyChange(); } }

This comment has been minimized.

@haacked

haacked Aug 27, 2015
Contributor

Nitpick Neymar: brace formatting here is inconsistent with the rest of the code. 😄

@@ -129,23 +182,70 @@ void UpdateConnection()
void OnPropertyChange(object sender, System.ComponentModel.PropertyChangedEventArgs e)

This comment has been minimized.

@haacked

haacked Aug 27, 2015
Contributor

You could probably omit the System.CompenentModel. part here since it's already declared in the usings section.

SelectedRepository = r;
var repo = await ApiFactory.Create(r.CloneUrl).GetRepository();
r.SetIcon(repo.Private, repo.Fork);
}).ToList();

This comment has been minimized.

@haacked

haacked Aug 27, 2015
Contributor

The use of ToList here is confusing because we're not using the return value.

I think ForEach would more clearly express the intent here.

                e.NewItems
                    .Cast<ISimpleRepositoryModel>()
                    .ForEach(async r =>
                {
                    if (String.Equals(Holder.ActiveRepo?.RepositoryPath, r.LocalPath, StringComparison.CurrentCultureIgnoreCase))
                        SelectedRepository = r;
                    var repo = await ApiFactory.Create(r.CloneUrl).GetRepository();
                    r.SetIcon(repo.Private, repo.Fork);
                });

This comment has been minimized.

@shana

shana Aug 27, 2015
Author Collaborator

Yup, ForEach is better! 👍

var old = Repositories.FirstOrDefault(x => String.Equals(Holder.ActiveRepo?.RepositoryPath, x.LocalPath, StringComparison.CurrentCultureIgnoreCase));
// open the solution selection dialog when the user wants to switch to a different repo
// since there's no other way of changing the source control context in VS
if (SelectedRepository != old)

This comment has been minimized.

@haacked

haacked Aug 27, 2015
Contributor

I haven't thought this through, but this is a reference equality check. Should this be:

if (!Equals(SelectedRepository, old))

This comment has been minimized.

@shana

shana Aug 27, 2015
Author Collaborator

It's on purpose, the equality operators are overriden in SimpleRepositoryModel to perform comparisons based on content (because the instances are different, maybe not their content). There's comments in SimpleRepositoryModel to that effect.

This comment has been minimized.

@shana

shana Aug 28, 2015
Author Collaborator

nvm, I took the overloaded operators out and switched to Equals on this

{
if (values[0] is ISimpleRepositoryModel)
return ((ISimpleRepositoryModel)values[0]).Name;
return String.Empty;

This comment has been minimized.

@haacked

haacked Aug 27, 2015
Contributor

This is probably more a code style issue than an actual perf issue since array access and casting types is pretty cheap, but I would probably write the above as:

It probably doesn't matter for perf, but I tend to replace double cast checks with something like:

var model = values[0] as ISimpleRepositoryModel;
return model != null ? model.Name : String.Empty;

That accesses the array only once and type checks only once. However, more importantly to me, I think that's a bit more readable.

This comment has been minimized.

@haacked

haacked Aug 27, 2015
Contributor

Or even better.

var model = values[0] as ISimpleRepositoryModel;
return model?.Name ?? String.Empty;
@haacked
Copy link
Contributor

@haacked haacked commented Aug 27, 2015

Yeah, I agree. The message is just a notification, not a popup, so that's not going to be jarring. I've set up a separate PR (#59) for it anyway, it doesn't need to be here (but it's based on this one so reviewing that one means only looking at the one commit that has the message)

Sorry, i don't think i was being clear. I think that popping up the New Project dialog after creating a new repository should be done in a separate PR too. I don't think it belongs in this PR which should solely be focused on listing repositories.

@shana
Copy link
Collaborator Author

@shana shana commented Aug 27, 2015

Sorry, i don't think i was being clear. I think that popping up the New Project dialog after creating a new repository should be done in a separate PR too. I don't think it belongs in this PR which should solely be focused on listing repositories.

Oh yeah, I'm taking that part out too 😄

shana added 9 commits Aug 28, 2015
When there's more than one connection, logging out of the first
connection would cause it to render the logged out connection instead of
the one still logged in.
Add a tracker class to accurately track the state of the local git
repository list, so we can update our lists accordingly. Cleanup and fix
a bunch of list-refreshing stuff.
@shana shana force-pushed the shana/list-git-repos branch from 49bb73f to 03e17bc Aug 28, 2015
shana added 2 commits Aug 31, 2015
Operator precedence is kinda important...
@shana
Copy link
Collaborator Author

@shana shana commented Aug 31, 2015

Ok, I think I caught all the issues and fixed all the things! 🍨

if (context == null)
return item?.Name ?? String.Empty;

if (context.SectionConnection.Username == item.CloneUrl.Owner)

This comment has been minimized.

@haacked

haacked Sep 2, 2015
Contributor

If context not null, but item was null, we'd get a NullReferenceException here. Perhaps line 79 should be if (context == null || item == null)

string old;
using (var key = Registry.CurrentUser.OpenSubKey(PathsKey, true))
{
old = (string)key.GetValue("Value0", string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);

This comment has been minimized.

@haacked

haacked Sep 2, 2015
Contributor

Potential NullReferenceException here with key.

{
using (var subkey = key.OpenSubKey(x))
{
var path = subkey.GetValue("Path") as string;

This comment has been minimized.

@haacked

haacked Sep 2, 2015
Contributor

Potential NullReferenceException here. If we want to throw an exception when subkey is null (since the caller is handling it), we probably should throw something better and more informative than NullReferenceException.

@haacked
Copy link
Contributor

@haacked haacked commented Sep 4, 2015

I went ahead and fixed the potential nullrefs. I think this branch is good.

haacked added a commit that referenced this pull request Sep 4, 2015
Add list of repos to the connect page
@haacked haacked merged commit f615190 into master Sep 4, 2015
3 checks passed
3 checks passed
GitHub CLA @shana has accepted the GitHub Contributor License Agreement.
Details
VisualStudio Build #2305898 succeeded in 127s
Details
jenkins/build_log Jenkins Build Log
Details
@haacked
Copy link
Contributor

@haacked haacked commented Sep 4, 2015

high-five-to-self

@shana shana deleted the shana/list-git-repos branch Dec 7, 2015
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.

None yet

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