public static async Task UpdateGitIgnore(string repoPath) { var path = Path.Combine(repoPath, ".gitignore"); var encoding = GetEncoding(path); await GetLatestIgnoreFile(); SolutionExtensions.WriteMessageToOutputPane("Updating .gitignore file"); var text = await BuildNewIgnoreFile(repoPath,path, encoding); await WriteTextAsync(path, text, FileMode.Create, encoding); SolutionExtensions.WriteMessageToOutputPane("Updating .gitignore done!"); }
public static string GetThemeId() { var version = SolutionExtensions.GetActiveIDE().Version; const string CategoryName = "General"; const string ThemePropertyName = "CurrentTheme"; if (version == "14.0") { string keyName = String.Format( @"Software\Microsoft\VisualStudio\{0}\ApplicationPrivateSettings\Microsoft\VisualStudio", version); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName)) { if (key != null) { var keyText = (string)key.GetValue("ColorTheme", String.Empty); if (!String.IsNullOrEmpty(keyText)) { var keyTextValues = keyText.Split('*'); if (keyTextValues.Length > 2) { return(keyTextValues[2]); } } } } return(null); } else { string keyName = String.Format(@"Software\Microsoft\VisualStudio\{0}\{1}", version, CategoryName); using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName)) { if (key != null) { return((string)key.GetValue(ThemePropertyName, String.Empty)); } } return(null); } }
private static async Task GetLatestIgnoreFile() { var workingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var path = Path.Combine(workingPath, "VisualStudio.gitignore"); try { SolutionExtensions.WriteMessageToOutputPane("Getting Latest ignore file from github"); using (WebClient client = new WebClient()) { await client.DownloadFileTaskAsync(new Uri("https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore"), path); SolutionExtensions.WriteMessageToOutputPane("Success"); } } catch (Exception) { SolutionExtensions.WriteMessageToOutputPane("Download Failed"); } }
private static async Task<string> BuildNewIgnoreFile(string repoPath, string ignorePath, Encoding encoding) { StringBuilder sb = new StringBuilder(); sb.AppendLine(HEADER1); sb.AppendLine(HEADER2); sb.AppendLine(HEADER3); var workingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var path = Path.Combine(workingPath, "VisualStudio.gitignore"); if (!File.Exists(path)) { SolutionExtensions.WriteMessageToOutputPane("Updated .ignorefile not found, using cached ignore file"); path = Path.Combine(workingPath, "Resources\\VisualStudio.gitignore"); } var mainBody = File.ReadAllText(path); sb.Append(mainBody); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(IGNORESECTION); sb.AppendLine(); if (HasGitIgnore(repoPath)) { var linesToAdd = await GetCustomAllLinesAsync(ignorePath, encoding); if (linesToAdd?.Count > 0) { int start = string.IsNullOrWhiteSpace(linesToAdd[0]) ? 1: 0; for (int i = start; i < linesToAdd.Count; i++) { sb.AppendLine(linesToAdd[i]); } } } return sb.ToString(); }
public static async Task InitRepo(string solutionFile) { var solutionPath = Path.GetDirectoryName(solutionFile); SolutionExtensions.WriteMessageToOutputPane("Creating Repo"); GitRepository.Init(solutionPath); SolutionExtensions.WriteMessageToOutputPane("Repo Created"); SolutionExtensions.WriteMessageToOutputPane("Adding .gitignore file"); await IgnoreFileManager.UpdateGitIgnore(solutionPath); //File.WriteAllText(Path.Combine(solutionPath, ".tfignore"), @"\.git"); RepositoryManager.Instance.Clear(); Thread.Sleep(1000); var repo = RepositoryManager.Instance.GetTrackerForPath(solutionFile); if (repo != null) { repo.AddFile(Path.Combine(solutionPath, ".gitignore")); repo.AddFile(solutionFile); } }