private void PrintProcessedModuleInfo(Dep dep, GetInfo getInfo, string treeish) { var longestModuleName = modules.Select(m => m.Name.Length).Max() + 5; dep.UpdateConfigurationIfNull(); var name = dep.Name + (dep.Configuration == null || dep.Configuration.Equals("full-build") ? "" : Helper.ConfigurationDelimiter + dep.Configuration); var outputTreeish = getInfo.Forced && !treeish.Equals("master") ? treeish + " *forced" : dep.Treeish ?? "master"; if (getInfo.HookUpdated) { outputTreeish += " (hook updated) "; } if (getInfo.Pulled) { outputTreeish += " *pulled"; ConsoleWriter.Shared.WriteUpdate(GetPrintString(longestModuleName, name, outputTreeish, getInfo.CommitInfo)); Log.LogDebug($"{"[" + dep.Name + "]",-30}{outputTreeish,-18} {getInfo.CommitInfo}"); return; } if (getInfo.ForcedLocal) { outputTreeish += " *forced local"; ConsoleWriter.Shared.WriteWarning(GetPrintString(longestModuleName, name, outputTreeish, getInfo.CommitInfo)); Log.LogDebug($"{"[" + dep.Name + "]",-30}{outputTreeish,-18} {getInfo.CommitInfo}"); return; } if (getInfo.Reset) { outputTreeish += " *reset"; ConsoleWriter.Shared.WriteWarning(GetPrintString(longestModuleName, name, outputTreeish, getInfo.CommitInfo)); Log.LogDebug($"{"[" + dep.Name + "]",-30}{outputTreeish,-18} {getInfo.CommitInfo}"); return; } if (getInfo.Changed || getInfo.Cloned) { Log.LogDebug($"{"[" + dep.Name + "]",-30}{outputTreeish + (getInfo.Cloned ? " *cloned" : " *changed"),-18} {getInfo.CommitInfo}"); ConsoleWriter.Shared.WriteUpdate(GetPrintString(longestModuleName, name, outputTreeish, getInfo.CommitInfo)); } else { Log.LogDebug($"{"[" + dep.Name + "]",-30}{outputTreeish + " *skipped",-18} {getInfo.CommitInfo}"); ConsoleWriter.Shared.WriteSkip(GetPrintString(longestModuleName, name, outputTreeish, getInfo.CommitInfo)); } }
private void GetFullModule(Dep dep, string[] force) { var getInfo = new GetInfo(); var module = modules.FirstOrDefault(m => m.Name.Equals(dep.Name)); if (module == null) { throw new CementException("Failed to find module " + dep.Name); } var repo = new GitRepository(dep.Name, Helper.CurrentWorkspace, Log); if (!repo.IsGitRepo) { ConsoleWriter.Shared.WriteProgress(dep.Name + " " + dep.Treeish + " cloning"); if (Directory.Exists(Path.Combine(repo.Workspace, repo.ModuleName))) { CloneInNotEmptyFolder(module, repo); } else { CloneInEmptyFolder(dep, module, repo); } getInfo.Cloned = true; } repo.TryUpdateUrl(modules.FirstOrDefault(m => m.Name.Equals(dep.Name))); repo.SubmoduleUpdate(); GetTreeish(repo, dep, force, dep.Treeish, getInfo); if (verbose) { getInfo.CommitInfo = repo.GetCommitInfo(); } if (HooksHelper.InstallHooks(dep.Name)) { getInfo.HookUpdated = true; } PrintProcessedModuleInfo(dep, getInfo, getInfo.Forced ? getInfo.ForcedBranch : dep.Treeish); WarnIfNotMerged(repo); }
private void GetTreeish(GitRepository repo, Dep dep, string force, string treeish, GetInfo getInfo) { treeish = treeish ?? "master"; Log.Info($"{"[" + dep.Name + "]",-30}Getting treeish '{treeish}'"); var hasRemoteBranch = repo.HasRemoteBranch(treeish); getInfo.Forced = HaveToForce(dep, force, repo); if (getInfo.Forced) { treeish = force; Log.Info($"{"[" + dep.Name + "]",-30}treeish '{treeish}' was forced"); } ConsoleWriter.WriteProgress(dep.Name + "/" + dep.Configuration + "\t" + treeish); var oldSha = repo.SafeGetCurrentLocalCommitHash(); var remoteSha = repo.HasRemoteBranch(treeish) ? repo.RemoteCommitHashAtBranch(treeish) : treeish; var localChangesAction = DefineLocalChangesPolicy(repo, oldSha, remoteSha); if (localChangesAction == LocalChangesAction.ForceLocal) { getInfo.ForcedLocal = true; return; } if (localChangesAction == LocalChangesAction.Reset) { Reset(repo, dep); getInfo.Reset = true; } ConsoleWriter.WriteProgress(dep.Name + " looking for remote commit hash"); if (hasRemoteBranch && repo.RemoteCommitHashAtBranch(treeish).Equals(oldSha) && repo.CurrentLocalTreeish().Value.Equals(treeish)) { return; } if (repo.HasLocalBranch(treeish)) { ConsoleWriter.WriteProgress(dep.Name + " has local branch " + treeish); Log.Info($"{"[" + dep.Name + "]",-30}has local branch '{treeish}'"); ConsoleWriter.WriteProgress(dep.Name + " checkout " + treeish); repo.Checkout(treeish); if (hasRemoteBranch) { if (userLocalChangesPolicy == LocalChangesPolicy.Reset && !repo.FastForwardPullAllowed(treeish)) { repo.ResetHard(treeish); } else { ConsoleWriter.WriteProgress(dep.Name + " pull " + treeish); repo.Pull(treeish); } } } else { Log.Info($"{"[" + dep.Name + "]",-30}doesn't have local branch '{treeish}'"); ConsoleWriter.WriteProgress(dep.Name + " fetch " + treeish); if (repo.HasRemoteBranch(treeish)) { repo.Fetch(treeish); } else { repo.Fetch(""); } ConsoleWriter.WriteProgress(dep.Name + " checkout " + treeish); repo.Checkout(treeish); } var newSha = repo.CurrentLocalCommitHash(); getInfo.Reset = false; if (userLocalChangesPolicy == LocalChangesPolicy.Reset && hasRemoteBranch && !repo.RemoteCommitHashAtBranch(treeish).Equals(newSha)) { repo.ResetHard(treeish); getInfo.Reset = true; } getInfo.Changed = !oldSha.Equals(newSha); getInfo.Pulled = localChangesAction == LocalChangesAction.Pull; }