public void RefreshAll() { //pull config yaml from remote ConfigProvider.PullConfigFromRemote( Config.Repositories, Path.GetDirectoryName(ConfigPathRepositories), Config.Credentials.Where(c => Config.Repositories.StartsWith(c.Url)).FirstOrDefault()); //load defined repositories from yaml file var repositoryConfigs = ConfigProvider.LoadRepositoryConfigsFromFile(ConfigPathRepositories); //pull repositories foreach (var repositoryConfig in repositoryConfigs) { try { var repositoryPath = Path.Combine(RepositoriesPath, repositoryConfig.Alias); var credentials = Config.Credentials.Where(c => repositoryConfig.Url.StartsWith(c.Url)).FirstOrDefault(); GitProvider.PullFromRemote(repositoryConfig.Url, repositoryPath, credentials); } catch (Exception ex) { logger.WarnFormat(ex.Message); } } //load from file system repositories = ConfigProvider.LoadRepositoriesFromFilesystem(RepositoriesPath, repositoryConfigs); }
private ChangeSetHistory GetRawHistory(string repoName) { using (var cache = new Cache()) { var provider = new GitProvider(); provider.Initialize(RepoBuilder.GetRepoPath(repoName), cache.ToString(), null); var(history, graph) = provider.GetRawHistory(null); return(history); } }
private ChangeSetHistory GetCleanHistory(string repoName) { using (var cache = new Cache()) { var provider = new GitProvider(); provider.Initialize(RepoBuilder.GetRepoPath(repoName), cache.ToString(), null); provider.UpdateCache(null, false, null); return(provider.QueryChangeSetHistory()); } }
static void Main(string[] args) { // Setup _defaultLogger = LogManager.GetLogger("Default"); EnsureWorkingAreaExists(); // Parse command line options CommandLineOptions options = new CommandLineOptions(); Parser.Default.ParseArguments(args, options); Job currentJob = JobHelper.GetJob(options.JobId, _defaultLogger); if (currentJob == null) { ExitProgramWithError("Job not found"); } // Intialise deployment context. DeploymentContext deploymentContext = DeploymentContextFactory.CreateContextForJob(currentJob); _statusUpdater = new DeploymentStatusUpdater(deploymentContext); // Checkout code from source control _statusUpdater.UpdateStatus(DeploymentStatuses.VscCheckout); GitProvider gitProvider = new GitProvider(deploymentContext); bool checkoutSuccess = gitProvider.Checkout(); if (!checkoutSuccess) { ExitProgramWithError("Git checkout was unsuccessful.", currentJob); } // Load deployment conifguration bool configLoadSuccess = ConfigLoader.LoadConfigurationIntoContext(deploymentContext); if (!configLoadSuccess) { ExitProgramWithError("Could not load configuration", currentJob); } // Run Tasks bool taskRunResult = DeploymentTaskRunner.RunTasks(deploymentContext, _statusUpdater); if (taskRunResult) { _statusUpdater.Dispose(); JobHelper.MarkJobAsComplete(currentJob); } else { ExitProgramWithError("Task did not complete.", currentJob); } }
public void CreateBranchTest() { //Assert.Inconclusive("This test accesses file system."); var project = new Mock <VBProject>(); var repo = new Repository("SourceControlTest", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SourceControlTest"), @"https://github.com/ckuhn203/SourceControlTest.git" ); var git = new GitProvider(project.Object); git = new GitProvider(project.Object, git.Clone(repo.RemoteLocation, repo.LocalLocation), new CodePaneWrapperFactory()); git.CreateBranch("NewBranch"); Assert.AreEqual("NewBranch", git.CurrentBranch); }
public void CloneCreatesLocalRepo() { //Assert.Inconclusive("This test accesses file system."); //arrange var project = new Mock <VBProject>(); var expected = new Repository("SourceControlTest", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SourceControlTest"), @"https://github.com/ckuhn203/SourceControlTest.git" ); var git = new GitProvider(project.Object); //act var actual = git.Clone(expected.RemoteLocation, expected.LocalLocation); //assert Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.LocalLocation, actual.LocalLocation); Assert.AreEqual(expected.RemoteLocation, actual.RemoteLocation); Assert.IsTrue(Directory.Exists(Path.Combine(expected.LocalLocation, ".git"))); }
public void LastUpdatedFilesTest() { var storageMock = new Mock <RepositoryStorage>(); var executorMock = new Mock <ScriptExecutor>(); var gitMock = new Mock <LibGit2SharpWrapper>(); var provider = new GitProvider(storageMock.Object, executorMock.Object, gitMock.Object); Repository repository = new Repository(); repository.Id = "1"; repository.Url = "fakeurl"; var path = Path.Combine("/", repository.Id); storageMock.Setup(i => i.Combine(repository.Id)).Returns(path); executorMock.Setup(i => i.ExecuteCommon("LastUpdatedFiles", path)).Returns(""); var result = provider.LastUpdatedFiles(repository); Assert.Empty(result); }
public void InitVBAProjectIntitializesRepo() { //Assert.Inconclusive("This test accesses file system."); //arrange var component = new Mock <VBComponent>(); component.Setup(c => c.Name).Returns("Module1"); component.Setup(c => c.Type).Returns(vbext_ComponentType.vbext_ct_StdModule); component.Setup(c => c.Export("foo")).Verifiable(); var componentList = new List <VBComponent> { component.Object }; var components = new Mock <VBComponents>(); components.Setup(c => c.GetEnumerator()).Returns(componentList.GetEnumerator()); var project = new Mock <VBProject>(); project.Setup(p => p.VBComponents).Returns(components.Object); project.Setup(p => p.Name).Returns("SourceControlTest"); //act var git = new GitProvider(project.Object); git.InitVBAProject(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); //assert Assert.AreEqual(project.Object.Name, git.CurrentRepository.Name); var repoDir = Path.Combine(git.CurrentRepository.LocalLocation, ".git"); Assert.IsTrue(Directory.Exists(repoDir), "Repo directory does not exist."); }
public CommandCreateBranch(VBProject project, RepositorySettings repoSettings) : base(project) { Provider = new GitProvider(project, repoSettings); }
public CommandInit(VBProject project) : base(project) { Provider = new GitProvider(VBProject); }
public CommandCommit(VBProject project, RepositorySettings repoSettings, IEnumerable <string> components) : base(project) { Provider = new GitProvider(project, repoSettings); Components = components; }
/// <summary> /// The main entry point for the application. /// </summary> //[STAThread] static int Main(string[] args) { Params param = null; Parser.Default.ParseArguments <Params>(args) .WithParsed(opts => param = opts) .WithNotParsed(PrintErrorAndExit); Log.Logger = MakeLogger(param.Verbose); Log.Information("Vault2Git -- converting history from Vault repositories to Git"); Console.InputEncoding = System.Text.Encoding.UTF8; Configuration configuration; // First look for Config file in the current directory - allows for repository-based config files var configPath = Path.Combine(Environment.CurrentDirectory, "Vault2Git.exe.config"); if (File.Exists(configPath)) { var configFileMap = new ExeConfigurationFileMap { ExeConfigFilename = configPath }; configuration = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None); } else { // Get normal exe file config. // This is what happens by default when using ConfigurationManager.AppSettings["setting"] // to access config properties var applicationName = Environment.GetCommandLineArgs()[0]; #if !DEBUG applicationName += ".exe"; #endif configPath = Path.Combine(Environment.CurrentDirectory, applicationName); configuration = ConfigurationManager.OpenExeConfiguration(configPath); } Log.Information($"Using config file {configPath}"); // Get access to the AppSettings properties in the chosen config file param.ApplyAppConfigIfParamNotPresent((AppSettingsSection)configuration.GetSection("appSettings")); var git2VaultRepoPaths = param.Paths.ToDictionary(pair => RemoveTrailingSlash(pair.Split('~')[1]), pair => RemoveTrailingSlash(pair.Split('~')[0])); if (!git2VaultRepoPaths.Keys.All(p => param.Branches.Contains(p))) { Console.Error.WriteLine($"Config git branches ({string.Join(",", git2VaultRepoPaths.Keys)}) are not a superset of branches ({string.Join(",", param.Branches)})"); return(-2); } param.Branches = git2VaultRepoPaths.Keys; // check working folder ends with trailing slash if (param.WorkingFolder.Last() != '\\') { param.WorkingFolder += '\\'; } Log.Information(param.ToString()); var git = new GitProvider(param.WorkingFolder, param.GitCmd, param.GitDomainName, param.SkipEmptyCommits, param.IgnoreGitIgnore); var vault = new VaultProvider(param.VaultServer, param.VaultRepo, param.VaultUser, param.VaultPassword); var processor = new Processor(git, vault, param.Directories.ToList(), param.Limit, param.DoGitPushOrigin, param.SampleTimeWhenNoFullPathAvailable, param.BeginDate) { WorkingFolder = param.WorkingFolder, ForceFullFolderGet = param.ForceFullFolderGet }; var git2VaultRepoPathsSubset = new Dictionary <string, string>(); foreach (var branch in param.Branches) { git2VaultRepoPathsSubset[branch] = git2VaultRepoPaths[branch]; } if (param.RunContinuously) { var consecutiveErrorCount = 0; var cancelKeyPressed = false; Console.CancelKeyPress += delegate { cancelKeyPressed = true; Log.Information("Stop process requested"); }; var nextRun = DateTime.UtcNow; do { if (nextRun <= DateTime.UtcNow) { try { processor.Pull(git2VaultRepoPathsSubset); consecutiveErrorCount = 0; } catch (Exception e) { Log.Warning($"Exception caught while pulling in new versions from vault. Current consecutive exception count: {consecutiveErrorCount}.\n{e}"); } nextRun = DateTime.UtcNow.AddMinutes(1); Log.Information($"Next run scheduled for {nextRun:u}"); } Thread.Sleep(TimeSpan.FromSeconds(1)); } while (!cancelKeyPressed); } else { processor.Pull(git2VaultRepoPathsSubset); } if (!param.IgnoreLabels) { processor.CreateTagsFromLabels(); } return(0); }