Thursday, 15 April 2010

.net - C# Git Command issue -


I am developing an app where I need to run the guit command with C #. I have used the process to run the command. If I am passing the username and password then the username or password is wrong, but this is the actual working code below my code: -

  Public static zero error (string gitCommand) {string strPassword = "password"; ProcessStartInfo gitInfo = newest processinfo (); Process gitprocess = new process (); GitInfo.CreateNoWindow = True; GitInfo.UserName = "UserName"; GitInfo.Password = Misc. Convert page (stripper); GitInfo.UseShellExecute = false; GitInfo.FileName = @ "C: \ Program Files (x86) \ Git \ bin \ git.exe"; // git repostory directory paths gitInfo.Arguments = gitCommand; // git command like "fetch orin" gitInfo.WorkingDirectory = @ "E: \ Code demo \ testrepo"; // YOUR_GIT_REPOSITORY_PATH where you want to copy the data gitInfo.RedirectStandardError = true; GitInfo.RedirectStandardOutput = True; (Var proc = new System.Diagnostics.Process ()) using {proc.StartInfo = gitInfo; Proc.Start (); Var output = proc.StandardOutput.ReadToEnd (); Var error = proc.StandardError.ReadToEnd (); Var logRaw = string.IsNullOrEmpty (Output) & amp; Amp; ! String.IsNullOrEmpty (error)? Error.Split ('\ n') .Oir (): Output. Sample ('\ n') .oir (); Proc.WaitForExit (); Proc.close (); }}  

You have two options first one git askpass witch "git config core To use ".askpass git-gui-askpass", set configuration for your git repo (or globally). Call it as the first command for your process here. The drawback is that every time you make a modified order it will ask for a password.

Or you can ask for your own executable witch once for the password, and you will have the option to store the password in your application. But here you have to be careful because if you do not store it properly it will be a security risk.


No comments:

Post a Comment