/// <summary> /// Constructor creates a shell executable file that echoes the PASSWORD /// environment variable when called. When GIT_ASKPASS is present, Git /// obtains a password for its HTTPS operations by calling it. /// </summary> public ClassGitPasswd() { // WAR: Do a different kind of shell script dependent on the OS) if (ClassUtils.IsMono()) { // Mono: Use the Shell script pathPasswordBatchHelper = Path.Combine(App.AppHome, "passwd.sh"); File.WriteAllText(pathPasswordBatchHelper, "echo $PASSWORD" + Environment.NewLine); // Set the execute bit if (Exec.Run("chmod", "+x " + pathPasswordBatchHelper).Success() == false) { App.PrintLogMessage("ClassGitPasswd: Unable to chmod +x on " + pathPasswordBatchHelper, MessageType.Error); } } else { // Windows: Use the CMD BAT script // Note: Using "App.AppHome" directory to host the batch helper file // fails on XP where that directory has spaces in the name ("Documents and Settings") // which git cannot handle in this context. Similarly, git will fail with // any other path that contains a space. // This redirection is used to provide the password in an automated way. pathPasswordBatchHelper = Path.Combine(Path.GetTempPath(), "passwd.bat"); File.WriteAllText(pathPasswordBatchHelper, "@echo %PASSWORD%" + Environment.NewLine); pathPasswordBatchHelper = ClassUtils.GetShortPathName(pathPasswordBatchHelper); } ClassUtils.AddEnvar("GIT_ASKPASS", pathPasswordBatchHelper); App.PrintLogMessage("Created HTTP password helper file: " + pathPasswordBatchHelper, MessageType.General); }
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> /// Constructor class function, create batch file helper in the temp space /// </summary> public ClassSSH() { string pathHelpertLong = ClassUtils.WriteResourceToFile(Path.GetTempPath(), "git_ssh_helper.sh", Properties.Resources.git_ssh_helper); pathHelper = ClassUtils.GetShortPathName(pathHelpertLong); // Make the batch file executable: this trick will only work with Mono File.SetAttributes(pathHelper, (FileAttributes)((uint)File.GetAttributes(pathHelper) | 0x80000000)); App.PrintLogMessage("SSH helper path:" + pathHelper, MessageType.Error); ClassUtils.AddEnvar("GIT_SSH", pathHelper); }
/// <summary> /// Constructor class function, create executables in the temp space /// </summary> public ClassPutty() { string pathPageantLong = ClassUtils.WriteResourceToFile(Path.GetTempPath(), "pageant.exe", Properties.Resources.pageant); string pathPlinkLong = ClassUtils.WriteResourceToFile(Path.GetTempPath(), "plink.exe", Properties.Resources.plink); string pathPuttyGenLong = ClassUtils.WriteResourceToFile(Path.GetTempPath(), "puttygen.exe", Properties.Resources.puttygen); pathPageant = ClassUtils.GetShortPathName(pathPageantLong); pathPlink = ClassUtils.GetShortPathName(pathPlinkLong); pathPuttyGen = ClassUtils.GetShortPathName(pathPuttyGenLong); ClassUtils.AddEnvar("PLINK_PROTOCOL", "ssh"); ClassUtils.AddEnvar("GIT_SSH", pathPlink); // Run the daemon process, update keys RunPageantUpdateKeys(); }