/// <summary> /// Gets the commit info for submodule. /// </summary> public static CommitData GetCommitData(GitModule module, string sha1, ref string error) { if (module == null) throw new ArgumentNullException("module"); if (sha1 == null) throw new ArgumentNullException("sha1"); //Do not cache this command, since notes can be added string arguments = string.Format(CultureInfo.InvariantCulture, "log -1 --pretty=\"format:"+LogFormat+"\" {0}", sha1); var info = module.RunGitCmd(arguments, GitModule.LosslessEncoding); if (info.Trim().StartsWith("fatal")) { error = "Cannot find commit " + sha1; return null; } int index = info.IndexOf(sha1) + sha1.Length; if (index < 0) { error = "Cannot find commit " + sha1; return null; } if (index >= info.Length) { error = info; return null; } CommitData commitInformation = CreateFromFormatedData(info, module); return commitInformation; }
public static bool IsBinaryFile(GitModule aModule, string fileName) { var t = IsBinaryAccordingToGitAttributes(aModule, fileName); if (t.HasValue) return t.Value; return HasMatchingExtension(BinaryExtensions, fileName); }
public GitRef(GitModule module, string guid, string completeName, string remote) { Module = module; Guid = guid; Selected = false; CompleteName = completeName; Remote = remote; if (CompleteName.StartsWith("refs/heads/")) { IsHead = true; } else if (CompleteName.StartsWith("refs/tags/")) { IsTag = true; } else if (CompleteName.StartsWith("refs/remotes/")) { IsRemote = true; } else if (CompleteName.StartsWith("refs/bisect/")) { IsBisect = true; } ParseName(); _remoteSettingName = String.Format("branch.{0}.remote", Name); _mergeSettingName = String.Format("branch.{0}.merge", Name); }
public void GetSubmoduleNamesFromDiffTest() { GitModule testModule = new GitModule("D:\\Test\\SuperProject"); // Submodule name without spaces in the name string text = "diff --git a/Externals/conemu-inside b/Externals/conemu-inside\nindex a17ea0c..b5a3d51 160000\n--- a/Externals/conemu-inside\n+++ b/Externals/conemu-inside\n@@ -1 +1 @@\n-Subproject commit a17ea0c8ebe9d8cd7e634ba44559adffe633c11d\n+Subproject commit b5a3d51777c85a9aeee534c382b5ccbb86b485d3\n"; string fileName = "Externals/conemu-inside"; GitSubmoduleStatus status = GitCommandHelpers.GetSubmoduleStatus(text, testModule, fileName); Assert.AreEqual(status.Commit, "b5a3d51777c85a9aeee534c382b5ccbb86b485d3"); Assert.AreEqual(status.Name, fileName); Assert.AreEqual(status.OldCommit, "a17ea0c8ebe9d8cd7e634ba44559adffe633c11d"); Assert.AreEqual(status.OldName, fileName); // Submodule name with spaces in the name text = "diff --git a/Assets/Core/Vehicle Physics core assets b/Assets/Core/Vehicle Physics core assets\nindex 2fb8851..0cc457d 160000\n--- a/Assets/Core/Vehicle Physics core assets\t\n+++ b/Assets/Core/Vehicle Physics core assets\t\n@@ -1 +1 @@\n-Subproject commit 2fb88514cfdc37a2708c24f71eca71c424b8d402\n+Subproject commit 0cc457d030e92f804569407c7cd39893320f9740\n"; fileName = "Assets/Core/Vehicle Physics core assets"; status = GitCommandHelpers.GetSubmoduleStatus(text, testModule, fileName); Assert.AreEqual(status.Commit, "0cc457d030e92f804569407c7cd39893320f9740"); Assert.AreEqual(status.Name, fileName); Assert.AreEqual(status.OldCommit, "2fb88514cfdc37a2708c24f71eca71c424b8d402"); Assert.AreEqual(status.OldName, fileName); }
public static IRepositoryHostPlugin TryGetGitHosterForModule(GitModule aModule) { if (!aModule.ValidWorkingDir()) return null; return GitHosters.FirstOrDefault(gitHoster => gitHoster.GitModuleIsRelevantToMe(aModule)); }
public GitUICommands(GitModule module) { Module = module; RepoChangedNotifier = new ActionNotifier( () => InvokeEvent(null, PostRepositoryChanged)); Notifications = NotificationManager.Get(this); }
private void InitClick(object sender, EventArgs e) { if (string.IsNullOrEmpty(Directory.Text)) { MessageBox.Show(this, _chooseDirectory.Text,_chooseDirectoryCaption.Text); return; } if (File.Exists(Directory.Text)) { MessageBox.Show(this, _chooseDirectoryNotFile.Text,_chooseDirectoryNotFileCaption.Text); return; } GitModule module = new GitModule(Directory.Text); if (!System.IO.Directory.Exists(module.WorkingDir)) System.IO.Directory.CreateDirectory(module.WorkingDir); MessageBox.Show(this, module.Init(Central.Checked, Central.Checked), _initMsgBoxCaption.Text); if (GitModuleChanged != null) GitModuleChanged(this, new GitModuleEventArgs(module)); Repositories.AddMostRecentRepository(Directory.Text); Close(); }
/// <summary> /// Gets branches which contain the given commit. /// If both local and remote branches are requested, remote branches are prefixed with "remotes/" /// (as returned by git branch -a) /// </summary> /// <param name="sha1">The sha1.</param> /// <param name="getLocal">Pass true to include local branches</param> /// <param name="getRemote">Pass true to include remote branches</param> /// <returns></returns> public static IEnumerable<string> GetAllBranchesWhichContainGivenCommit(GitModule module, string sha1, bool getLocal, bool getRemote) { string args = "--contains " + sha1; if (getRemote && getLocal) args = "-a "+args; else if (getRemote) args = "-r "+args; else if (!getLocal) return new string[]{}; string info = module.RunGitCmd("branch " + args, GitModule.SystemEncoding); if (info.Trim().StartsWith("fatal") || info.Trim().StartsWith("error:")) return new List<string>(); string[] result = info.Split(new[] { '\r', '\n', '*' }, StringSplitOptions.RemoveEmptyEntries); // Remove symlink targets as in "origin/HEAD -> origin/master" for (int i = 0; i < result.Length; i++) { string item = result[i].Trim(); int idx; if (getRemote && ((idx = item.IndexOf(" ->")) >= 0)) { item = item.Substring(0, idx); } result[i] = item; } return result; }
public static string GetSubmoduleText(GitModule superproject, string name, string hash) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Submodule " + name); sb.AppendLine(); GitModule module = superproject.GetSubmodule(name); if (module.IsValidGitWorkingDir()) { string error = ""; CommitData data = CommitData.GetCommitData(module, hash, ref error); if (data == null) { sb.AppendLine("Commit hash:\t" + hash); return sb.ToString(); } string header = data.GetHeaderPlain(); string body = "\n" + data.Body.Trim(); sb.AppendLine(header); sb.Append(body); } else sb.AppendLine("Commit hash:\t" + hash); return sb.ToString(); }
public static bool RunScript(IWin32Window owner, GitModule aModule, string script, RevisionGrid revisionGrid) { if (string.IsNullOrEmpty(script)) return false; ScriptInfo scriptInfo = ScriptManager.GetScript(script); if (scriptInfo == null) { MessageBox.Show(owner, "Cannot find script: " + script, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } if (string.IsNullOrEmpty(scriptInfo.Command)) return false; string argument = scriptInfo.Arguments; foreach (string option in Options) { if (string.IsNullOrEmpty(argument) || !argument.Contains(option)) continue; if (!option.StartsWith("{s")) continue; if (revisionGrid != null) continue; MessageBox.Show(owner, string.Format("Option {0} is only supported when started from revision grid.", option), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return RunScript(owner, aModule, scriptInfo, revisionGrid); }
public void Execute(GitModule module) { if (Dto.Amend) Dto.Result = module.RunGitCmd("commit --amend -m \"" + Dto.Message + "\""); else Dto.Result = module.RunGitCmd("commit -m \"" + Dto.Message + "\""); }
public CommonLogic(GitModule aModule) { Module = aModule; if (aModule != null) { var repoDistGlobalSettings = RepoDistSettings.CreateGlobal(false); var repoDistPulledSettings = RepoDistSettings.CreateDistributed(Module, false); var repoDistLocalSettings = RepoDistSettings.CreateLocal(Module, false); var repoDistEffectiveSettings = new RepoDistSettings( new RepoDistSettings(repoDistGlobalSettings, repoDistPulledSettings.SettingsCache), repoDistLocalSettings.SettingsCache); var configFileGlobalSettings = ConfigFileSettings.CreateGlobal(false); var configFileLocalSettings = ConfigFileSettings.CreateLocal(Module, false); var configFileEffectiveSettings = new ConfigFileSettings(configFileGlobalSettings, configFileLocalSettings.SettingsCache); RepoDistSettingsSet = new RepoDistSettingsSet( repoDistEffectiveSettings, repoDistLocalSettings, repoDistPulledSettings, repoDistGlobalSettings); ConfigFileSettingsSet = new ConfigFileSettingsSet( configFileEffectiveSettings, configFileLocalSettings, configFileGlobalSettings); } }
public FormDiff(GitModule module) { InitializeComponent(); Translate(); module_ = module; diffViewer.ExtraDiffArgumentsChanged += DiffViewerExtraDiffArgumentsChanged; }
public void CheckIsCommitNewer(GitModule submodule) { if (submodule == null || !submodule.ValidWorkingDir()) return; string baseCommit = submodule.GetMergeBase(Commit, OldCommit); IsCommitNewer = baseCommit == OldCommit; }
public void GetAllBranchesWhichContainGivenCommitTestReturnsEmptyList() { var module = new GitModule(""); var actualResult = module.GetAllBranchesWhichContainGivenCommit("fakesha1", false, false); Assert.IsNotNull(actualResult); Assert.IsTrue(!actualResult.Any()); }
public void CheckSubmoduleStatus(GitModule submodule) { Status = SubmoduleStatus.NewSubmodule; if (submodule == null) return; Status = submodule.CheckSubmoduleStatus(Commit, OldCommit); }
public FormDiff(GitModule module, GitRevision revision) { InitializeComponent(); Translate(); module_ = module; RevisionGrid.SetSelectedRevision(revision); }
public CommitData GetOldCommitData(GitModule submodule) { if (submodule == null || !submodule.ValidWorkingDir()) return null; string error = ""; return CommitData.GetCommitData(submodule, OldCommit, ref error); }
public static new bool ShowDialog(IWin32Window owner, GitModule module, string arguments) { using (var formRemoteProcess = new FormRemoteProcess(module, arguments)) { formRemoteProcess.ShowDialog(owner); return !formRemoteProcess.ErrorOccurred(); } }
private static void CheckWorkingDir(string path) { GitModule module = new GitModule(path); //Should not contain double slashes -> \\ Assert.IsFalse(module.WorkingDir.Contains("\\\\"), "WorkingDir" + module.WorkingDir + "\n" + GetCurrentDir()); //Should end with slash Assert.IsTrue(module.WorkingDir.EndsWith("\\"), "WorkingDir" + module.WorkingDir + "\n" + GetCurrentDir()); }
public void LoadModule(GitModule module) { if (UICommands != null && UICommands.Module == module) { return; } UICommands = new GitUICommands(module); }
public static bool AbortCurrentAction(GitModule module) { if (ShowAbortMessage()) { module.ResetHard(""); return true; } return false; }
public LocalSettingsSettingsPage(CommonLogic commonLogic, CheckSettingsLogic checkSettingsLogic, GitModule gitModule) : this() { _commonLogic = commonLogic; _checkSettingsLogic = checkSettingsLogic; _gitModule = gitModule; _commonLogic.FillEncodings(Local_FilesEncoding); }
public FormMergeSubmodule(GitUICommands aCommands, string filename) : base(aCommands) { InitializeComponent(); Translate(); lbSubmodule.Text = filename; this.filename = filename; this.submodule = Module.GetSubmodule(filename); }
public FormProcess(string process, string arguments, GitModule module, string input, bool useDialogSettings) : base(useDialogSettings) { ProcessCallback = processStart; AbortCallback = processAbort; ProcessString = process ?? Settings.GitCommand; WorkingDir = module == null ? Settings.WorkingDir : module.WorkingDir; ProcessArguments = arguments; Remote = ""; ProcessInput = input; }
private void FetchData() { Loading.Visible = true; CommitCount.Text = ""; var dict = new Dictionary<string, HashSet<string>>(); var items = CommitCounter.GroupAllCommitsByContributor().Item1; if (cbIncludeSubmodules.Checked) { IList<string> submodules = Settings.Module.GetSubmodulesNames(); GitModule submodule = new GitModule(); foreach (var submoduleName in submodules) { submodule.WorkingDir = Settings.Module.WorkingDir + submoduleName + Settings.PathSeparator.ToString(); if (submodule.ValidWorkingDir()) { var submoduleItems = CommitCounter.GroupAllCommitsByContributor(submodule).Item1; foreach (var keyValuePair in submoduleItems) { if (!dict.ContainsKey(keyValuePair.Key)) dict.Add(keyValuePair.Key, new HashSet<string>()); dict[keyValuePair.Key].Add(submodule.SubmoduleName); if (items.ContainsKey(keyValuePair.Key)) items[keyValuePair.Key] += keyValuePair.Value; else items.Add(keyValuePair.Key, keyValuePair.Value); } } } } var sortedItems = from pair in items orderby pair.Value descending select pair; foreach (var keyValuePair in sortedItems) { string submodulesList = ""; if (dict.ContainsKey(keyValuePair.Key)) { var sub = dict[keyValuePair.Key]; if (sub.Count == 1) { foreach (var item in dict[keyValuePair.Key]) submodulesList = " [" + item + "]"; } else submodulesList = " [" + sub.Count.ToString() + " submodules]"; } CommitCount.Text += string.Format("{0,6} - {1}{2}\r\n", keyValuePair.Value, keyValuePair.Key, submodulesList); } Loading.Visible = false; }
/// <summary> /// Gets the commit info for module. /// </summary> /// <param name="module">Git module.</param> /// <param name="sha1">The sha1.</param> /// <returns></returns> public static CommitInformation GetCommitInfo(GitModule module, string sha1) { string error = ""; CommitData data = CommitData.GetCommitData(module, sha1, ref error); if (data == null) return new CommitInformation(error, ""); string header = data.GetHeader(); string body = "\n" + WebUtility.HtmlEncode(data.Body.Trim()); return new CommitInformation(header, body); }
private void BranchDropDown(object sender, EventArgs e) { GitModule module = new GitModule(Directory.Text); Branch.DisplayMember = "Name"; IList<GitRef> heads; if (module.IsValidGitWorkingDir()) heads = module.GetRefs(false); else heads = new List<GitRef>(); heads.Insert(0, GitRef.NoHead(module)); Branch.DataSource = heads; }
public static void RunEventScripts(GitModule aModule, ScriptEvent scriptEvent) { foreach (ScriptInfo scriptInfo in GetScripts()) if (scriptInfo.Enabled && scriptInfo.OnEvent == scriptEvent) { if (scriptInfo.AskConfirmation) if (MessageBox.Show(String.Format("Do you want to execute '{0}'?", scriptInfo.Name), "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) continue; ScriptRunner.RunScript(aModule, scriptInfo.Name, null); } }
public static void SetCommitMessage(GitModule module, string commitMessageText) { if (String.IsNullOrEmpty(commitMessageText)) { File.Delete(GetCommitMessagePath(module)); return; } using (var textWriter = new StreamWriter(GetCommitMessagePath(module), false, module.CommitEncoding)) { textWriter.Write(commitMessageText); } }