public Remote(DarcSettings settings, ILogger logger) { ValidateSettings(settings); _logger = logger; if (settings.GitType == GitRepoType.GitHub) { _gitClient = new GitHubClient(settings.PersonalAccessToken, _logger); } else if (settings.GitType == GitRepoType.AzureDevOps) { _gitClient = new AzureDevOpsClient(settings.PersonalAccessToken, _logger); } // Only initialize the file manager if we have a git client, which excludes "None" if (_gitClient != null) { _fileManager = new GitFileManager(_gitClient, _logger); } // Initialize the bar client if there is a password if (!string.IsNullOrEmpty(settings.BuildAssetRegistryPassword)) { if (!string.IsNullOrEmpty(settings.BuildAssetRegistryBaseUri)) { _barClient = ApiFactory.GetAuthenticated(settings.BuildAssetRegistryBaseUri, settings.BuildAssetRegistryPassword); } else { _barClient = ApiFactory.GetAuthenticated(settings.BuildAssetRegistryPassword); } } }
public Local(ILogger logger, string overrideRootPath = null) { _repo = overrideRootPath ?? LocalHelpers.GetRootDir(GitExecutable, logger); _logger = logger; _gitClient = new LocalGitClient(GitExecutable, _logger); _fileManager = new GitFileManager(_gitClient, _logger); }
public RepoApiController(ISubscriptionRepo subscriptionRepo, IUserRepo userRepo, IGitRepo gitRepo, ILogger logger) { _subscriptionRepo = subscriptionRepo; _userRepo = userRepo; _gitRepo = gitRepo; _logger = logger; }
public Local(string gitPath, ILogger logger) { _repo = Directory.GetParent(gitPath).FullName; _logger = logger; _gitClient = new LocalGitClient(_logger); _fileManager = new GitFileManager(_gitClient, _logger); }
void MirrorWorkingTreeFiles(IGitRepo srcRepo, string srcDirPath, string destDirPath) { if (!Path.IsPathFullyQualified(srcDirPath) || !Path.IsPathFullyQualified(destDirPath)) { throw new InvalidOperationException(); } if (destDirPath == "" || destDirPath == "\\" || destDirPath == "/" || Regex.Match(destDirPath, @"^\w+:\\$").Success) { throw new InvalidOperationException(); } // 나중에 priority queue 사용을 고려해보는 것으로 var srcFilePaths = Directory.GetFiles(srcDirPath); var destFilePaths = Directory.EnumerateFiles(destDirPath) .ToHashSet(StringComparer.CurrentCultureIgnoreCase); // 1. srcFilePath가 ignored라면 스킵 var ignoredSrcFilePaths = srcRepo.GetIgnores(srcFilePaths); foreach (var srcFilePath in srcFilePaths) { if (ignoredSrcFilePaths.Contains(srcFilePath)) { continue; } var srcFileRelPath = Path.GetRelativePath(srcDirPath, srcFilePath); var destFilePath = Path.Combine(destDirPath, srcFileRelPath); // 2. destFile이 있고, 파일 사이즈랑 마지막으로 쓴 시간이 같으면 스킵 if (destFilePaths.Contains(destFilePath)) { var srcFileInfo = new FileInfo(srcFilePath); var destFileInfo = new FileInfo(destFilePath); // 크기와 날짜가 같으면 스킵 if (srcFileInfo.Length == destFileInfo.Length && srcFileInfo.LastWriteTime == destFileInfo.LastWriteTime) { destFilePaths.Remove(destFilePath); continue; } } // 아니라면 덮어씌우기 File.Copy(srcFilePath, destFilePath, true); // destFilePaths에서 삭제 destFilePaths.Remove(destFilePath); } // 남은 파일은 src에 없다는 것이므로 삭제, 주의 foreach (var destFilePath in destFilePaths) { File.Delete(destFilePath); Console.WriteLine("{0}: deleted", destFilePath); } }
public static async Task <HttpResponseMessage> ExecuteGitCommand(this IGitRepo gitRepo, HttpMethod method, string requestUri, ILogger logger, string body = null, string versionOverride = null) { using (HttpClient client = gitRepo.CreateHttpClient(versionOverride)) { HttpRequestManager requestManager = new HttpRequestManager(client, method, requestUri, logger, body, versionOverride); return(await requestManager.ExecuteAsync()); } }
void MirrorWorkingTreeDirectories(IGitRepo srcRepo, string srcDirPath, string destDirPath, bool bTopLevel) { if (!Path.IsPathFullyQualified(srcDirPath) || !Path.IsPathFullyQualified(destDirPath)) { throw new InvalidOperationException(); } if (destDirPath == "" || destDirPath == "\\" || destDirPath == "/" || Regex.Match(destDirPath, @"^\w+:\\$").Success) { throw new InvalidOperationException(); } var srcSubDirPaths = Directory.GetDirectories(srcDirPath); var destSubDirPaths = Directory.EnumerateDirectories(destDirPath).ToHashSet(StringComparer.CurrentCultureIgnoreCase); var ignoreSrcSubDirPaths = srcRepo.GetIgnores(srcSubDirPaths); // 각 디렉토리에서 foreach (var srcSubDirPath in srcSubDirPaths) { if (ignoreSrcSubDirPaths.Contains(srcSubDirPath)) { continue; } var srcSubDirRelPath = Path.GetRelativePath(srcDirPath, srcSubDirPath); var destSubDirPath = Path.Combine(destDirPath, srcSubDirRelPath); // 중요; if (bTopLevel && srcSubDirRelPath.Equals(".git", StringComparison.CurrentCultureIgnoreCase)) { destSubDirPaths.Remove(destSubDirPath); continue; } // 디렉토리가 존재한다면 if (destSubDirPaths.Contains(destSubDirPath)) { MirrorWorkingTree(srcRepo, srcSubDirPath, destSubDirPath, false); destSubDirPaths.Remove(destSubDirPath); } else { Directory.CreateDirectory(destSubDirPath); MirrorWorkingTree(srcRepo, srcSubDirPath, destSubDirPath, false); destSubDirPaths.Remove(destSubDirPath); } } // src에 존재하지 않거나 ignored된 디렉토리는 삭제 foreach (var destSubDirPath in destSubDirPaths) { Directory.Delete(destSubDirPath, true); Console.WriteLine("{0}: deleted", destSubDirPath); } }
public static string GetDecodedContent(this IGitRepo gitRepo, string encodedContent) { var serializerSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; byte[] content = Convert.FromBase64String(encodedContent); return(Encoding.UTF8.GetString(content)); }
public Remote(IGitRepo gitClient, IBarClient barClient, ILogger logger) { _logger = logger; _barClient = barClient; _gitClient = gitClient; if (_gitClient != null) { _fileManager = new GitFileManager(_gitClient, _logger); } }
public static string GetDecodedContent(this IGitRepo gitRepo, string encodedContent) { try { byte[] content = Convert.FromBase64String(encodedContent); return(Encoding.UTF8.GetString(content)); } catch (FormatException) { return(encodedContent); } }
public static string GetDecodedContent(this IGitRepo gitRepo, string encodedContent) { try { byte[] content = Convert.FromBase64String(encodedContent); // We can't use Encoding.UTF8.GetString here because that returns a string containing a BOM if one exists in the bytes. using (var str = new MemoryStream(content, false)) using (var reader = new StreamReader(str)) { return(reader.ReadToEnd()); } } catch (FormatException) { return(encodedContent); } }
/// <summary> /// Get a remote for a specific repo. /// </summary> /// <param name="options">Command line options</param> /// <param name="repoUrl">Repository url</param> /// <param name="logger">Logger</param> /// <returns>New remote</returns> public static IRemote GetRemote(CommandLineOptions options, string repoUrl, ILogger logger) { DarcSettings darcSettings = LocalSettings.GetDarcSettings(options, logger, repoUrl); if (darcSettings.GitType != GitRepoType.None && string.IsNullOrEmpty(darcSettings.GitRepoPersonalAccessToken)) { throw new DarcException($"No personal access token was provided for repo type '{darcSettings.GitType}'"); } // If a temporary repository root was not provided, use the environment // provided temp directory. string temporaryRepositoryRoot = darcSettings.TemporaryRepositoryRoot; if (string.IsNullOrEmpty(temporaryRepositoryRoot)) { temporaryRepositoryRoot = Path.GetTempPath(); } IGitRepo gitClient = null; if (darcSettings.GitType == GitRepoType.GitHub) { gitClient = new GitHubClient(options.GitLocation, darcSettings.GitRepoPersonalAccessToken, logger, temporaryRepositoryRoot, // Caching not in use for Darc local client. null); } else if (darcSettings.GitType == GitRepoType.AzureDevOps) { gitClient = new AzureDevOpsClient(options.GitLocation, darcSettings.GitRepoPersonalAccessToken, logger, temporaryRepositoryRoot); } IBarClient barClient = null; if (!string.IsNullOrEmpty(darcSettings.BuildAssetRegistryPassword)) { barClient = new MaestroApiBarClient(darcSettings.BuildAssetRegistryPassword, darcSettings.BuildAssetRegistryBaseUri); } return(new Remote(gitClient, barClient, logger)); }
void MirrorWorkingTree(IGitRepo srcRepo, string srcDirPath, string destDirPath, bool bTopLevel) { if (!Path.IsPathFullyQualified(srcDirPath) || !Path.IsPathFullyQualified(destDirPath)) { throw new InvalidOperationException(); } if (destDirPath == "" || destDirPath == "\\" || destDirPath == "/" || Regex.Match(destDirPath, @"^\w+:\\$").Success) { throw new InvalidOperationException(); } MirrorWorkingTreeFiles(srcRepo, srcDirPath, destDirPath); // 더 무서운 DirectoryMirror MirrorWorkingTreeDirectories(srcRepo, srcDirPath, destDirPath, bTopLevel); }
public Remote(DarcSettings settings, ILogger logger) { ValidateSettings(settings); _logger = logger; if (settings.GitType == GitRepoType.GitHub) { _gitClient = new GitHubClient(settings.PersonalAccessToken, _logger); } else { _gitClient = new VstsClient(settings.PersonalAccessToken, _logger); } _fileManager = new DependencyFileManager(_gitClient, _logger); _barClient = new BuildAssetRegistryClient(settings.BuildAssetRegistryBaseUri, _logger); }
public GitFileManager(IGitRepo gitRepo, ILogger logger) { _gitClient = gitRepo; _logger = logger; }
public static byte[] GetContentBytes(this IGitRepo gitRepo, string content) { string decodedContent = GetDecodedContent(gitRepo, content); return(Encoding.UTF8.GetBytes(decodedContent)); }
public DependencyFileManager(IGitRepo gitRepo, ILogger logger) { _gitClient = gitRepo; _logger = logger; }