/// <summary> /// Probes for a git repository and if one is found, returns a normalized GitHub uri /// <see cref="UriString"/> for the repository's remote named "origin" if one is found /// </summary> /// <remarks> /// The lookup checks to see if the path specified by the RepositoryPath property of the specified /// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it /// either finds a repository, or reaches the root disk. /// </remarks> /// <param name="repoInfo">The repository information containing the path to start probing</param> /// <returns>Returns a <see cref="UriString"/> representing the uri of the "origin" remote normalized to a GitHub repository url or null if none found.</returns> public static UriString GetUriFromVSGit(IGitRepositoryInfo repoInfo) { return GitServiceHelper.GetUri(repoInfo); }
/// <summary> /// Probes for a git repository and if one is found, returns a <see cref="IRepository"/> instance for the /// repository. /// </summary> /// <remarks> /// The lookup checks to see if the path specified by the RepositoryPath property of the specified /// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it /// either finds a repository, or reaches the root disk. /// </remarks> /// <param name="repoInfo">The repository information containing the path to start probing</param> /// <returns>An instance of <see cref="IRepository"/> or null</returns> public static IRepository GetRepoFromVSGit(IGitRepositoryInfo repoInfo) { return GitServiceHelper.GetRepo(repoInfo); }
/// <summary> /// Probes for a git repository and if one is found, returns a normalized GitHub uri /// <see cref="UriString"/> for the repository's remote named "origin" if one is found /// </summary> /// <remarks> /// The lookup checks to see if the path specified by the RepositoryPath property of the specified /// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it /// either finds a repository, or reaches the root disk. /// </remarks> /// <param name="repoInfo">The repository information containing the path to start probing</param> /// <returns>Returns a <see cref="UriString"/> representing the uri of the "origin" remote normalized to a GitHub repository url or null if none found.</returns> public UriString GetUri(IGitRepositoryInfo repoInfo) { return GetUri(GetRepo(repoInfo)); }
void UpdateRepo(IGitRepositoryInfo repo) { ActiveRepo = repo; RepoChanged(); Invalidate(); }
/// <summary> /// Probes for a git repository and if one is found, returns a <see cref="IRepository"/> instance for the /// repository. /// </summary> /// <remarks> /// The lookup checks to see if the path specified by the RepositoryPath property of the specified /// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it /// either finds a repository, or reaches the root disk. /// </remarks> /// <param name="repoInfo">The repository information containing the path to start probing</param> /// <returns>An instance of <see cref="IRepository"/> or null</returns> public IRepository GetRepo(IGitRepositoryInfo repoInfo) { return GetRepo(repoInfo?.RepositoryPath); }
/// <summary> /// Gets the policies applicable to the specified <paramref name="repository"/>. /// </summary> /// <param name="repository">An <see cref="IGitRepositoryInfo"/> instance representing the repository.</param> /// <returns>Returns a <see cref="JObject"/> that contains the policies.</returns> private static JToken GetBranchPolicies(IGitRepositoryInfo repository) { // Create the HttpClient that can be used to connect to TFS var context = GetTfsContext(); var client = new HttpClient(new HttpClientHandler { Credentials = context.TeamProjectCollection.Credentials }); client.BaseAddress = new Uri(context.TeamProjectCollection.Uri.ToString() + "/"); // Retrieve the policies var teamProjectId = context.TeamProjectUri.Segments.Last(); var response = client.GetAsync(teamProjectId + "/_apis/policy/configurations").Result; if (!response.IsSuccessStatusCode) { // Check if the response was 404 Not Found if (response.StatusCode == HttpStatusCode.NotFound) { // We'll assume that the Git repository is not hosted on a server that supports branch policies return null; } else { // An error occured throw new HttpRequestException("An error occurred while retrieving branch policies for repository " + repository.RepositoryPath + "."); } } // Parse the result var result = JObject.Parse(response.Content.ReadAsStringAsync().Result); return result["value"]; }
void CheckAndUpdate(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName != "ActiveRepositories") return; var service = GitService; if (service == null) return; var repo = service.ActiveRepositories.FirstOrDefault(); // this comparison is safe, the extension method supports null instances if (!repo.Compare(ActiveRepo)) // so annoying that this is on the wrong thread syncContext.Post(r => ActiveRepo = r as IGitRepositoryInfo, repo); }
async void UIContextChanged(bool active) { Debug.Assert(ServiceProvider != null, "UIContextChanged called before service provider is set"); if (ServiceProvider == null) return; if (active) { GitService = GitService ?? ServiceProvider.GetService<IGitExt>(); if (ActiveRepo == null) ActiveRepo = await System.Threading.Tasks.Task.Run(() => { var repos = GitService?.ActiveRepositories; // Looks like this might return null after a while, for some unknown reason // if it does, let's refresh the GitService instance in case something got wonky // and try again. See issue #23 if (repos == null) { VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error 2001: ActiveRepositories is null. GitService: '{0}'", GitService)); GitService = ServiceProvider?.GetService<IGitExt>(); repos = GitService?.ActiveRepositories; if (repos == null) VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error 2002: ActiveRepositories is null. GitService: '{0}'", GitService)); } return repos?.FirstOrDefault(); }); } else ActiveRepo = null; }
void UIContextChanged(object sender, UIContextChangedEventArgs e) { ActiveRepo = null; UIContextChanged(e.Activated); }
async void UIContextChanged(bool active) { Debug.Assert(ServiceProvider != null, "UIContextChanged called before service provider is set"); if (ServiceProvider == null) return; if (active) { GitService = GitService ?? ServiceProvider.GetService<IGitExt>(); if (ActiveRepo == null) ActiveRepo = await System.Threading.Tasks.Task.Run(() => GitService.ActiveRepositories.FirstOrDefault()); } else ActiveRepo = null; }