diff --git a/src/corgit/Corgit.cs b/src/corgit/Corgit.cs index 53ad816..27b2ae3 100644 --- a/src/corgit/Corgit.cs +++ b/src/corgit/Corgit.cs @@ -142,6 +142,9 @@ public async Task> LogAsync(GitArguments.LogOptions optio public Task CommitAsync(string message = "", GitArguments.CommitOptions options = default) => RunGitAsync(GitArguments.Commit(options), message); + public Task CheckoutAsync(string treeish, IEnumerable paths = null, GitArguments.CheckoutOptions options = default) + => RunGitAsync(GitArguments.Checkout(treeish, paths, options)); + public Task AddAsync(IEnumerable paths) => RunGitAsync(GitArguments.Add(paths)); diff --git a/src/corgit/GitArguments.cs b/src/corgit/GitArguments.cs index ff53c58..78d135e 100644 --- a/src/corgit/GitArguments.cs +++ b/src/corgit/GitArguments.cs @@ -145,6 +145,53 @@ public static IEnumerable Config(string key, string value = null, string } } + public struct CheckoutOptions + { + public readonly bool Track; + public readonly bool Create; + public readonly string StartPoint; + + public CheckoutOptions(bool track = false, bool create = false, string startPoint = null) + { + Track = track; + Create = create; + StartPoint = startPoint; + } + } + public static IEnumerable Checkout(string treeish, IEnumerable paths = null, GitArguments.CheckoutOptions options = default) + { + if (string.IsNullOrEmpty(treeish)) + throw new ArgumentNullException(nameof(treeish)); + + yield return "checkout"; + yield return "-q"; + + if(options.Create) + { + yield return "-b"; + if(!string.IsNullOrEmpty(options.StartPoint)) + { + yield return options.StartPoint; + } + } + + if (options.Track) + { + yield return "--track"; + } + + yield return treeish; + + if (paths != null) + { + yield return "--"; + foreach (var path in paths) + { + yield return path; + } + } + } + public static IEnumerable Status() { yield return "--no-optional-locks";