public GitSetupWindow(GitOptions gitOptions) { InitializeComponent(); DataContext = this; Canceled = true; GitOptions = gitOptions; }
public static GitOutputs InvokeWithOutput(BaseGitCommand command, GitOptions gitOptions = null) { var git = new Git(command, gitOptions); git.Start(true); git.WaitForExit(); return git._gitOutputs; }
public GitListArchiveRepository( ILogger <GitListArchiveRepository> logger, IOptions <GitOptions> gitOptions, IRepository repository) { _logger = logger; _options = gitOptions.Value; _repo = repository; }
public bool UseGit(GitOptions options) { var gitSelectionSuccess = SetCheckBox("useGitCheckBox", options.UseGit); if (gitSelectionSuccess && options.UseGit) { return(gitSelectionSuccess && SetCheckBox("createGitIgnoreFileCheckBox", options.UseGitIgnore)); } return(gitSelectionSuccess); }
private Git(BaseGitCommand command, GitOptions gitOptions) { if (gitOptions == null) gitOptions = new GitOptions(); _gitOptions = gitOptions; #if DEBUG _gitOptions.DisplayStandardOutput = true; #endif _command = command; }
public static Task DownloadSdk(GitOptions options) { return(Task.Run(async() => { var url = options.GitUrl + "/archive/development.zip"; var folderPath = options.RootFolder; var fileName = options.FileName.Replace(".zip", "") + "-development"; string zipPath, filePath; //if (!IsLinux) //{ zipPath = string.Format("{0}\\{1}", folderPath, fileName); filePath = string.Format("{0}.zip", zipPath); //} if (options.ReplaceExisting) { if (File.Exists(filePath)) { File.Delete(filePath); } if (Directory.Exists(zipPath)) { Directory.Delete(zipPath, true); } } using (var client = new HttpClient()) { var result = await client.GetAsync(url); result.EnsureSuccessStatusCode(); using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None)) { await result.Content.CopyToAsync(fileStream); fileStream.Close(); } } if (File.Exists(filePath)) { var unzip = new Unzip(filePath); unzip.ExtractToDirectory(folderPath); } })); }
public void ValidatePreviewTree(ProjectDetails projectDetails, GitOptions gitOptions) { var rootFolder = projectDetails.ProjectInSolution ? projectDetails.SolutionName : projectDetails.ProjectName; Func <AppQuery, AppQuery> solutionLocation = (c) => previewTree(c).Contains(projectDetails.SolutionLocation); Func <AppQuery, AppQuery> solutionLocationChildren = (c) => solutionLocation(c).Children(); Func <AppQuery, AppQuery> rootFolderChildren = (c) => solutionLocationChildren(c).Contains(rootFolder).Children(); Func <AppQuery, AppQuery> checkForGit = c => rootFolderChildren(c).Index(0).Contains("<span color='#AAAAAA'>.git</span>"); Func <AppQuery, AppQuery> checkForGitIgnore = c => rootFolderChildren(c).Index(1).Contains("<span color='#AAAAAA'>.gitignore</span>"); Assert.IsNotEmpty(Session.Query(c => solutionLocation(c))); Assert.IsNotEmpty(Session.Query(c => solutionLocation(c).Children().Contains(rootFolder))); if (gitOptions.UseGit) { Assert.IsNotEmpty(Session.Query(checkForGit)); if (gitOptions.UseGitIgnore) { Assert.IsNotEmpty(Session.Query(checkForGitIgnore)); } else { Assert.IsEmpty(Session.Query(checkForGitIgnore)); } } else { Assert.IsEmpty(Session.Query(checkForGit)); Assert.IsEmpty(Session.Query(checkForGitIgnore)); } Assert.IsNotEmpty(Session.Query(c => rootFolderChildren(c).Contains(projectDetails.SolutionName + ".sln"))); if (projectDetails.ProjectInSolution) { Assert.IsNotEmpty(Session.Query(c => rootFolderChildren(c).Contains(projectDetails.ProjectName))); Assert.IsNotEmpty(Session.Query(c => rootFolderChildren(c).Contains(projectDetails.ProjectName).Children().Contains(projectDetails.ProjectName + ".csproj"))); } else { Assert.IsNotEmpty(Session.Query(c => rootFolderChildren(c).Contains(projectDetails.ProjectName + ".csproj"))); } }
private static void BuildGit(GitOptions git) { var nugetSourceDir = Path.Combine(Environment.CurrentDirectory, ".nupkg_src"); CleanDirectory(nugetSourceDir); Console.Out.WriteLine($"Building NuGet packages from {git.Repository} {git.Branch}@{git.Commit}"); shell.Run("git", "clone", git.Repository, nugetSourceDir, "-b", git.Branch, "--single-branch", "--quiet") .RedirectTo(Console.Out) .RedirectStandardErrorTo(Console.Error) .Wait(); shell.Run("git", new[] { "checkout", git.Commit, "--quiet" }, options => options.WorkingDirectory(nugetSourceDir)) .RedirectTo(Console.Out) .RedirectStandardErrorTo(Console.Error).Wait(); BuildPackages(nugetSourceDir); }
public static async Task <GitReference> PushChangesAsync(IGitHubClient client, IGitOptionsHost options, string commitMessage, Func <GitHubBranch, Task <IEnumerable <GitObject> > > getChanges) { GitOptions gitOptions = options.GitOptions; GitHubProject project = new GitHubProject(gitOptions.Repo, gitOptions.Owner); GitHubBranch branch = new GitHubBranch(gitOptions.Branch, project); IEnumerable <GitObject> changes = await getChanges(branch); if (!changes.Any()) { return(null); } string masterRef = $"heads/{gitOptions.Branch}"; GitReference currentMaster = await client.GetReferenceAsync(project, masterRef); string masterSha = currentMaster.Object.Sha; if (!options.IsDryRun) { GitTree tree = await client.PostTreeAsync(project, masterSha, changes.ToArray()); GitCommit commit = await client.PostCommitAsync( project, commitMessage, tree.Sha, new[] { masterSha }); // Only fast-forward. Don't overwrite other changes: throw exception instead. return(await client.PatchReferenceAsync(project, masterRef, commit.Sha, force : false)); } else { Logger.WriteMessage($"The following files would have been updated at {gitOptions.Owner}/{gitOptions.Repo}/{gitOptions.Branch}:"); Logger.WriteMessage(); foreach (GitObject gitObject in changes) { Logger.WriteMessage($"{gitObject.Path}:"); Logger.WriteMessage(gitObject.Content); Logger.WriteMessage(); } return(null); } }
public AppOptions( string lastRootPath, string lastSelectedFilePath, bool wasEdited, CsvFile lastSelectedCsvFile, VisualConfig visulaConfig, SaveOptions saveOptions, GitOptions gitOptions, List <char> delimiters, List <char> blockIdentifiers, List <DirectoryWithCsv> lastCsvFilesStructure) { LastRootPath = lastRootPath; LastSelectedFilePath = lastSelectedFilePath; WasEdited = wasEdited; LastSelectedCsvFile = lastSelectedCsvFile; VisualConfig = visulaConfig; SaveOptions = saveOptions; GitOptions = gitOptions; Delimiters = delimiters; BlockIdentifiers = blockIdentifiers; LastCsvFilesStructure = lastCsvFilesStructure; }
public static Uri GetCommitUrl(GitOptions gitOptions, string sha) { return(new Uri($"https://github.com/{gitOptions.Owner}/{gitOptions.Repo}/commit/{sha}")); }
public static Uri GetBlobUrl(GitOptions gitOptions) { return(new Uri($"https://github.com/{gitOptions.Owner}/{gitOptions.Repo}/blob/{gitOptions.Branch}/{gitOptions.Path}")); }
public async Task PublishImageInfoCommand_ReplaceTags() { using (TempFolderContext tempFolderContext = TestHelper.UseTempFolder()) { string repo1Image1DockerfilePath = DockerfileHelper.CreateDockerfile("1.0/runtime/os", tempFolderContext); string repo2Image2DockerfilePath = DockerfileHelper.CreateDockerfile("2.0/runtime/os", tempFolderContext); Manifest manifest = CreateManifest( CreateRepo("repo1", CreateImage( CreatePlatform(repo1Image1DockerfilePath, new string[0]))), CreateRepo("repo2", CreateImage( CreatePlatform(repo2Image2DockerfilePath, new string[0]))) ); RepoData repo2; ImageArtifactDetails srcImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath, simpleTags: new List <string> { "newtag" }) } } } }, { repo2 = new RepoData { Repo = "repo2", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo2Image2DockerfilePath, simpleTags: new List <string> { "tag1" }) } } } } } } }; string file = Path.Combine(tempFolderContext.Path, "image-info.json"); File.WriteAllText(file, JsonHelper.SerializeObject(srcImageArtifactDetails)); ImageArtifactDetails targetImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath, simpleTags: new List <string> { "oldtag" }) } } } } } }; Mock <IGitHubClient> gitHubClientMock = GetGitHubClientMock(); Mock <IGitHubClientFactory> gitHubClientFactoryMock = new Mock <IGitHubClientFactory>(); gitHubClientFactoryMock .Setup(o => o.GetClient(It.IsAny <GitHubAuth>(), false)) .Returns(gitHubClientMock.Object); GitOptions gitOptions = new GitOptions { AuthToken = "token", Repo = "testRepo", Branch = "testBranch", Path = "imageinfo.json" }; PublishImageInfoCommand command = new PublishImageInfoCommand( gitHubClientFactoryMock.Object, Mock.Of <ILoggerService>(), CreateHttpClientFactory(gitOptions, targetImageArtifactDetails)); command.Options.ImageInfoPath = file; command.Options.GitOptions = gitOptions; command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); await command.ExecuteAsync(); ImageArtifactDetails expectedImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath, simpleTags: new List <string> { "newtag" }) } } } }, repo2 } }; Func <GitObject[], bool> verifyGitObjects = (gitObjects) => { if (gitObjects.Length != 1) { return(false); } return(gitObjects[0].Content.Trim() == JsonHelper.SerializeObject(expectedImageArtifactDetails).Trim()); }; gitHubClientMock.Verify( o => o.PostTreeAsync(It.IsAny <GitHubProject>(), It.IsAny <string>(), It.Is <GitObject[]>(gitObjects => verifyGitObjects(gitObjects)))); } }
public async Task PublishImageInfoCommand_ReplaceContent() { using (TempFolderContext tempFolderContext = TestHelper.UseTempFolder()) { string repo1Image1DockerfilePath = DockerfileHelper.CreateDockerfile("1.0/runtime/os", tempFolderContext); string repo2Image2DockerfilePath = DockerfileHelper.CreateDockerfile("2.0/runtime/os", tempFolderContext); Manifest manifest = CreateManifest( CreateRepo("repo1", CreateImage( new Platform[] { CreatePlatform(repo1Image1DockerfilePath, new string[] { "tag1" }) }, productVersion: "1.0")), CreateRepo("repo2", CreateImage( new Platform[] { CreatePlatform(repo2Image2DockerfilePath, new string[] { "tag1" }) }, productVersion: "2.0")) ); RepoData repo2; ImageArtifactDetails srcImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath, simpleTags: new List <string> { "newtag" }) }, ProductVersion = "1.0", Manifest = new ManifestData { SyndicatedDigests = new List <string> { "newdigest1", "newdigest2" } } } } }, { repo2 = new RepoData { Repo = "repo2", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo2Image2DockerfilePath, simpleTags: new List <string> { "tag1" }) }, ProductVersion = "2.0" } } } } } }; string file = Path.Combine(tempFolderContext.Path, "image-info.json"); File.WriteAllText(file, JsonHelper.SerializeObject(srcImageArtifactDetails)); ImageArtifactDetails targetImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath, simpleTags: new List <string> { "oldtag" }) }, ProductVersion = "1.0", Manifest = new ManifestData { SyndicatedDigests = new List <string> { "olddigest1", "olddigest2" } } } } } } }; GitOptions gitOptions = new GitOptions { AuthToken = "token", Repo = "PublishImageInfoCommand_ReplaceContent", Branch = "testBranch", Path = "imageinfo.json", Email = "*****@*****.**", Username = "******" }; AzdoOptions azdoOptions = new AzdoOptions { AccessToken = "azdo-token", AzdoBranch = "testBranch", AzdoRepo = "testRepo", Organization = "azdo-org", Project = "azdo-project", AzdoPath = "imageinfo.json" }; Mock <IRepository> repositoryMock = GetRepositoryMock(); Mock <IGitService> gitServiceMock = GetGitServiceMock(repositoryMock.Object, gitOptions.Path, targetImageArtifactDetails); string actualImageArtifactDetailsContents = null; gitServiceMock .Setup(o => o.Stage(It.IsAny <IRepository>(), It.IsAny <string>())) .Callback((IRepository repo, string path) => { actualImageArtifactDetailsContents = File.ReadAllText(path); }); PublishImageInfoCommand command = new PublishImageInfoCommand(gitServiceMock.Object, Mock.Of <ILoggerService>()); command.Options.ImageInfoPath = file; command.Options.GitOptions = gitOptions; command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); await command.ExecuteAsync(); ImageArtifactDetails expectedImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath, simpleTags: new List <string> { "newtag" }) }, ProductVersion = "1.0", Manifest = new ManifestData { SyndicatedDigests = new List <string> { "newdigest1", "newdigest2" } } } } }, repo2 } }; Assert.Equal(JsonHelper.SerializeObject(expectedImageArtifactDetails), actualImageArtifactDetailsContents.Trim()); VerifyMocks(repositoryMock); } }
public static void Invoke(BaseGitCommand command, GitOptions gitOptions = null) { var git = new Git(command, gitOptions); git.Start(false); git.WaitForExit(); }
public async Task PublishImageInfoCommand_RemoveOutOfDateContent() { using (TempFolderContext tempFolderContext = TestHelper.UseTempFolder()) { string repo1Image1DockerfilePath = DockerfileHelper.CreateDockerfile("1.0/runtime/os", tempFolderContext); string repo2Image2DockerfilePath = DockerfileHelper.CreateDockerfile("2.0/runtime/os", tempFolderContext); Manifest manifest = CreateManifest( CreateRepo("repo1", CreateImage( new Platform[] { CreatePlatform(repo1Image1DockerfilePath, new string[0]) }, productVersion: "1.0")), CreateRepo("repo2", CreateImage( new Platform[] { CreatePlatform(repo2Image2DockerfilePath, new string[0]) }, productVersion: "2.0")) ); manifest.Registry = "mcr.microsoft.com"; RepoData repo2; ImageArtifactDetails srcImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath) }, ProductVersion = "1.0" } } }, { repo2 = new RepoData { Repo = "repo2", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo2Image2DockerfilePath) }, ProductVersion = "2.0" } } } } } }; string file = Path.Combine(tempFolderContext.Path, "image-info.json"); File.WriteAllText(file, JsonHelper.SerializeObject(srcImageArtifactDetails)); ImageArtifactDetails targetImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath) }, ProductVersion = "1.0" }, new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform( DockerfileHelper.CreateDockerfile("1.0/runtime2/os", tempFolderContext)) }, ProductVersion = "1.0" } } }, new RepoData { Repo = "repo4" } } }; GitOptions gitOptions = new GitOptions { AuthToken = "token", Repo = "repo", Owner = "owner", Path = "imageinfo.json", Branch = "branch", Email = "*****@*****.**", Username = "******" }; AzdoOptions azdoOptions = new AzdoOptions { AccessToken = "azdo-token", Branch = "testBranch", Repo = "testRepo", Organization = "azdo-org", Project = "azdo-project", Path = "imageinfo.json" }; Mock <IRepository> repositoryMock = GetRepositoryMock(); Mock <IGitService> gitServiceMock = GetGitServiceMock(repositoryMock.Object, gitOptions.Path, targetImageArtifactDetails); PublishImageInfoCommand command = new PublishImageInfoCommand(gitServiceMock.Object, Mock.Of <ILoggerService>()); command.Options.ImageInfoPath = file; command.Options.GitOptions = gitOptions; command.Options.AzdoOptions = azdoOptions; command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); command.LoadManifest(); await command.ExecuteAsync(); ImageArtifactDetails expectedImageArtifactDetails = new ImageArtifactDetails { Repos = { new RepoData { Repo = "repo1", Images = { new ImageData { Platforms = { Helpers.ImageInfoHelper.CreatePlatform(repo1Image1DockerfilePath) }, ProductVersion = "1.0" } } }, repo2 } }; VerifyMocks(repositoryMock); } }