public async Task GitPullFromRepositoryAsync(string repositoryPath, string localDir, string branch, CancellationToken cancel = default) { string gitUrl = this.Settings.GitLabBaseUrl._CombineUrl(repositoryPath + ".git").ToString(); gitUrl = gitUrl._ReplaceStr("https://", $"https://*****:*****@"); await Lfs.CreateDirectoryAsync(localDir); // localDir ディレクトリに .git ディレクトリは存在するか? string dotgitDir = localDir._CombinePath(".git"); bool init = false; StrDictionary <string> envVars = new StrDictionary <string>(); // empty config string emptyCfgPath = Env.MyLocalTempDir._CombinePath("empty.txt"); using (await Lock1.LockWithAwait(cancel)) { if (await Lfs.IsFileExistsAsync(emptyCfgPath, cancel) == false) { await Lfs.WriteStringToFileAsync(emptyCfgPath, "\n\n", cancel : cancel); } } envVars.Add("GIT_CONFIG_GLOBAL", emptyCfgPath); envVars.Add("GIT_CONFIG_SYSTEM", emptyCfgPath); if (await Lfs.IsDirectoryExistsAsync(dotgitDir, cancel)) { try { // update を試みる await EasyExec.ExecAsync(this.GitExe, $"pull origin {branch}", localDir, cancel : cancel, additionalEnvVars : envVars); } catch (Exception ex) { ex._Error(); init = true; } } else { init = true; } if (init) { // 初期化する await Lfs.DeleteDirectoryAsync(localDir, true, cancel : cancel, forcefulUseInternalRecursiveDelete : true); // git clone をする await EasyExec.ExecAsync(this.GitExe, $"clone {gitUrl} {localDir}", cancel : cancel, additionalEnvVars : envVars); // update を試みる await EasyExec.ExecAsync(this.GitExe, $"pull origin {branch}", localDir, cancel : cancel, additionalEnvVars : envVars); } }