Skip to content

Instantly share code, notes, and snippets.

@srdjan
Created December 11, 2012 17:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srdjan/4260421 to your computer and use it in GitHub Desktop.
Save srdjan/4260421 to your computer and use it in GitHub Desktop.
Custom Git task for FAKE
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