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-04-11 05:50:19 -07:00
|
|
|
|
public bool UseTheirs(List<string> files)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-04-11 05:50:19 -07:00
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
builder.Append("checkout --theirs --");
|
|
|
|
|
foreach (var f in files)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-04-11 05:50:19 -07:00
|
|
|
|
builder.Append(" \"");
|
|
|
|
|
builder.Append(f);
|
|
|
|
|
builder.Append("\"");
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
2024-04-11 05:50:19 -07:00
|
|
|
|
Args = builder.ToString();
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool UseMine(List<string> files)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
builder.Append("checkout --ours --");
|
|
|
|
|
foreach (var f in files)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-04-11 05:50:19 -07:00
|
|
|
|
builder.Append(" \"");
|
|
|
|
|
builder.Append(f);
|
|
|
|
|
builder.Append("\"");
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-04-11 05:50:19 -07:00
|
|
|
|
Args = builder.ToString();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
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-05-25 10:27:42 -07:00
|
|
|
|
public bool Commit(string commitId, Action<string> onProgress)
|
|
|
|
|
{
|
|
|
|
|
Args = $"checkout --detach --progress {commitId}";
|
|
|
|
|
TraitErrorAsOutput = true;
|
|
|
|
|
_outputHandler = onProgress;
|
|
|
|
|
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
|
|
|
|
}
|