2024-07-09 02:58:17 -07:00
|
|
|
|
using System.IO;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public class Commit : Command
|
|
|
|
|
{
|
2024-10-22 18:45:52 -07:00
|
|
|
|
public Commit(string repo, string message, bool amend, bool signOff)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-10-22 18:45:52 -07:00
|
|
|
|
_tmpFile = Path.GetTempFileName();
|
|
|
|
|
File.WriteAllText(_tmpFile, message);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2024-07-09 02:56:23 -07:00
|
|
|
|
TraitErrorAsOutput = true;
|
2024-10-22 18:45:52 -07:00
|
|
|
|
Args = $"commit --allow-empty --file=\"{_tmpFile}\"";
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (amend)
|
|
|
|
|
Args += " --amend --no-edit";
|
2024-10-22 18:45:52 -07:00
|
|
|
|
if (signOff)
|
|
|
|
|
Args += " --signoff";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-10-22 18:45:52 -07:00
|
|
|
|
|
|
|
|
|
public bool Run()
|
|
|
|
|
{
|
|
|
|
|
var succ = Exec();
|
2024-10-23 00:28:09 -07:00
|
|
|
|
|
2024-10-22 18:45:52 -07:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Delete(_tmpFile);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Ignore
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return succ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _tmpFile = string.Empty;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|