public static Settings Parse(IGitModule gitModule, ISettingsSource settings, StashPlugin plugin) { var result = new Settings { Username = plugin.StashUsername.ValueOrDefault(settings), Password = plugin.StashPassword.ValueOrDefault(settings), StashUrl = plugin.StashBaseUrl.ValueOrDefault(settings), DisableSSL = plugin.StashDisableSsl.ValueOrDefault(settings) }; var module = ((GitModule)gitModule); var remotes = module.GetRemotes() .Select(r => module.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, r))) .ToArray(); foreach (var url in remotes) { var pattern = url.Contains("http") ? StashHttpRegex : StashSshRegex; var match = Regex.Match(url, pattern); if (match.Success && result.StashUrl.Contains(match.Groups["url"].Value)) { result.ProjectKey = match.Groups["project"].Value; result.RepoSlug = match.Groups["repo"].Value; return result; } } return null; }
public static Settings Parse(IGitModule gitModule, IGitPluginSettingsContainer setting) { var result = new Settings { Username = setting.GetSetting(StashPlugin.StashUsername), Password = setting.GetSetting(StashPlugin.StashPassword) }; var module = ((GitModule)gitModule); var remotes = module.GetRemotes() .Select(r => module.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, r))) .ToArray(); foreach (var url in remotes) { var pattern = url.Contains("http") ? StashHttpRegex : StashSshRegex; var match = Regex.Match(url, pattern); if (match.Success) { result.ProjectKey = match.Groups["project"].Value; result.RepoSlug = match.Groups["repo"].Value; result.StashUrl = match.Groups["url"].Value; return result; } } return null; }
public static Uri GetFetchUrl(IGitModule aModule, string remote) { string remotes = aModule.RunGitCmd("remote show -n \"" + remote + "\""); string fetchUrlLine = remotes.Split('\n').Select(p => p.Trim()).First(p => p.StartsWith("Push")); return new Uri(fetchUrlLine.Split(new[] { ':' }, 2)[1].Trim()); }
public ProxySwitcherForm(IGitPluginSettingsContainer settings, GitUIBaseEventArgs gitUiCommands) { InitializeComponent(); this.Text = _pluginDescription.Text; this.settings = settings; this.gitCommands = gitUiCommands.GitModule; }
private GerritSettings(IGitModule aModule) { Module = aModule; Port = 29418; DefaultBranch = "master"; DefaultRemote = "gerrit"; DefaultRebase = true; }
public FindLargeFilesForm(float threshold, GitUIBaseEventArgs gitUiEventArgs) { InitializeComponent(); this.threshold = threshold; this.gitUiCommands = gitUiEventArgs; this.gitCommands = gitUiEventArgs.GitModule; }
public ProxySwitcherForm(ISettingsSource settings, GitUIBaseEventArgs gitUiCommands) { InitializeComponent(); Translate(); this.Text = _pluginDescription.Text; this.settings = settings; this.gitCommands = gitUiCommands.GitModule; }
public FindLargeFilesForm(float threshold, GitUIBaseEventArgs gitUiEventArgs) { InitializeComponent(); Translate(); this._threshold = threshold; this._gitUiCommands = gitUiEventArgs; this._gitCommands = gitUiEventArgs != null ? gitUiEventArgs.GitModule : null; }
// public only because of FormTranslate public GerritSettings(IGitModule aModule) { Translator.Translate(this, GitCommands.Settings.CurrentTranslation); Module = aModule; Port = 29418; DefaultBranch = "master"; DefaultRemote = "gerrit"; DefaultRebase = true; }
public DeleteUnusedBranchesForm(int days, string referenceBranch, IGitModule gitCommands) { InitializeComponent(); this.referenceBranch = referenceBranch; this.days = days; this.gitCommands = gitCommands; instructionLabel.Text = "Choose branches to delete. Only branches that are fully merged in '" + referenceBranch + "' will be deleted."; }
public ProxySwitcherForm(ProxySwitcherPlugin plugin, ISettingsSource settings, GitUIBaseEventArgs gitUiCommands) { InitializeComponent(); Translate(); Text = _pluginDescription.Text; _plugin = plugin; _settings = settings; _gitCommands = gitUiCommands.GitModule; }
public FormImpact(IGitModule Module) { syncContext = SynchronizationContext.Current; InitializeComponent(); UpdateAuthorInfo(""); Impact.Init(Module); Impact.UpdateData(); Impact.Invalidated += Impact_Invalidated; }
public DeleteUnusedBranchesForm(int days, string referenceBranch, IGitModule gitCommands, IGitUICommands gitUICommands, IGitPlugin gitPlugin) { InitializeComponent(); this.referenceBranch = referenceBranch; this.days = days; this.gitCommands = gitCommands; _gitUICommands = gitUICommands; _gitPlugin = gitPlugin; imgLoading.Image = IsMonoRuntime() ? Resources.loadingpanel_static : Resources.loadingpanel; RefreshObsoleteBranches(); }
private static Tuple<Dictionary<string, int>, int> GroupAllCommitsByContributor(IGitModule module, DateTime since, DateTime until) { var sinceParam = since != DateTime.MinValue ? GetDateParameter(since, "since") : ""; var untilParam = until != DateTime.MaxValue ? GetDateParameter(since, "until") : ""; var unformattedCommitsPerContributor = module.RunGitCmd( "shortlog --all -s -n --no-merges" + sinceParam + untilParam) .Split('\n'); return ParseCommitsPerContributor(unformattedCommitsPerContributor); }
public FormGitStatistics(IGitModule aModule, string codeFilePattern) { Module = aModule; _codeFilePattern = codeFilePattern; InitializeComponent(); TotalLinesOfCode.Font = new Font(SystemFonts.MessageBoxFont.FontFamily, 9.75F, FontStyle.Bold, GraphicsUnit.Point); TotalLinesOfCode2.Font = TotalLinesOfCode.Font; TotalLinesOfTestCode.Font = TotalLinesOfCode.Font; TotalCommits.Font = TotalLinesOfCode.Font; LoadingLabel.Font = TotalLinesOfCode.Font; syncContext = SynchronizationContext.Current; }
public GitRef(IGitModule module, string guid, string completeName, string remote) { Module = module; Guid = guid; Selected = false; CompleteName = completeName; Remote = remote; IsTag = CompleteName.StartsWith(RefsTagsPrefix); IsDereference = CompleteName.EndsWith(TagDereferenceSuffix); IsHead = CompleteName.StartsWith(RefsHeadsPrefix); IsRemote = CompleteName.StartsWith(RefsRemotesPrefix); IsBisect = CompleteName.StartsWith(RefsBisectPrefix); ParseName(); _remoteSettingName = RemoteSettingName(Name); _mergeSettingName = String.Format("branch.{0}.merge", Name); }
public FormGitStatistics(IGitModule module, string codeFilePattern, bool countSubmodule) { ThreadHelper.ThrowIfNotOnUIThread(); _module = module; _codeFilePattern = codeFilePattern; _countSubmodule = countSubmodule; InitializeComponent(); Translate(); TotalLinesOfCode.Font = new Font(SystemFonts.MessageBoxFont.FontFamily, 9.75F, FontStyle.Bold, GraphicsUnit.Point); TotalLinesOfCode2.Font = TotalLinesOfCode.Font; TotalLinesOfTestCode.Font = TotalLinesOfCode.Font; TotalCommits.Font = TotalLinesOfCode.Font; LoadingLabel.Font = TotalLinesOfCode.Font; this.AdjustForDpiScaling(); }
private static bool HaveValidCommitMsgHook([NotNull] IGitModule gitModule, bool force = false) { if (gitModule == null) { throw new ArgumentNullException(nameof(gitModule)); } string path = Path.Combine(gitModule.ResolveGitInternalPath("hooks"), "commit-msg"); if (!File.Exists(path)) { return(false); } // We don't want to read the contents of the commit-msg every time // we call this method, so we cache the result if we aren't // forced. lock (_syncRoot) { if (!force && _validatedHooks.TryGetValue(path, out var isValid)) { return(isValid); } try { string content = File.ReadAllText(path); // Don't do an extensive check. If the commit-msg contains the // text "gerrit", it's probably the Gerrit commit-msg hook. isValid = content.IndexOf("gerrit", StringComparison.OrdinalIgnoreCase) != -1; } catch { isValid = false; } _validatedHooks[path] = isValid; return(isValid); } }
private static GitRevision GetCurrentRevision( IGitModule module, [CanBeNull] RevisionGridControl revisionGrid, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches, List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches, [CanBeNull] GitRevision currentRevision) { if (currentRevision == null) { IEnumerable <IGitRef> refs; if (revisionGrid == null) { var currentRevisionGuid = module.GetCurrentCheckout(); currentRevision = new GitRevision(currentRevisionGuid); refs = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid).ToList(); } else { currentRevision = revisionGrid.GetCurrentRevision(); refs = currentRevision.Refs; } foreach (var gitRef in refs) { if (gitRef.IsTag) { currentTags.Add(gitRef); } else if (gitRef.IsHead || gitRef.IsRemote) { currentBranches.Add(gitRef); if (gitRef.IsRemote) { currentRemoteBranches.Add(gitRef); } else { currentLocalBranches.Add(gitRef); } } } } return(currentRevision); }
private void GetRepositorySubmodulesStatus(SubmoduleInfoResult result, IGitModule module, CancellationToken cancelToken, string noBranchText) { foreach (var submodule in module.GetSubmodulesLocalPaths().OrderBy(submoduleName => submoduleName)) { cancelToken.ThrowIfCancellationRequested(); var name = submodule; string path = module.GetSubmoduleFullPath(submodule); if (AppSettings.DashboardShowCurrentBranch && !GitModule.IsBareRepository(path)) { name = name + " " + GetModuleBranch(path, noBranchText); } var smi = new SubmoduleInfo { Text = name, Path = path }; result.OurSubmodules.Add(smi); GetSubmoduleStatusAsync(smi, cancelToken).FileAndForget(); } }
public void Setup() { _data = new CommitData("c3c03473f3bc7fb3807b3132a20ac70743cdbda3", Guid.NewGuid().ToString(), new ReadOnlyCollection <string>(new List <string> { "a2b24c7f6ed5dacbac5470561914fcb27a992024" }), "John Doe (Acme Inc) <*****@*****.**>", DateTime.UtcNow, "John Doe <*****@*****.**>", DateTime.UtcNow, "\tI made a really neato change.\n\nNotes (p4notes):\n\tP4@547123"); _linkFactory = Substitute.For <ILinkFactory>(); _commitInfoRenderer = Substitute.For <ICommitDataHeaderRenderer>(); _commitInfoRenderer.Render(Arg.Any <CommitData>(), true).Returns(x => null); _module = Substitute.For <IGitModule>(); _getModule = () => _module; _provider = new CommitInformationProvider(_getModule, _linkFactory, _commitInfoRenderer); }
public void Setup() { _gitFile = Path.Combine(_workingDir, ".git"); _gitWorkingDir = _gitFile.EnsureTrailingPathSeparator(); _indexLockFile = Path.Combine(_gitWorkingDir, IndexLock); _file = Substitute.For <FileBase>(); _directory = Substitute.For <DirectoryBase>(); _fileSystem = Substitute.For <IFileSystem>(); _fileSystem.Directory.Returns(_directory); _fileSystem.File.Returns(_file); _module = Substitute.For <IGitModule>(); _module.WorkingDir.Returns(_workingDir); _gitDirectoryResolver = Substitute.For <IGitDirectoryResolver>(); _gitDirectoryResolver.Resolve(_workingDir).Returns(_gitWorkingDir); _manager = new IndexLockManager(_module, _gitDirectoryResolver, _fileSystem); }
public void Setup() { if (_referenceRepository == null) { _referenceRepository = new ReferenceRepository(); } else { _referenceRepository.Reset(); } _uiCommands = new GitUICommands(_referenceRepository.Module); _module = Substitute.For <IGitModule>(); _module.GetCurrentRemote().ReturnsForAnyArgs("origin"); _module.GetCurrentCheckout().ReturnsForAnyArgs(ObjectId.WorkTreeId); _exampleScript = ScriptManager.GetScript(_keyOfExampleScript); _exampleScript.AskConfirmation = false; // avoid any dialogs popping up _exampleScript.RunInBackground = true; // avoid any dialogs popping up }
private static GitRevision GetCurrentRevision( [NotNull] IGitModule module, [CanBeNull] IScriptHostControl scriptHostControl, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches, List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches) { GitRevision currentRevision; IEnumerable <IGitRef> refs; if (scriptHostControl == null) { var currentRevisionGuid = module.GetCurrentCheckout(); currentRevision = currentRevisionGuid == null ? null : new GitRevision(currentRevisionGuid); refs = module.GetRefs(true, true).Where(gitRef => gitRef.ObjectId == currentRevisionGuid); } else { currentRevision = scriptHostControl.GetCurrentRevision(); refs = currentRevision?.Refs ?? Array.Empty <IGitRef>(); } foreach (var gitRef in refs) { if (gitRef.IsTag) { currentTags.Add(gitRef); } else if (gitRef.IsHead || gitRef.IsRemote) { currentBranches.Add(gitRef); if (gitRef.IsRemote) { currentRemoteBranches.Add(gitRef); } else { currentLocalBranches.Add(gitRef); } } } return(currentRevision); }
private CommandStatus ExecuteRunScript(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid) { try { var result = (CommandStatus)_miRunScript.Invoke(null, new object[] { owner, module, scriptKey, uiCommands, revisionGrid }); return(result); } catch (TargetInvocationException ex) { throw ex.InnerException; } }
public bool ProcessRevisionSelectionChange(IGitModule currentModule, IReadOnlyCollection <GitRevision> selectedRevisions) { if (selectedRevisions.Count > 1) { return(false); } var revision = selectedRevisions.FirstOrDefault(); var changed = !string.Equals(revision?.AuthorEmail, AuthorEmailToHighlight, StringComparison.OrdinalIgnoreCase); if (changed) { AuthorEmailToHighlight = revision is not null ? revision.AuthorEmail : currentModule.GetEffectiveSetting(SettingKeyString.UserEmail); return(true); } return(false); }
private void SetTopProjectSubmoduleInfo(SubmoduleInfoResult result, string noBranchText, IGitModule topProject, bool isParentTopProject, bool isCurrentTopProject) { if (isParentTopProject && !isCurrentTopProject) { result.TopProject = result.SuperProject; } else { string path = topProject.WorkingDir; string name = Directory.Exists(path) ? Path.GetFileName(Path.GetDirectoryName(path)) + GetBranchNameSuffix(path, noBranchText) : path; result.TopProject = new SubmoduleInfo { Text = name, Path = path, Bold = isCurrentTopProject }; } }
public static GerritSettings Load([NotNull] IWin32Window owner, [NotNull] IGitModule aModule) { if (owner == null) { throw new ArgumentNullException("owner"); } if (aModule == null) { throw new ArgumentNullException("aModule"); } try { return(Load(aModule)); } catch (GerritSettingsException ex) { MessageBox.Show(owner, ex.Message, _settingsError.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
/// <summary> /// Get the result submodule structure /// </summary> /// <param name="currentModule">The current module</param> /// <param name="noBranchText">text with no branches</param> private SubmoduleInfoResult GetSuperProjectRepositorySubmodulesStructure(GitModule currentModule, string noBranchText) { var result = new SubmoduleInfoResult { Module = currentModule }; IGitModule topProject = currentModule.GetTopModule(); bool isCurrentTopProject = currentModule.SuperprojectModule is null; SetTopProjectSubmoduleInfo(result, noBranchText, topProject, isCurrentTopProject); bool isParentTopProject = currentModule.SuperprojectModule?.WorkingDir == topProject.WorkingDir; if (isParentTopProject) { result.SuperProject = result.TopProject; } // Set result.CurrentSubmoduleName and populate result.AllSubmodules SetSubmoduleData(currentModule, result, noBranchText, topProject); return(result); }
private void execute(ILoadingTaskState taskState) { string authorName = this.RespectMailmap ? "%aN" : "%an"; string command = "log --pretty=tformat:\"--- %ad --- " + authorName + "\" --numstat --date=iso -C --all --no-merges"; LoadModuleInfo(command, Module, taskState); if (ShowSubmodules) { IList <string> submodules = Module.GetSubmodulesLocalPathes(); foreach (var submoduleName in submodules) { IGitModule submodule = Module.GetISubmodule(submoduleName); if (submodule.IsValidGitWorkingDir(submodule.GitWorkingDir)) { LoadModuleInfo(command, submodule, taskState); } } } }
/// <summary> /// Parse the output from git-diff --name-status /// </summary> /// <param name="module">The Git module</param> /// <param name="statusString">output from the git command</param> /// <param name="firstRevision">from revision string</param> /// <param name="secondRevision">to revision</param> /// <param name="parentToSecond">The parent for the second revision</param> /// <returns>list with the parsed GitItemStatus</returns> /// <seealso href="https://git-scm.com/docs/git-diff"/> /// <remarks>Git revisions are required to determine if the <see cref="GitItemStatus"/> are WorkTree or Index.</remarks> public static IReadOnlyList <GitItemStatus> GetDiffChangedFilesFromString(IGitModule module, string statusString, [CanBeNull] string firstRevision, [CanBeNull] string secondRevision, [CanBeNull] string parentToSecond) { StagedStatus staged = StagedStatus.Unknown; if (firstRevision == GitRevision.IndexGuid && secondRevision == GitRevision.UnstagedGuid) { staged = StagedStatus.WorkTree; } else if (firstRevision == parentToSecond && secondRevision == GitRevision.IndexGuid) { staged = StagedStatus.Index; } else if ((firstRevision.IsNotNullOrWhitespace() && !firstRevision.IsArtificial()) || (secondRevision.IsNotNullOrWhitespace() && !secondRevision.IsArtificial()) || parentToSecond.IsNotNullOrWhitespace()) { // This cannot be a worktree/index file staged = StagedStatus.None; } return(GetAllChangedFilesFromString_v1(module, statusString, true, staged)); }
public FindLargeFilesForm(float threshold, GitUIEventArgs gitUiEventArgs) { InitializeComponent(); sHADataGridViewTextBoxColumn.Width = DpiUtil.Scale(54); sizeDataGridViewTextBoxColumn.Width = DpiUtil.Scale(52); commitCountDataGridViewTextBoxColumn.Width = DpiUtil.Scale(88); lastCommitDateDataGridViewTextBoxColumn.Width = DpiUtil.Scale(103); InitializeComplete(); sHADataGridViewTextBoxColumn.DataPropertyName = nameof(GitObject.SHA); pathDataGridViewTextBoxColumn.DataPropertyName = nameof(GitObject.Path); sizeDataGridViewTextBoxColumn.DataPropertyName = nameof(GitObject.Size); CompressedSize.DataPropertyName = nameof(GitObject.CompressedSize); commitCountDataGridViewTextBoxColumn.DataPropertyName = nameof(GitObject.CommitCount); lastCommitDateDataGridViewTextBoxColumn.DataPropertyName = nameof(GitObject.LastCommitDate); dataGridViewCheckBoxColumn1.DataPropertyName = nameof(GitObject.Delete); _threshold = threshold; _gitUiCommands = gitUiEventArgs; _gitCommands = gitUiEventArgs?.GitModule; }
private Task[] GetTasks(CancellationToken token) { List <Task> tasks = new List <Task>(); string authorName = RespectMailmap ? "%aN" : "%an"; string command = "log --pretty=tformat:\"--- %ad --- " + authorName + "\" --numstat --date=iso -C --all --no-merges"; tasks.Add(Task.Factory.StartNew(() => LoadModuleInfo(command, Module, token), token)); if (ShowSubmodules) { IList <string> submodules = Module.GetSubmodulesLocalPathes(); foreach (var submoduleName in submodules) { IGitModule submodule = Module.GetSubmodule(submoduleName); if (submodule.IsValidGitWorkingDir()) { tasks.Add(Task.Factory.StartNew(() => LoadModuleInfo(command, submodule, token), token)); } } } return(tasks.ToArray()); }
public static CommandStatus RunScript(IWin32Window owner, IGitModule module, string scriptKey, IGitUICommands uiCommands, RevisionGridControl revisionGrid, Action <string> showError) { if (string.IsNullOrEmpty(scriptKey)) { return(false); } var script = ScriptManager.GetScript(scriptKey); if (script == null) { showError("Cannot find script: " + scriptKey); return(false); } if (string.IsNullOrEmpty(script.Command)) { return(false); } string arguments = script.Arguments; if (!string.IsNullOrEmpty(arguments) && revisionGrid == null) { string optionDependingOnSelectedRevision = ScriptOptionsParser.Options.FirstOrDefault(option => ScriptOptionsParser.DependsOnSelectedRevision(option) && ScriptOptionsParser.Contains(arguments, option)); if (optionDependingOnSelectedRevision != null) { showError($"Option {optionDependingOnSelectedRevision} is only supported when started with revision grid available."); return(false); } } return(RunScript(owner, module, script, uiCommands, revisionGrid, showError)); }
/// <summary> /// This function always at least sets result.TopProject /// </summary> /// <param name="result">submodule info</param> /// <param name="noBranchText">text with no branches</param> private void GetSuperProjectRepositorySubmodulesStructure(GitModule currentModule, SubmoduleInfoResult result, string noBranchText) { bool isCurrentTopProject = currentModule.SuperprojectModule == null; if (isCurrentTopProject) { SetTopProjectSubmoduleInfo(result, noBranchText, result.Module, false, isCurrentTopProject); return; } IGitModule topProject = currentModule.SuperprojectModule.GetTopModule(); bool isParentTopProject = currentModule.SuperprojectModule.WorkingDir == topProject.WorkingDir; // Set result.SuperProject SetSuperProjectSubmoduleInfo(currentModule.SuperprojectModule, result, noBranchText, topProject, isParentTopProject); // Set result.TopProject SetTopProjectSubmoduleInfo(result, noBranchText, topProject, isParentTopProject, isCurrentTopProject); // Set result.CurrentSubmoduleName and populate result.SuperSubmodules SetSubmoduleData(currentModule, result, noBranchText, topProject); }
/// <summary> /// Returns all relevant github-remotes for the current working directory /// </summary> /// <returns></returns> public List<IHostedRemote> GetHostedRemotesForModule(IGitModule aModule) { var repoInfos = new List<IHostedRemote>(); string[] remotes = aModule.GetRemotes(false); foreach (string remote in remotes) { var url = aModule.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)); if (string.IsNullOrEmpty(url)) continue; var m = Regex.Match(url, @"git(?:@|://)github.com[:/]([^/]+)/([\w_\.\-]+)\.git"); if (!m.Success) m = Regex.Match(url, @"https?://(?:[^@:]+)?(?::[^/@:]+)?@?github.com/([^/]+)/([\w_\.\-]+)(?:.git)?"); if (m.Success) { var hostedRemote = new GithubHostedRemote(remote, m.Groups[1].Value, m.Groups[2].Value.Replace(".git", "")); if (!repoInfos.Contains(hostedRemote)) repoInfos.Add(hostedRemote); } } return repoInfos; }
private void LoadModuleInfo(string command, IGitModule module, CancellationToken token) { Process p = module.RunGitCmdDetached(command); // Read line string line = p.StandardOutput.ReadLine(); // Analyze commit listing while (!token.IsCancellationRequested) { Commit commit = new Commit(); // Reached the end ? if (line == null) break; // Look for commit delimiters if (!line.StartsWith("--- ")) { line = p.StandardOutput.ReadLine(); continue; } // Strip "--- " line = line.Substring(4); // Split date and author string[] header = line.Split(new[] { " --- " }, 2, StringSplitOptions.RemoveEmptyEntries); if (header.Length != 2) continue; // Save author in variable commit.author = header[1]; // Parse commit date DateTime date = DateTime.Parse(header[0]).Date; // Calculate first day of the commit week date = commit.week = date.AddDays(-(int)date.DayOfWeek); // Reset commit data commit.data.Commits = 1; commit.data.AddedLines = 0; commit.data.DeletedLines = 0; // Parse commit lines while ((line = p.StandardOutput.ReadLine()) != null && !line.StartsWith("--- ") && !token.IsCancellationRequested) { // Skip empty line if (string.IsNullOrEmpty(line)) continue; string[] fileLine = line.Split('\t'); if (fileLine.Length >= 2) { if (fileLine[0] != "-") commit.data.AddedLines += int.Parse(fileLine[0]); if (fileLine[1] != "-") commit.data.DeletedLines += int.Parse(fileLine[1]); } } if (Updated != null && !token.IsCancellationRequested) Updated(commit); } }
public RefreshContext(IGitModule commands, bool includeRemotes, bool includeUnmerged, string referenceBranch, string remoteRepositoryName, string regexFilter, TimeSpan obsolescenceDuration, CancellationToken cancellationToken) { this.commands = commands; this.includeRemotes = includeRemotes; this.includeUnmerged = includeUnmerged; this.referenceBranch = referenceBranch; this.remoteRepositoryName = remoteRepositoryName; this.regexFilter = regexFilter; this.obsolescenceDuration = obsolescenceDuration; this.cancellationToken = cancellationToken; }
public static GerritSettings Load(IGitModule aModule) { string path = aModule.GitWorkingDir + ".gitreview"; if (!File.Exists(path)) return null; bool inHeader = false; var result = new GerritSettings(aModule); foreach (string line in File.ReadAllLines(path)) { string trimmed = line.Trim(); // Skip empty lines and comments. if (trimmed.Length == 0 || trimmed[0] == '#') continue; // Look for the section header. if (trimmed[0] == '[') { inHeader = trimmed.Trim(new[] { '[', ']' }).Equals("gerrit", StringComparison.OrdinalIgnoreCase); } else if (inHeader) { // Split on the = and trim the parts. string[] parts = trimmed.Split(new[] { '=' }, 2).Select(p => p.Trim()).ToArray(); // Ignore invalid lines. if (parts.Length != 2 || parts[1].Length == 0) continue; // Get the parts of the config file. switch (parts[0].ToLowerInvariant()) { case "host": result.Host = parts[1]; break; case "project": result.Project = parts[1]; break; case "defaultbranch": result.DefaultBranch = parts[1]; break; case "defaultremote": result.DefaultRemote = parts[1]; break; case "defaultrebase": result.DefaultRebase = !parts[1].Equals("0"); break; case "port": int value; if (!int.TryParse(parts[1], out value)) return null; result.Port = value; break; } } } if (!result.IsValid()) return null; return result; }
public GitRef(IGitModule module, string guid, string completeName) : this(module, guid, completeName, string.Empty) { }
private static string GetCommitMessagePath(IGitModule module) { return(Path.Combine(module.GetGitDirectory(), "COMMITMESSAGE")); }
public FilteredGitRefsProvider(IGitModule module) { _refs = new(() => module.GetRefs(RefsFilter.NoFilter)); }
public GitCommandsInstance(IGitModule module) : this(module.GitWorkingDir) { }
public void Setup() { _module = Substitute.For<IGitModule>(); _controller = new GitRemoteController(_module); }
public void LoadRemotes_should_not_throw_if_module_is_null() { _module = null; ((Action)(() => _controller.LoadRemotes())).ShouldNotThrow(); }
public IndexLockManager(IGitModule module, IGitDirectoryResolver gitDirectoryResolver, IFileSystem fileSystem) { _module = module; _gitDirectoryResolver = gitDirectoryResolver; _fileSystem = fileSystem; }
public ImpactLoader(IGitModule aModule) { Module = aModule; }
public GitTagController(IGitUICommands uiCommands, IGitModule module) : this(uiCommands, module, new FileSystem()) { }
public static Tuple<Dictionary<string, int>, int> GroupAllCommitsByContributor(IGitModule module) { return GroupAllCommitsByContributor(module, DateTime.MinValue, DateTime.MaxValue); }
private static string ParseScriptArguments(string arguments, string option, IWin32Window owner, RevisionGridControl revisionGrid, IGitModule module, IReadOnlyList <GitRevision> allSelectedRevisions, in IList <IGitRef> selectedTags, in IList <IGitRef> selectedBranches, in IList <IGitRef> selectedLocalBranches, in IList <IGitRef> selectedRemoteBranches, in IList <string> selectedRemotes, GitRevision selectedRevision, in IList <IGitRef> currentTags, in IList <IGitRef> currentBranches, in IList <IGitRef> currentLocalBranches, in IList <IGitRef> currentRemoteBranches, GitRevision currentRevision, string currentRemote)
public static (string arguments, bool abort) Parse(string arguments, IGitModule module, IWin32Window owner, RevisionGridControl revisionGrid) { GitRevision selectedRevision = null; GitRevision currentRevision = null; IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>(); var selectedLocalBranches = new List <IGitRef>(); var selectedRemoteBranches = new List <IGitRef>(); var selectedRemotes = new List <string>(); var selectedBranches = new List <IGitRef>(); var selectedTags = new List <IGitRef>(); var currentLocalBranches = new List <IGitRef>(); var currentRemoteBranches = new List <IGitRef>(); var currentRemote = ""; var currentBranches = new List <IGitRef>(); var currentTags = new List <IGitRef>(); foreach (string option in Options) { if (string.IsNullOrEmpty(arguments)) { continue; } if (!Contains(arguments, option)) { continue; } if (currentRevision == null && option.StartsWith("c")) { currentRevision = GetCurrentRevision(module, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches); if (currentRevision == null) { return(arguments : null, abort : true); } if (currentLocalBranches.Count == 1) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, currentLocalBranches[0].Name)); } else { currentRemote = module.GetCurrentRemote(); if (string.IsNullOrEmpty(currentRemote)) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, AskToSpecify(currentLocalBranches, revisionGrid))); } } } else if (selectedRevision == null && revisionGrid != null && DependsOnSelectedRevision(option)) { allSelectedRevisions = revisionGrid.GetSelectedRevisions(); selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); if (selectedRevision == null) { return(arguments : null, abort : true); } } arguments = ParseScriptArguments(arguments, option, owner, revisionGrid, module, allSelectedRevisions, selectedTags, selectedBranches, selectedLocalBranches, selectedRemoteBranches, selectedRemotes, selectedRevision, currentTags, currentBranches, currentLocalBranches, currentRemoteBranches, currentRevision, currentRemote); if (arguments == null) { return(arguments : null, abort : true); } } return(arguments, abort : false); }
public void Setup() { _module = Substitute.For <IGitModule>(); _scriptHostControl = Substitute.For <IScriptHostControl>(); }
public void Init(IGitModule Module) { impact_loader = new ImpactLoader(Module); impact_loader.RespectMailmap = true; // respect the .mailmap file impact_loader.Updated += OnImpactUpdate; }
private static string GetAmendCommitPath(IGitModule module) { return(Path.Combine(module.GetGitDirectory(), "AMENDCOMMIT")); }
private void LoadModuleInfo(string command, IGitModule module, ILoadingTaskState taskState) { using (GitCommandsInstance git = new GitCommandsInstance(module)) { git.StreamOutput = true; git.CollectOutput = false; Process p = git.CmdStartProcess(Settings.GitCommand, command); // Read line string line = p.StandardOutput.ReadLine(); // Analyze commit listing while (!taskState.IsCanceled()) { Commit commit = new Commit(); // Reached the end ? if (line == null) break; // Look for commit delimiters if (!line.StartsWith("--- ")) { line = p.StandardOutput.ReadLine(); continue; } // Strip "--- " line = line.Substring(4); // Split date and author string[] header = line.Split(new string[] { " --- " }, 2, StringSplitOptions.RemoveEmptyEntries); if (header.Length != 2) continue; // Save author in variable commit.author = header[1]; // Parse commit date DateTime date = DateTime.Parse(header[0]).Date; // Calculate first day of the commit week date = commit.week = date.AddDays(-(int)date.DayOfWeek); // Reset commit data commit.data.Commits = 1; commit.data.AddedLines = 0; commit.data.DeletedLines = 0; // Parse commit lines while ((line = p.StandardOutput.ReadLine()) != null && !line.StartsWith("--- ") && !taskState.IsCanceled()) { // Skip empty line if (string.IsNullOrEmpty(line)) continue; string[] file_line = line.Split('\t'); if (file_line.Length >= 2) { if (file_line[0] != "-") commit.data.AddedLines += int.Parse(file_line[0]); if (file_line[1] != "-") commit.data.DeletedLines += int.Parse(file_line[1]); } } if (Updated != null && !taskState.IsCanceled()) Updated(commit); } } }
public IndexLockManager(IGitModule module) : this(module, new GitDirectoryResolver(), new FileSystem()) { }
public bool GitModuleIsRelevantToMe(IGitModule aModule) { return GetHostedRemotesForModule(aModule).Count > 0; }
private async Task GetRepositorySubmodulesStatusAsync(SubmoduleInfoResult result, IGitModule module, CancellationToken cancelToken, string noBranchText) { List <Task> tasks = new List <Task>(); foreach (var submodule in module.GetSubmodulesLocalPaths().OrderBy(submoduleName => submoduleName)) { cancelToken.ThrowIfCancellationRequested(); var name = submodule; string path = module.GetSubmoduleFullPath(submodule); if (AppSettings.DashboardShowCurrentBranch && !GitModule.IsBareRepository(path)) { name = name + " " + GetModuleBranch(path, noBranchText); } var smi = new SubmoduleInfo { Text = name, Path = path }; result.OurSubmodules.Add(smi); tasks.Add(GetSubmoduleStatusAsync(smi, cancelToken)); } await Task.WhenAll(tasks); }
public GitRemoteController(IGitModule module) { _module = module; Remotes = new BindingList<GitRemote>(); }