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

Commit bd11b66

Browse files
committed
Improve detection of content to show the open dialog
Having commits is not enough to decide whether to show the create or the open dialog. Check whether the repo has subdirectories or files that are not a readme and don't start with .. That at least should be a hint that there's something to open in it.
1 parent 6b45c99 commit bd11b66

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
</None>
102102
<Compile Include="Helpers\INotifyPropertySource.cs" />
103103
<Compile Include="Helpers\PropertyNotifierExtensions.cs" />
104+
<Compile Include="Helpers\SimpleRepositoryModelExtensions.cs" />
104105
<Compile Include="Info\ApplicationInfo.cs" />
105106
<Compile Include="Models\IAccount.cs" />
106107
<Compile Include="Models\IConnectionManager.cs" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using GitHub.Models;
2+
using System;
3+
using System.Linq;
4+
using System.IO;
5+
6+
namespace GitHub.Extensions
7+
{
8+
using VisualStudio;
9+
10+
public static class SimpleRepositoryModelExtensions
11+
{
12+
public static bool HasCommits(this ISimpleRepositoryModel repository)
13+
{
14+
var repo = Services.GetRepoFromPath(repository.LocalPath);
15+
return repo?.Commits.Count() > 0;
16+
}
17+
public static bool HasContent(this ISimpleRepositoryModel repository)
18+
{
19+
var dir = new DirectoryInfo(repository.LocalPath);
20+
return dir.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly)
21+
.Any(x => ((x.Attributes.HasFlag(FileAttributes.Directory) || x.Attributes.HasFlag(FileAttributes.Normal)) &&
22+
!x.Name.StartsWith(".", StringComparison.Ordinal) && !x.Name.StartsWith("readme", StringComparison.Ordinal)));
23+
}
24+
}
25+
}

src/GitHub.Exports/Services/Services.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
using Microsoft.VisualStudio.ComponentModelHost;
99
using Microsoft.VisualStudio.Shell;
1010
using Microsoft.VisualStudio.Shell.Interop;
11-
using Microsoft.VisualStudio.TextManager.Interop;
1211
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
13-
using GitHub.Models;
1412
using GitHub.Info;
15-
using GitHub.Extensions;
1613
using GitHub.Primitives;
1714

1815
namespace GitHub.VisualStudio
@@ -180,11 +177,5 @@ public static UriString GetUriFromRepository(this IGitRepositoryInfo repoInfo)
180177
{
181178
return repoInfo.GetRepoFromIGit()?.GetUri();
182179
}
183-
184-
public static bool HasCommits(this ISimpleRepositoryModel repository)
185-
{
186-
var repo = GetRepoFromPath(repository.LocalPath);
187-
return repo?.Commits.Count() > 0;
188-
}
189180
}
190181
}

src/GitHub.VisualStudio/TeamExplorer/Connect/GitHubConnectSection.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ void HandleCreatedRepo(ISimpleRepositoryModel newrepo)
232232

233233
void HandleClonedRepo(ISimpleRepositoryModel newrepo)
234234
{
235+
235236
var msg = string.Format(CultureInfo.CurrentUICulture, Constants.Notification_RepoCloned, newrepo.Name, newrepo.CloneUrl);
236-
if (newrepo.HasCommits())
237+
if (newrepo.HasCommits() && newrepo.HasContent())
237238
msg += " " + string.Format(CultureInfo.CurrentUICulture, Constants.Notification_OpenProject, newrepo.LocalPath);
238239
else
239240
msg += " " + string.Format(CultureInfo.CurrentUICulture, Constants.Notification_CreateNewProject, newrepo.LocalPath);

0 commit comments

Comments
 (0)