public static string GitQueryCurrentBranch( this ICakeContext context, GitToolSettings toolSettings, GitQueryCurrentBranchConfig config = null ) { var runner = new GitQueryCurrentBranchRunner( context, toolSettings ); return runner.Run( config ); }
public static string GitQueryCurrentBranch( this ICakeContext context, DirectoryPath repoRoot, GitQueryCurrentBranchConfig config = null ) { var toolSettings = new GitToolSettings { WorkingDirectory = repoRoot }; return GitQueryCurrentBranch( context, toolSettings, config ); }
// ---------------- Functions ---------------- /// <summary> /// Runs git on the local repository and returns /// the name of the current branch. /// </summary> /// <param name="config"> /// Configuration. If null, it grabs the configuration /// from the passed in command-line arguments. /// </param> public string Run(GitQueryCurrentBranchConfig config = null) { if (config == null) { config = ArgumentBinder.FromArguments <GitQueryCurrentBranchConfig>(this.context); } string branch = null; string onStdOut(string line) { if (string.IsNullOrWhiteSpace(line) == false) { branch = line; } return(line); }; ProcessSettings processSettings = new ProcessSettings { Arguments = ProcessArgumentBuilder.FromString("rev-parse --abbrev-ref HEAD"), RedirectStandardOutput = true, RedirectedStandardOutputHandler = onStdOut }; this.Run(this.toolSettings, processSettings.Arguments, processSettings, null); if (branch == null) { throw new InvalidOperationException( "Could not get the current branch from Git" ); } if (config.NoPrint == false) { context.Information($"Current Branch: {branch}"); } return(branch); }