Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions src/GitHub.App/Extensions/RepositoryModelExtensions.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/GitHub.App/GitHub.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
<Compile Include="Caches\ImageCache.cs" />
<Compile Include="Extensions\AkavacheExtensions.cs" />
<Compile Include="Extensions\EnvironmentExtensions.cs" />
<Compile Include="Extensions\RepositoryModelExtensions.cs" />
<Compile Include="Extensions\ValidationExtensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Infrastructure\LoggingConfiguration.cs" />
Expand Down
46 changes: 46 additions & 0 deletions src/GitHub.Exports/Extensions/GitHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using GitHub.Primitives;
using LibGit2Sharp;
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
using System;
using System.Linq;

namespace GitHub.Extensions
{
public static class GitHelpers
{
public static Repository GetRepoFromIGit(this IGitRepositoryInfo repoInfo)
{
var repoPath = Repository.Discover(repoInfo.RepositoryPath);
if (repoPath == null)
return null;
return new Repository(repoPath);
}

public static UriString GetUriFromRepository(this IGitRepositoryInfo repoInfo)
{
return repoInfo.GetRepoFromIGit()?.GetUri();
}

public static UriString GetUri(this Repository repo)
{
return UriString.ToUriString(GetUriFromRepository(repo)?.ToRepositoryUrl());
}

static UriString GetUriFromRepository(Repository repo)
{
return repo
?.Network
.Remotes
.FirstOrDefault(x => x.Name.Equals("origin", StringComparison.Ordinal))
?.Url;
}

public static Repository GetRepoFromPath(string path)
{
var repoPath = Repository.Discover(path);
if (repoPath == null)
return null;
return new Repository(repoPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@
using System;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;

namespace GitHub.Extensions
{
using VisualStudio;

public static class SimpleRepositoryModelExtensions
{
/// <summary>
/// Create a SimpleRepositoryModel from a VS git repo object
/// </summary>
public static ISimpleRepositoryModel ToModel(this IGitRepositoryInfo repo)
{
if (repo == null)
return null;
var uri = repo.GetUriFromRepository();
var name = uri?.NameWithOwner;
return name != null ? new SimpleRepositoryModel(name, uri, repo.RepositoryPath) : null;
}

public static bool HasCommits(this ISimpleRepositoryModel repository)
{
var repo = Services.GetRepoFromPath(repository.LocalPath);
var repo = GitHelpers.GetRepoFromPath(repository.LocalPath);
return repo?.Commits.Any() ?? false;
}

public static bool MightContainSolution(this ISimpleRepositoryModel repository)
{
var dir = new DirectoryInfo(repository.LocalPath);
Expand Down
7 changes: 4 additions & 3 deletions src/GitHub.Exports/GitHub.Exports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@
<None Include="..\..\script\Key.snk" Condition="$(Buildtype) == 'Internal'">
<Link>Key.snk</Link>
</None>
<Compile Include="Extensions\GitHelpers.cs" />
<Compile Include="Helpers\INotifyPropertySource.cs" />
<Compile Include="Helpers\PropertyNotifierExtensions.cs" />
<Compile Include="Helpers\SimpleRepositoryModelExtensions.cs" />
<Compile Include="Extensions\PropertyNotifierExtensions.cs" />
<Compile Include="Extensions\SimpleRepositoryModelExtensions.cs" />
<Compile Include="Info\ApplicationInfo.cs" />
<Compile Include="Models\IAccount.cs" />
<Compile Include="Models\IConnectionManager.cs" />
Expand All @@ -122,7 +123,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Authentication\AuthenticationResultExtensions.cs" />
<Compile Include="Services\VSExtensions.cs" />
<Compile Include="Extensions\VSExtensions.cs" />
<Compile Include="UI\IView.cs" />
<Compile Include="UI\Octicon.cs" />
<Compile Include="ViewModels\IGitHubConnectSection.cs" />
Expand Down
38 changes: 1 addition & 37 deletions src/GitHub.Exports/Services/Services.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using EnvDTE;
using EnvDTE80;
using GitHub.Services;
Expand All @@ -8,9 +7,9 @@
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
using GitHub.Info;
using GitHub.Primitives;
using GitHub.Extensions;

namespace GitHub.VisualStudio
{
Expand Down Expand Up @@ -142,40 +141,5 @@ public static Repository GetRepoFromSolution(this IVsSolution solution)
return null;
return new Repository(repoPath);
}

public static UriString GetUri(this Repository repo)
{
return UriString.ToUriString(GetUriFromRepository(repo)?.ToRepositoryUrl());
}

static UriString GetUriFromRepository(Repository repo)
{
return repo
?.Network
.Remotes
.FirstOrDefault(x => x.Name.Equals("origin", StringComparison.Ordinal))
?.Url;
}

public static Repository GetRepoFromIGit(this IGitRepositoryInfo repoInfo)
{
var repoPath = Repository.Discover(repoInfo.RepositoryPath);
if (repoPath == null)
return null;
return new Repository(repoPath);
}

public static Repository GetRepoFromPath(string path)
{
var repoPath = Repository.Discover(path);
if (repoPath == null)
return null;
return new Repository(repoPath);
}

public static UriString GetUriFromRepository(this IGitRepositoryInfo repoInfo)
{
return repoInfo.GetRepoFromIGit()?.GetUri();
}
}
}
2 changes: 1 addition & 1 deletion src/GitHub.Exports/Services/VSServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static IEnumerable<ISimpleRepositoryModel> PokeTheRegistryForRepositoryList()
var path = subkey?.GetValue("Path") as string;
if (path != null)
{
var uri = VisualStudio.Services.GetRepoFromPath(path)?.GetUri();
var uri = GitHelpers.GetRepoFromPath(path)?.GetUri();
var name = uri?.NameWithOwner;
if (name != null)
return new SimpleRepositoryModel(name, uri, path);
Expand Down
4 changes: 0 additions & 4 deletions src/GitHub.Extensions/GitRepoExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
using NullGuard;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GitHub.Extensions
{
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.VisualStudio/Base/TeamExplorerItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GitHub.VisualStudio.Helpers;
using NullGuard;
using Octokit;
using GitHub.Extensions;

namespace GitHub.VisualStudio.Base
{
Expand Down