Skip to content

Commit

Permalink
Add git-checkout (#11)
Browse files Browse the repository at this point in the history
* Add git-checkout

* Add create option to Checkout
  • Loading branch information
jzebedee authored Mar 15, 2019
1 parent ca697bb commit 77767c8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/corgit/Corgit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public async Task<IEnumerable<GitCommit>> LogAsync(GitArguments.LogOptions optio
public Task<ExecutionResult> CommitAsync(string message = "", GitArguments.CommitOptions options = default)
=> RunGitAsync(GitArguments.Commit(options), message);

public Task<ExecutionResult> CheckoutAsync(string treeish, IEnumerable<string> paths = null, GitArguments.CheckoutOptions options = default)
=> RunGitAsync(GitArguments.Checkout(treeish, paths, options));

public Task<ExecutionResult> AddAsync(IEnumerable<string> paths)
=> RunGitAsync(GitArguments.Add(paths));

Expand Down
47 changes: 47 additions & 0 deletions src/corgit/GitArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,53 @@ public static IEnumerable<string> 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<string> Checkout(string treeish, IEnumerable<string> 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<string> Status()
{
yield return "--no-optional-locks";
Expand Down

0 comments on commit 77767c8

Please sign in to comment.