private void InitClick(object sender, EventArgs e) { var directoryPath = _NO_TRANSLATE_Directory.Text; if (!IsRootedDirectoryPath(directoryPath)) { MessageBox.Show(this, _chooseDirectory.Text, _chooseDirectoryCaption.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (File.Exists(directoryPath)) { MessageBox.Show(this, _chooseDirectoryNotFile.Text, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var module = new VsrModule(directoryPath); if (!System.IO.Directory.Exists(module.WorkingDir)) { System.IO.Directory.CreateDirectory(module.WorkingDir); } MessageBox.Show(this, module.Init(Central.Checked, Central.Checked), _initMsgBoxCaption.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); _gitModuleChanged?.Invoke(this, new VsrModuleEventArgs(module)); ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Locals.AddAsMostRecentAsync(directoryPath)); Close(); }
/// <summary> /// Creates a throw-away new repository in a temporary location. /// </summary> public GitModuleTestHelper(string repositoryName = "repo1") { TemporaryPath = GetTemporaryPath(); string path = Path.Combine(TemporaryPath, repositoryName); if (Directory.Exists(path)) { throw new ArgumentException($"Repository '{path}' already exists", nameof(repositoryName)); } Directory.CreateDirectory(path); var module = new VsrModule(path); module.Init(bare: false, shared: false); Module = module; // Don't assume global user/email Module.LocalConfigFile.SetString(SettingKeyString.UserName, "author"); Module.LocalConfigFile.SetString(SettingKeyString.UserEmail, "*****@*****.**"); Module.LocalConfigFile.FilesEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); Module.LocalConfigFile.Save(); return; string GetTemporaryPath() { var tempPath = Path.GetTempPath(); // workaround macOS symlinking its temp folder if (tempPath.StartsWith("/var")) { tempPath = "/private" + tempPath; } return(Path.Combine(tempPath, Path.GetRandomFileName())); } }