Created
December 11, 2012 17:20
-
-
Save srdjan/4260421 to your computer and use it in GitHub Desktop.
Custom Git task for FAKE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
namespace MyFakeTasks | |
{ | |
public class GitTasks | |
{ | |
public static int Pull(string workingDirectory) | |
{ | |
var processStartInfo = new ProcessStartInfo(); | |
processStartInfo.CreateNoWindow = true; | |
processStartInfo.RedirectStandardError = true; | |
processStartInfo.RedirectStandardOutput = true; | |
processStartInfo.FileName = @"C:\Program Files (x86)\Git\bin\git.exe"; | |
processStartInfo.UseShellExecute = false; | |
var result = gitPull(processStartInfo, workingDirectory); | |
Console.WriteLine(result); | |
return result; | |
} | |
static int gitPull(ProcessStartInfo processStartInfo, string workingDirectory) | |
{ | |
var process = new Process(); | |
processStartInfo.Arguments = "pull"; | |
processStartInfo.WorkingDirectory = workingDirectory; | |
process.StartInfo = processStartInfo; | |
process.Start(); | |
var stdErrStr = process.StandardError.ReadToEnd(); | |
var stdOutStr = process.StandardOutput.ReadToEnd(); | |
process.WaitForExit(); | |
process.Close(); | |
Console.Write(stdErrStr.Any() ? stdErrStr : stdOutStr); | |
return stdOutStr.Contains("Already up-to-date.") ? 0 : 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment