/// <summary> /// Reload status fields in the context of a status class /// </summary> private void Status() { XY.Clear(); AltFile.Clear(); ExecResult result = Repo.Run("status --porcelain -uall -z"); if (!result.Success()) { return; } string[] response = result.stdout .Replace('/', Path.DirectorySeparatorChar) // Correct the path slash on Windows .Split(("\0") .ToCharArray(), StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < response.Length; i++) { string s = response[i].Substring(3); string code = response[i].Substring(0, 2); XY[s] = code; if ("RC".Contains(response[i][0])) { i++; AltFile[s] = response[i]; } } }
/// <summary> /// Refresh the list of remotes for the given repo while keeping the /// existing passwords and push commands /// </summary> public void Refresh(ClassRepo repo) { // Build the new list while picking up password fields from the existing list Dictionary <string, Remote> newlist = new Dictionary <string, Remote>(); string[] response = new[] { string.Empty }; ExecResult result = repo.Run("remote -v"); if (result.Success()) { response = result.stdout.Split((Environment.NewLine).ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string s in response) { Remote r = new Remote(); // Split the resulting remote repo name/url into separate strings string[] url = s.Split("\t ".ToCharArray()); string name = url[0]; // Find if the name exists in the main list and save off the password from it if (newlist.ContainsKey(name)) { r = newlist[name]; } if (remotes.ContainsKey(name)) { r.Password = remotes[name].Password; r.PushCmd = remotes[name].PushCmd; } // Set all other fields that we refresh every time r.Name = name; if (url[2] == "(fetch)") { r.UrlFetch = url[1]; } if (url[2] == "(push)") { r.UrlPush = url[1]; } // Add it to the new list newlist[name] = r; } } // Set the newly built list to be the master list remotes = newlist; // Fixup the new current string name if (!remotes.ContainsKey(Current)) { Current = remotes.Count > 0 ? remotes.ElementAt(0).Key : ""; } }
/// <summary> /// Sets or removes a local git configuration value. /// If the value is null or empty string, the key will be removed (unset). /// </summary> public static void SetLocal(ClassRepo repo, string key, string value) { string setkey = string.IsNullOrEmpty(value) ? "--unset " : ""; string val = string.IsNullOrEmpty(value) ? "" : " \"" + value + "\""; string cmd = setkey + key + val; if (repo.Run("config --local " + cmd).Success() == false) App.PrintLogMessage("Error setting local git config parameter!", MessageType.Error); }
/// <summary> /// Returns a value of a local git configuration key /// </summary> public static string GetLocal(ClassRepo repo, string key) { ExecResult result = repo.Run("config --local --get " + key); if (result.Success()) return result.stdout; App.PrintLogMessage("Error getting local git config parameter!", MessageType.Error); return string.Empty; }
/// <summary> /// Sets or removes a local git configuration value. /// If the value is null or empty string, the key will be removed (unset). /// </summary> public static void SetLocal(ClassRepo repo, string key, string value) { string setkey = string.IsNullOrEmpty(value) ? "--unset " : ""; string val = string.IsNullOrEmpty(value) ? "" : " \"" + value + "\""; string cmd = setkey + key + val; if (repo.Run("config --local " + cmd).Success() == false) { App.PrintLogMessage("Error setting local git config parameter!", MessageType.Error); } }
/// <summary> /// Returns a value of a local git configuration key /// </summary> public static string GetLocal(ClassRepo repo, string key) { ExecResult result = repo.Run("config --local --get " + key); if (result.Success()) { return(result.stdout); } App.PrintLogMessage("Error getting local git config parameter!", MessageType.Error); return(string.Empty); }
/// <summary> /// Refresh the list of remotes for the given repo while keeping the /// existing passwords and push commands /// </summary> public void Refresh(ClassRepo repo) { // Build the new list while picking up password fields from the existing list Dictionary<string, Remote> newlist = new Dictionary<string, Remote>(); string[] response = new[] {string.Empty}; ExecResult result = repo.Run("remote -v"); if (result.Success()) { response = result.stdout.Split((Environment.NewLine).ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string s in response) { Remote r = new Remote(); // Split the resulting remote repo name/url into separate strings string[] url = s.Split("\t ".ToCharArray()); string name = url[0]; // Find if the name exists in the main list and save off the password from it if (newlist.ContainsKey(name)) r = newlist[name]; if (remotes.ContainsKey(name)) { r.Password = remotes[name].Password; r.PushCmd = remotes[name].PushCmd; } // Set all other fields that we refresh every time r.Name = name; if (url[2] == "(fetch)") r.UrlFetch = url[1]; if (url[2] == "(push)") r.UrlPush = url[1]; // Add it to the new list newlist[name] = r; } } // Set the newly built list to be the master list remotes = newlist; // Fixup the new current string name if (!remotes.ContainsKey(Current)) Current = remotes.Count > 0 ? remotes.ElementAt(0).Key : ""; }
/// <summary> /// Add new remote repository /// </summary> private void BtAddClick(object sender, EventArgs e) { ClassRemotes.Remote remote = new ClassRemotes.Remote(); FormRemoteAddEdit remoteAddEdit = new FormRemoteAddEdit(); remoteAddEdit.Prepare(FormRemoteAddEdit.Function.Add, remote); if (remoteAddEdit.ShowDialog() == DialogResult.OK) { remote = remoteAddEdit.Get(); ExecResult result = _repo.Run("remote add " + remote.Name + " " + remote.UrlFetch); if (result.Success()) { _repo.Remotes.SetPassword(remote.Name, remote.Password); _repo.Remotes.SetPushCmd(remote.Name, remote.PushCmd); SetRepo(_repo); } else { MessageBox.Show("Git is unable to add this remote repository.", "Add remote repository", MessageBoxButtons.OK, MessageBoxIcon.Error); App.PrintStatusMessage(result.stderr, MessageType.Error); } } }