2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public class Checkout : Command
|
|
|
|
|
{
|
|
|
|
|
public Checkout(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Branch(string branch, Action<string> onProgress)
|
|
|
|
|
{
|
2021-05-26 03:43:28 -07:00
|
|
|
|
Args = $"checkout --progress {branch}";
|
|
|
|
|
TraitErrorAsOutput = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler = onProgress;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Branch(string branch, string basedOn, Action<string> onProgress)
|
|
|
|
|
{
|
2021-05-26 18:14:34 -07:00
|
|
|
|
Args = $"checkout --progress -b {branch} {basedOn}";
|
|
|
|
|
TraitErrorAsOutput = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler = onProgress;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool File(string file, bool useTheirs)
|
|
|
|
|
{
|
|
|
|
|
if (useTheirs)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"checkout --theirs -- \"{file}\"";
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"checkout --ours -- \"{file}\"";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool FileWithRevision(string file, string revision)
|
|
|
|
|
{
|
2023-08-17 23:13:32 -07:00
|
|
|
|
Args = $"checkout {revision} -- \"{file}\"";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Files(List<string> files)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
StringBuilder builder = new StringBuilder();
|
2021-04-29 06:22:17 -07:00
|
|
|
|
builder.Append("checkout -f -q --");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
foreach (var f in files)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
builder.Append(" \"");
|
|
|
|
|
builder.Append(f);
|
|
|
|
|
builder.Append("\"");
|
|
|
|
|
}
|
|
|
|
|
Args = builder.ToString();
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
2021-05-26 03:43:28 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
protected override void OnReadline(string line)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler?.Invoke(line);
|
2021-05-26 03:43:28 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
private Action<string> _outputHandler;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|