public void Save_WhenLastIssueFileExists_ShouldDeleteIt() { A.CallTo(() => m_file.Exists($@"{m_repositoryDirectory}\.git\gitarmor\issuetracker\lastissue")).Returns(true); m_lastIssue.Save("123"); A.CallTo(() => m_file.Delete($@"{m_repositoryDirectory}\.git\gitarmor\issuetracker\lastissue")) .MustHaveHappened(); }
public void Arm_WhenIsAlreadyArmed_ShouldDoNothing() { var configPath = Path.Combine(m_repositoryFolder, @".git\gitarmor\config"); A.CallTo(() => m_fs.Exists(configPath)).Returns(true); m_repository.Arm(); A.CallTo(() => m_repoConfigFactory.LoadOrCreate(A <string> .Ignored)) .MustNotHaveHappened(); }
public GitArmorRepositoryConfig LoadOrCreate(string repositoryFolder) { var configFilePath = Path.Combine(repositoryFolder, @".git\gitarmor\config"); if (!m_files.Exists(configFilePath)) { if (!m_dirs.Exists(Path.Combine(repositoryFolder, @".git\gitarmor"))) { m_dirs.CreateDirectory(Path.Combine(repositoryFolder, @".git\gitarmor")); } var jsonConfig = m_serializer.Serialize(new GitArmorRepositoryConfig()); using (var fw = m_files.CreateText(configFilePath)) { fw.WriteLine(jsonConfig); } } string serializedJson = null; using (var fr = m_files.OpenText(configFilePath)) { serializedJson = fr.ReadToEnd(); } return(m_serializer.Deserialize <GitArmorRepositoryConfig>(serializedJson)); }
public void Save(string issue) { var directory = Path.GetDirectoryName(m_lastIssueFile); if (!m_directoryUtilities.Exists(directory)) { m_directoryUtilities.CreateDirectory(directory); } if (m_fileUtilities.Exists(m_lastIssueFile)) { m_fileUtilities.Delete(m_lastIssueFile); } using (var stream = m_fileUtilities.CreateText(m_lastIssueFile)) { stream.WriteLine(issue); } }
public void Arm() { if (IsArmed) { return; } var preComitHookPath = Path.Combine(m_repositoryFolder, @".git\hooks\pre-commit"); if (m_files.Exists(preComitHookPath)) { throw new HooksAlreadyExistsException(); } m_repoConfigFactory.LoadOrCreate(m_repositoryFolder); var preCommitHookSourcePath = Path.Combine(m_application.GetApplicationDirectory(), @"Hooks\pre-commit"); m_files.Copy(preCommitHookSourcePath, preComitHookPath); }
/// <see cref="IFileUtilities.Exists(string)"/> public static bool Exists(string path) => s_fileUtilities.Exists(path);