/// <summary> /// Callback on the command line text ready. /// We execute a custom (immediate) command which can be either a direct git /// command or a shell (command prompt?) command. /// Several commands may be separated by "&&" token. This accomodates Gerrit /// code review process and its shortcuts that can be easily pasted. /// </summary> private void CmdBoxTextReady(object sender, string cmd) { foreach (string command in cmd.Split(new[] { " && " }, StringSplitOptions.RemoveEmptyEntries)) { // Print out the command itself App.PrintStatusMessage(command, MessageType.Command); // If the command text started with a command 'git', remove it string[] tokens = command.Split(' '); string args = String.Join(" ", tokens, 1, tokens.Count() - 1); // We are guaranteed to have at least one token (by the TextBoxEx control) string run; if (tokens[0].ToLower() == "git") { // Command is a git command: execute it run = ClassGit.Run(args).ToString(); } else { // Command is an arbitrary (command line type) command // Use the command shell to execute it run = ClassUtils.ExecuteShellCommand(tokens[0], args); } App.PrintStatusMessage(run, MessageType.Output); } }
/// <summary> /// Start scanning at the time the form is first shown /// </summary> private void FormNewRepoScanAddShown(object sender, EventArgs e) { enableAdd = true; int count = 1; // Create each of the repos for the selected directories foreach (var d in dirs) { if (enableAdd == false) { return; } try { // Update progress bar and make sure it gets painted progressBar.Value = count++; Thread.Sleep(1); textRepo.Text = d; Application.DoEvents(); Directory.SetCurrentDirectory(d); if (ClassGit.Run("init").Success() == false) { throw new ClassException("init failed."); } App.Repos.Add(d); } catch (Exception ex) { App.PrintLogMessage("Unable to add repo: " + ex.Message, MessageType.Error); App.PrintStatusMessage(ex.Message, MessageType.Error); } } DialogResult = DialogResult.OK; }
public ExecResult Run(string args, bool async) { ExecResult output = new ExecResult(); try { Directory.SetCurrentDirectory(Root); // Set the HTTPS password string password = Remotes.GetPassword(""); ClassUtils.AddEnvar("PASSWORD", password); // The Windows limit to the command line argument length is about 8K // We may hit that limit when doing operations on a large number of files. // // However, when sending a long list of files, git was hanging unless // the total length was much less than that, so I set it to about 2000 chars // which seemed to work fine. if (args.Length < 2000) { return(ClassGit.Run(args, async)); } // Partition the args into "[command] -- [set of file chunks < 2000 chars]" // Basically we have to rebuild the command into multiple instances with // same command but with file lists not larger than about 2K int i = args.IndexOf(" -- ") + 3; string cmd = args.Substring(0, i + 1); args = args.Substring(i); // We separate git command up to and until the list of files App.PrintLogMessage("Processing large amount of files: please wait...", MessageType.General); // Add files individually up to the length limit using the starting " file delimiter string[] files = args.Split(new [] { " \"" }, StringSplitOptions.RemoveEmptyEntries); // Note: files in the list are now stripped from their initial " character! i = 0; do { StringBuilder batch = new StringBuilder(2100); while (batch.Length < 2000 && i < files.Length) { batch.Append("\"" + files[i++] + " "); } output = ClassGit.Run(cmd + batch, async); if (output.Success() == false) { break; } } while (i < files.Length); } catch (Exception ex) { App.PrintLogMessage(ex.Message, MessageType.Error); } return(output); }
/// <summary> /// Sets or removes a global git configuration value. /// If the value is null or empty string, the key will be removed (unset). /// </summary> public static void SetGlobal(string key, string value) { string setkey = string.IsNullOrEmpty(value) ? "--unset " : ""; string val = string.IsNullOrEmpty(value) ? "" : " \"" + value + "\""; string cmd = setkey + key + val; if (ClassGit.Run("config --global " + cmd).Success() == false) { App.PrintLogMessage("Error setting global git config parameter!", MessageType.Error); } }
/// <summary> /// Returns a value of a global git configuration key /// </summary> public static string GetGlobal(string key) { ExecResult result = ClassGit.Run("config --global --get " + key); if (result.Success()) { return(result.stdout); } App.PrintLogMessage("Error getting global git config parameter!", MessageType.Error); return(String.Empty); }