private string GetDefaultRepoLocalPathValue(IExecutionContext executionContext, IList<Pipelines.JobStep> steps, TrackingConfig trackingConfig, RepositoryInfo repoInfo) { string selfRepoPath = null; // For saving backward compatibility with the behavior of the Build.RepoLocalPath that was before this PR https://github.com/microsoft/azure-pipelines-agent/pull/3237 // We need to change how we set the default value of this variable // We need to allow the setting of paths from RepositoryTrackingInfo for checkout tasks where path input was provided by the user // and this input is not point to the default location for this repository // This is the only case where the value of Build.RepoLocalPath variable is not pointing to the root of sources directory /s. // The new logic is not affecting single checkout jobs and jobs with multiple checkouts and default paths for Self repository if (RepositoryUtil.HasMultipleCheckouts(executionContext.JobSettings)) { // get checkout task for self repo var selfCheckoutTask = GetSelfCheckoutTask(steps); // Check if the task has path input with custom path, if so we need to set as a value of selfRepoPath the value of SourcesDirectory from RepositoryTrackingInfo if (IsCheckoutToCustomPath(trackingConfig, repoInfo, selfCheckoutTask)) { selfRepoPath = trackingConfig.RepositoryTrackingInfo .Where(repo => RepositoryUtil.IsPrimaryRepositoryName(repo.Identifier)) .Select(props => props.SourcesDirectory).FirstOrDefault(); } } // For single checkout jobs and multicheckout jobs with default paths set selfRepoPath to the default sources directory if (selfRepoPath == null) { selfRepoPath = trackingConfig.SourcesDirectory; } return selfRepoPath; }
public void GetCloneDirectory_REPO_should_return_proper_value_when_called() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); var repo = new RepositoryResource() { Alias = "alias", Id = "repo1", Type = "git", Url = null, }; // If name is not set and url is not set, then it should use alias Assert.Equal("alias", RepositoryUtil.GetCloneDirectory(repo)); // If url is set, it should choose url over alias repo.Url = new Uri("https://[email protected]/jpricket/MyFirstProject/_git/repo1_url"); Assert.Equal("repo1_url", RepositoryUtil.GetCloneDirectory(repo)); // If name is set, it should choose name over alias or url repo.Properties.Set(RepositoryPropertyNames.Name, "MyFirstProject/repo1_name"); Assert.Equal("repo1_name", RepositoryUtil.GetCloneDirectory(repo)); } }
private TaskStep GetSelfCheckoutTask(IList<JobStep> steps) { return steps.Select(x => x as TaskStep) .Where(task => task.IsCheckoutTask() && task.Inputs.TryGetValue(PipelineConstants.CheckoutTaskInputs.Repository, out string repositoryAlias) && RepositoryUtil.IsPrimaryRepositoryName(repositoryAlias)).FirstOrDefault(); }
private string GetDefaultRepositoryPath( IExecutionContext executionContext, RepositoryResource repository, TrackingConfig newConfig ) { string repoPath = String.Empty; string workDirectory = HostContext.GetDirectory(WellKnownDirectory.Work); if (RepositoryUtil.HasMultipleCheckouts(executionContext.JobSettings)) { // If we have multiple checkouts they should all be rooted to the sources directory (_work/1/s/repo1) var repoSourceDirectory = newConfig?.RepositoryTrackingInfo.Where(item => string.Equals(item.Identifier, repository.Alias, StringComparison.OrdinalIgnoreCase)).Select(item => item.SourcesDirectory).FirstOrDefault(); if (repoSourceDirectory != null) { repoPath = Path.Combine(workDirectory, repoSourceDirectory); } else { repoPath = Path.Combine(workDirectory, newConfig.SourcesDirectory, RepositoryUtil.GetCloneDirectory(repository)); } } else { // For single checkouts, the repository is rooted to the sources folder (_work/1/s) repoPath = Path.Combine(workDirectory, newConfig.SourcesDirectory); } return(repoPath); }
public void GetRepository_should_return_correct_value_when_called() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); var repo1 = new RepositoryResource { Alias = "repo1", Id = "repo1", Type = "git", }; var repo2 = new RepositoryResource { Alias = "repo2", Id = "repo2", Type = "git", }; var repoSelf = new RepositoryResource { Alias = "self", Id = "repo3", Type = "git", }; Assert.Equal(repo1, RepositoryUtil.GetRepository(new[] { repo1, repo2 }, "repo1")); Assert.Equal(repo2, RepositoryUtil.GetRepository(new[] { repo1, repo2 }, "repo2")); Assert.Equal(repo1, RepositoryUtil.GetRepository(new[] { repoSelf, repo1, repo2 }, "repo1")); Assert.Equal(repo2, RepositoryUtil.GetRepository(new[] { repoSelf, repo1, repo2 }, "repo2")); Assert.Equal(repoSelf, RepositoryUtil.GetRepository(new[] { repoSelf, repo1, repo2 }, "self")); Assert.Equal(null, RepositoryUtil.GetRepository(new[] { repoSelf, repo1, repo2 }, "unknown")); } }
public Character LoadEntity(long id) { using (IDbConnection dbConnection = new SQLiteConnection(RepositoryUtil.LoadConnectionString())) { return(dbConnection.QuerySingleOrDefault <Character>("Select * From Characters Where Id = @Id", new { Id = id })); } }
public TrackingConfig( IExecutionContext executionContext, IList <RepositoryResource> repositories, int buildDirectory) : this() { ArgUtil.NotNull(executionContext, nameof(executionContext)); ArgUtil.NotNull(repositories, nameof(repositories)); // Get the repo that we are going to checkout first to create the tracking info from. var primaryRepository = RepositoryUtil.GetPrimaryRepository(repositories); // Set the directories. BuildDirectory = buildDirectory.ToString(CultureInfo.InvariantCulture); ArtifactsDirectory = Path.Combine(BuildDirectory, Constants.Build.Path.ArtifactsDirectory); SourcesDirectory = Path.Combine(BuildDirectory, Constants.Build.Path.SourcesDirectory); TestResultsDirectory = Path.Combine(BuildDirectory, Constants.Build.Path.TestResultsDirectory); // Set the other properties. CollectionId = executionContext.Variables.System_CollectionId; DefinitionId = executionContext.Variables.System_DefinitionId; RepositoryUrl = primaryRepository?.Url.AbsoluteUri; RepositoryType = primaryRepository?.Type; System = BuildSystem; UpdateJobRunProperties(executionContext); foreach (var repo in repositories) { RepositoryTrackingInfo.Add(new Build.RepositoryTrackingInfo(repo, SourcesDirectory)); } // Now that we have all the repositories set up, we can compute the config hash HashKey = TrackingConfigHashAlgorithm.ComputeHash(CollectionId, DefinitionId, RepositoryTrackingInfo); }
public bool TryGetCopiedCommit(Commit copiedFrom, Repository targetRepo, out Commit?commit) { var hash = CommitMessageUtil.ReadBasedirCommitNameFromMessage(copiedFrom.Message); if (hash != null) { // TODO: make option: remote name commit = targetRepo.Lookup <Commit>(hash); if (commit != null) { return(true); } CommandGit.ShallowFetch(targetRepo, "origin", hash.Sha); commit = targetRepo.Lookup <Commit>(hash); if (commit != null) { return(true); } return(false); } else { commit = RepositoryUtil.GetAllCommits(targetRepo) .FirstOrDefault(copied => CommitMessageUtil.ReadSubdirCommitNameFromMessage(copied.Message, _copyOptions.DirInSrcs) == copiedFrom.Id); if (commit != null) { return(true); } return(false); } }
public bool TryGetCopiedCommit(Commit copiedFrom, Repository targetRepo, out Commit?commit) { commit = RepositoryUtil.GetAllCommits(targetRepo) .FirstOrDefault(copied => CommitMessageUtil.ReadBasedirCommitNameFromMessage(copied.Message) == copiedFrom.Id); return(commit != null); }
public void Execute(IExecutionContext context, Command command) { var eventProperties = command.Properties; var data = command.Data; String alias; if (!eventProperties.TryGetValue(PluginInternalUpdateRepositoryEventProperties.Alias, out alias) || String.IsNullOrEmpty(alias)) { throw new Exception(StringUtil.Loc("MissingRepositoryAlias")); } var repository = context.Repositories.FirstOrDefault(x => string.Equals(x.Alias, alias, StringComparison.OrdinalIgnoreCase)); if (repository == null) { throw new Exception(StringUtil.Loc("RepositoryNotExist")); } if (string.IsNullOrEmpty(data)) { throw new Exception(StringUtil.Loc("MissingRepositoryPath")); } var currentPath = repository.Properties.Get <string>(RepositoryPropertyNames.Path); if (!string.Equals(data.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), currentPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), IOUtil.FilePathStringComparison)) { string repositoryPath = data.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); repository.Properties.Set <string>(RepositoryPropertyNames.Path, repositoryPath); bool isSelfRepo = RepositoryUtil.IsPrimaryRepositoryName(repository.Alias); bool hasMultipleCheckouts = RepositoryUtil.HasMultipleCheckouts(context.JobSettings); if (isSelfRepo || !hasMultipleCheckouts) { var directoryManager = context.GetHostContext().GetService <IBuildDirectoryManager>(); string _workDirectory = context.GetHostContext().GetDirectory(WellKnownDirectory.Work); var trackingConfig = directoryManager.UpdateDirectory(context, repository); if (hasMultipleCheckouts) { // In Multi-checkout, we don't want to reset sources dir or default working dir. // So, we will just reset the repo local path string buildDirectory = context.Variables.Get(Constants.Variables.Pipeline.Workspace); string repoRelativePath = directoryManager.GetRelativeRepositoryPath(buildDirectory, repositoryPath); context.SetVariable(Constants.Variables.Build.RepoLocalPath, Path.Combine(_workDirectory, repoRelativePath), isFilePath: true); } else { // If we only have a single repository, then update all the paths to point to it. context.SetVariable(Constants.Variables.Build.SourcesDirectory, repositoryPath, isFilePath: true); context.SetVariable(Constants.Variables.Build.RepoLocalPath, repositoryPath, isFilePath: true); context.SetVariable(Constants.Variables.System.DefaultWorkingDirectory, repositoryPath, isFilePath: true); } } } repository.Properties.Set("__AZP_READY", bool.TrueString); }
public void Insert(Character entity) { using (IDbConnection dbConnection = new SQLiteConnection(RepositoryUtil.LoadConnectionString())) { string insertQuery = "INSERT INTO Characters(Name, Player, Age, Gender, Alignment) VALUES (@Name, @Player, @Age, @Gender, @Alignment)"; dbConnection.Execute(insertQuery, entity); } }
public ObservableCollection <Character> LoadEntityCollection() { using (IDbConnection dbConnection = new SQLiteConnection(RepositoryUtil.LoadConnectionString())) { var output = dbConnection.Query <Character>("Select * From Characters"); return(new ObservableCollection <Character>(output)); } }
public void GetCloneDirectory_STRING_should_return_proper_value_when_called() { // These test cases were inspired by the test cases that git.exe uses // see https://github.com/git/git/blob/53f9a3e157dbbc901a02ac2c73346d375e24978c/t/t5603-clone-dirname.sh#L21 using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); // basic syntax with bare and non-bare variants Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo.git")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo/.git")); // similar, but using ssh URL rather than host:path syntax Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo.git")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo/.git")); // we should remove trailing slashes and .git suffixes Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo///")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo/.git/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo.git/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo.git///")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo///.git/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("ssh://host/foo/.git///")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo///")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo.git/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo/.git/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo.git///")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo///.git/")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo/.git///")); Assert.Equal("foo", RepositoryUtil.GetCloneDirectory("host:foo/.git///")); Assert.Equal("repo", RepositoryUtil.GetCloneDirectory("host:foo/repo")); // omitting the path should default to the hostname Assert.Equal("host", RepositoryUtil.GetCloneDirectory("ssh://host/")); Assert.Equal("host", RepositoryUtil.GetCloneDirectory("ssh://*****:*****@host/")); Assert.Equal("host", RepositoryUtil.GetCloneDirectory("host:/")); // auth materials should be redacted Assert.Equal("host", RepositoryUtil.GetCloneDirectory("ssh://*****:*****@host/")); Assert.Equal("host", RepositoryUtil.GetCloneDirectory("ssh://*****:*****@host:1234/")); Assert.Equal("host", RepositoryUtil.GetCloneDirectory("ssh://*****:*****@rd@host:1234/")); Assert.Equal("host", RepositoryUtil.GetCloneDirectory("user@host:/")); Assert.Equal("host", RepositoryUtil.GetCloneDirectory("user:password@host:/")); Assert.Equal("host", RepositoryUtil.GetCloneDirectory("user:passw@rd@host:/")); // trailing port-like numbers should not be stripped for paths Assert.Equal("1234", RepositoryUtil.GetCloneDirectory("ssh://*****:*****@host/test:1234")); Assert.Equal("1234", RepositoryUtil.GetCloneDirectory("ssh://*****:*****@host/test:1234.git")); } }
private TrackingConfig LoadIfExists( IExecutionContext executionContext, string file) { Trace.Entering(); Trace.Verbose($"Loading {file}"); // The tracking config will not exist for a new definition. if (!File.Exists(file)) { Trace.Verbose($"Tracking file does not exist: {file}"); return(null); } TrackingConfig result = null; // Load the content and distinguish between tracking config file // version 1 and file version 2. string content = File.ReadAllText(file); string fileFormatVersionJsonProperty = StringUtil.Format( @"""{0}""", TrackingConfig.FileFormatVersionJsonProperty); if (content.Contains(fileFormatVersionJsonProperty)) { // The config is the new format. Trace.Verbose("Parsing new tracking config format."); result = JsonConvert.DeserializeObject <TrackingConfig>(content); } else { // Attempt to parse the legacy format. Trace.Verbose("Parsing legacy tracking config format."); var legacyTrackingConfig = LegacyTrackingConfig.TryParse(content); if (legacyTrackingConfig == null) { executionContext.Warning(StringUtil.Loc("UnableToParseBuildTrackingConfig0", content)); } else { // Convert legacy format to the new format. result = ConvertToNewFormat( executionContext, legacyTrackingConfig, RepositoryUtil.GetCloneDirectory(legacyTrackingConfig.RepositoryUrl), RepositoryUtil.GuessRepositoryType(legacyTrackingConfig.RepositoryUrl)); } } if (result != null) { result.FileLocation = file; } return(result); }
public void GetCloneDirectory_STRING_should_throw_on_null() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); Assert.Throws <ArgumentNullException>(() => RepositoryUtil.GetCloneDirectory((string)null)); } }
public RepositoryTrackingInfo(RepositoryResource repositoryResource, string sourcesDirectoryRoot) { if (repositoryResource != null) { Identifier = repositoryResource.Alias; RepositoryType = repositoryResource.Type; RepositoryUrl = repositoryResource.Url.AbsoluteUri; SourcesDirectory = Path.Combine(sourcesDirectoryRoot, RepositoryUtil.GetCloneDirectory(repositoryResource)); } }
public void Delete(Character entity) { using (IDbConnection dbConnection = new SQLiteConnection(RepositoryUtil.LoadConnectionString())) { string deleteQuery = "Delete From Characters WHERE Id = @Id"; dbConnection.Execute(deleteQuery, new { entity.Id }); } }
private bool IsCheckoutToCustomPath(TrackingConfig trackingConfig, RepositoryInfo repoInfo, TaskStep selfCheckoutTask) { string path; string selfRepoName = RepositoryUtil.GetCloneDirectory(repoInfo.PrimaryRepository.Properties.Get<string>(Pipelines.RepositoryPropertyNames.Name)); string defaultRepoCheckoutPath = Path.GetFullPath(Path.Combine(trackingConfig.SourcesDirectory, selfRepoName)); return selfCheckoutTask != null && selfCheckoutTask.Inputs.TryGetValue(PipelineConstants.CheckoutTaskInputs.Path, out path) && !string.Equals(Path.GetFullPath(Path.Combine(trackingConfig.BuildDirectory, path)), defaultRepoCheckoutPath, IOUtil.FilePathStringComparison); }
public void TrimStandardBranchPrefix_should_return_correct_values() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); Assert.Equal(null, RepositoryUtil.TrimStandardBranchPrefix(null)); Assert.Equal("", RepositoryUtil.TrimStandardBranchPrefix("")); Assert.Equal("refs/branchName", RepositoryUtil.TrimStandardBranchPrefix("refs/branchName")); Assert.Equal("branchName", RepositoryUtil.TrimStandardBranchPrefix("refs/heads/branchName")); } }
public void GetRepositoryForLocalPath_should_return_correct_values() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); var repo1 = new RepositoryResource { Alias = "repo1", Id = "repo1", Type = "git", }; repo1.Properties.Set(RepositoryPropertyNames.Path, Path.Combine("root", "1", "s", "repo1")); var repo2 = new RepositoryResource { Alias = "repo2", Id = "repo2", Type = "git", }; repo2.Properties.Set(RepositoryPropertyNames.Path, Path.Combine("root", "1", "s", "repo2")); var repo3 = new RepositoryResource { Alias = "repo3", Id = "repo3", Type = "git", }; // repo3 has no path // Make sure null is returned if nothing matches or inputs are invalid Assert.Equal(null, RepositoryUtil.GetRepositoryForLocalPath(null, null)); Assert.Equal(null, RepositoryUtil.GetRepositoryForLocalPath(null, Path.Combine("root", "1", "s", "not_a_repo"))); Assert.Equal(null, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, null)); Assert.Equal(null, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, "not a path")); Assert.Equal(null, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, Path.Combine("root", "1", "s", "not_a_repo"))); Assert.Equal(null, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, Path.Combine("root", "1", "s"))); Assert.Equal(null, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, Path.Combine("root", "1", "s", "repo3"))); // Make sure the first repo is returned if there is only one Assert.Equal(repo1, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1 }, Path.Combine("root", "1", "s", "not_a_repo"))); Assert.Equal(repo2, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo2 }, "not a path")); Assert.Equal(repo3, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo3 }, "not a path")); // Make sure the matching repo is returned if there is more than one Assert.Equal(repo1, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, Path.Combine("root", "1", "s", "repo1"))); Assert.Equal(repo1, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, Path.Combine("root", "1", "s", "repo1", "sub", "path", "file.txt"))); Assert.Equal(repo2, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, Path.Combine("root", "1", "s", "repo2"))); Assert.Equal(repo2, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo1, repo2, repo3 }, Path.Combine("root", "1", "s", "repo2", "sub", "path", "file.txt"))); Assert.Equal(repo2, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo3, repo1, repo2 }, Path.Combine("root", "1", "s", "repo2"))); Assert.Equal(repo2, RepositoryUtil.GetRepositoryForLocalPath(new[] { repo3, repo1, repo2 }, Path.Combine("root", "1", "s", "repo2", "sub", "path", "file.txt"))); } }
private bool TryGetRepositoryInfoFromLocalPath(IExecutionContext executionContext, string localPath, out RepositoryInfo repoInfo) { // Return the matching repository resource and its source provider. Trace.Entering(); var repo = RepositoryUtil.GetRepositoryForLocalPath(executionContext.Repositories, localPath); repoInfo = new RepositoryInfo { PrimaryRepository = repo, SourceProvider = GetSourceProvider(executionContext, repo), }; return repoInfo.SourceProvider != null; }
public void IsPrimaryRepositoryName_should_work_correctly() { using (TestHostContext hc = new TestHostContext(this)) { Assert.Equal(false, RepositoryUtil.IsPrimaryRepositoryName(null)); Assert.Equal(false, RepositoryUtil.IsPrimaryRepositoryName("")); Assert.Equal(false, RepositoryUtil.IsPrimaryRepositoryName("none")); Assert.Equal(false, RepositoryUtil.IsPrimaryRepositoryName("some random string")); Assert.Equal(true, RepositoryUtil.IsPrimaryRepositoryName("self")); Assert.Equal(true, RepositoryUtil.IsPrimaryRepositoryName("SELF")); Assert.Equal(true, RepositoryUtil.IsPrimaryRepositoryName("Self")); Assert.Equal(true, RepositoryUtil.IsPrimaryRepositoryName("sELF")); } }
private bool TryGetRepositoryInfo(IExecutionContext executionContext, out RepositoryInfo repoInfo) { // Return the matching repository resource and its source provider. Trace.Entering(); var repo = RepositoryUtil.GetPrimaryRepository(executionContext.Repositories); repoInfo = new RepositoryInfo { Repository = repo, SourceProvider = GetSourceProvider(executionContext, repo), }; return(repoInfo.SourceProvider != null); }
public void HasMultipleCheckouts_should_not_throw() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); Assert.Equal(false, RepositoryUtil.HasMultipleCheckouts(null)); var dict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); Assert.Equal(false, RepositoryUtil.HasMultipleCheckouts(dict)); dict.Add("x", "y"); Assert.Equal(false, RepositoryUtil.HasMultipleCheckouts(dict)); dict.Add(WellKnownJobSettings.HasMultipleCheckouts, "burger"); Assert.Equal(false, RepositoryUtil.HasMultipleCheckouts(dict)); } }
public void Update(Character entity) { using (IDbConnection dbConnection = new SQLiteConnection(RepositoryUtil.LoadConnectionString())) { string insertQuery = "UPDATE Characters SET Name = @Name, Player = @Player, Age = @Age, Gender = @Gender, Alignment = @Alignment WHERE Id = @Id"; dbConnection.Execute(insertQuery, new { entity.Name, entity.Player, entity.Age, entity.Gender, entity.Alignment, entity.Id }); } }
public void HasMultipleCheckouts_should_return_true_when_set_correctly() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); Assert.Equal(false, RepositoryUtil.HasMultipleCheckouts(null)); var dict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); dict[WellKnownJobSettings.HasMultipleCheckouts] = "true"; Assert.Equal(true, RepositoryUtil.HasMultipleCheckouts(dict)); dict[WellKnownJobSettings.HasMultipleCheckouts] = "TRUE"; Assert.Equal(true, RepositoryUtil.HasMultipleCheckouts(dict)); dict[WellKnownJobSettings.HasMultipleCheckouts] = "True"; Assert.Equal(true, RepositoryUtil.HasMultipleCheckouts(dict)); } }
private string GetDefaultRepositoryPath( IExecutionContext executionContext, RepositoryResource repository, string defaultSourcesDirectory) { if (RepositoryUtil.HasMultipleCheckouts(executionContext.JobSettings)) { // If we have multiple checkouts they should all be rooted to the sources directory (_work/1/s/repo1) return(Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Work), defaultSourcesDirectory, RepositoryUtil.GetCloneDirectory(repository))); } else { // For single checkouts, the repository is rooted to the sources folder (_work/1/s) return(Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Work), defaultSourcesDirectory)); } }
public void GetTriggeringRepository_should_return_correct_value_when_called() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); var repo1 = new RepositoryResource { Alias = "repo1", Id = "repo1", Type = "git", }; var repo2 = new RepositoryResource { Alias = "repo2", Id = "repo2", Type = "git", }; var repoSelf = new RepositoryResource { Alias = "self", Id = "repo3", Type = "git", }; // No properties set Assert.Equal(null, RepositoryUtil.GetTriggeringRepository(null)); Assert.Equal(repo1, RepositoryUtil.GetTriggeringRepository(new[] { repo1 })); Assert.Equal(repo2, RepositoryUtil.GetTriggeringRepository(new[] { repo2 })); Assert.Equal(repoSelf, RepositoryUtil.GetTriggeringRepository(new[] { repoSelf })); Assert.Equal(null, RepositoryUtil.GetTriggeringRepository(new[] { repo1, repo2 })); Assert.Equal(repoSelf, RepositoryUtil.GetTriggeringRepository(new[] { repoSelf, repo1, repo2 })); Assert.Equal(repoSelf, RepositoryUtil.GetTriggeringRepository(new[] { repo1, repoSelf, repo2 })); Assert.Equal(repoSelf, RepositoryUtil.GetTriggeringRepository(new[] { repo1, repo2, repoSelf })); // With IsPrimaryRepository set repo2.Properties.Set(RepositoryUtil.IsTriggeringRepository, Boolean.TrueString); Assert.Equal(repo2, RepositoryUtil.GetTriggeringRepository(new[] { repo1, repo2, repoSelf })); repo2.Properties.Set(RepositoryUtil.IsTriggeringRepository, Boolean.FalseString); Assert.Equal(repoSelf, RepositoryUtil.GetTriggeringRepository(new[] { repo1, repo2, repoSelf })); } }
private void ProcessPluginInternalUpdateRepositoryPathCommand(IExecutionContext context, Dictionary <string, string> eventProperties, string data) { String alias; if (!eventProperties.TryGetValue(PluginInternalUpdateRepositoryEventProperties.Alias, out alias) || String.IsNullOrEmpty(alias)) { throw new Exception(StringUtil.Loc("MissingRepositoryAlias")); } var repository = context.Repositories.FirstOrDefault(x => string.Equals(x.Alias, alias, StringComparison.OrdinalIgnoreCase)); if (repository == null) { throw new Exception(StringUtil.Loc("RepositoryNotExist")); } if (string.IsNullOrEmpty(data)) { throw new Exception(StringUtil.Loc("MissingRepositoryPath")); } var currentPath = repository.Properties.Get <string>(RepositoryPropertyNames.Path); if (!string.Equals(data.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), currentPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), IOUtil.FilePathStringComparison)) { repository.Properties.Set <string>(RepositoryPropertyNames.Path, data.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); var directoryManager = HostContext.GetService <IBuildDirectoryManager>(); var trackingConfig = directoryManager.UpdateDirectory(context, repository); // Set the directory variables. string _workDirectory = HostContext.GetDirectory(WellKnownDirectory.Work); context.SetVariable(Constants.Variables.Build.SourcesDirectory, Path.Combine(_workDirectory, trackingConfig.SourcesDirectory), isFilePath: true); context.SetVariable(Constants.Variables.Build.RepoLocalPath, Path.Combine(_workDirectory, trackingConfig.SourcesDirectory), isFilePath: true); // Only set the working directory here if we are NOT in Multi-checkout if (!RepositoryUtil.HasMultipleCheckouts(context.JobSettings)) { context.SetVariable(Constants.Variables.System.DefaultWorkingDirectory, Path.Combine(_workDirectory, trackingConfig.SourcesDirectory), isFilePath: true); } } repository.Properties.Set("__AZP_READY", bool.TrueString); }
public void GuessRepositoryType_should_return_correct_values_when_called() { using (TestHostContext hc = new TestHostContext(this)) { Tracing trace = hc.GetTrace(); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType(null)); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType("")); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType("garbage")); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType("github")); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType("azuredevops")); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType("https://githubenterprise.com/microsoft/somerepo.git")); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType("https://almost.visual.studio.com/microsoft/somerepo.git")); Assert.Equal(string.Empty, RepositoryUtil.GuessRepositoryType("https://almost.dev2.azure.com/microsoft/somerepo.git")); Assert.Equal(RepositoryTypes.GitHub, RepositoryUtil.GuessRepositoryType("https://github.com/microsoft/somerepo.git")); Assert.Equal(RepositoryTypes.Git, RepositoryUtil.GuessRepositoryType("https://[email protected]/org/project/_git/reponame")); Assert.Equal(RepositoryTypes.Git, RepositoryUtil.GuessRepositoryType("https://[email protected]/project/_git/reponame")); Assert.Equal(RepositoryTypes.Tfvc, RepositoryUtil.GuessRepositoryType("https://[email protected]/project")); Assert.Equal(RepositoryTypes.Tfvc, RepositoryUtil.GuessRepositoryType("https://[email protected]/org/project")); Assert.Equal(RepositoryTypes.Bitbucket, RepositoryUtil.GuessRepositoryType("https://[email protected]/user1/mybucket.git")); } }