-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathPull.cs
More file actions
58 lines (54 loc) · 1.98 KB
/
Pull.cs
File metadata and controls
58 lines (54 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Text;
using RT.Servers;
using RT.Util;
namespace KtaneWeb
{
public sealed partial class KtanePropellerModule
{
private bool _pullActive = false;
private HttpResponse pull(HttpRequest req)
{
if (_pullActive)
return HttpResponse.PlainText("A pull is already currently active.");
try
{
_pullActive = true;
var output = new StringBuilder();
var runGitPull = req.Url["dont"] != "1";
if (runGitPull)
{
output.Append("git fetch origin\n==============================\n");
var cmd = new CommandRunner
{
Command = "git fetch origin",
WorkingDirectory = _config.BaseDir
};
cmd.StdoutText += str => output.Append(str);
cmd.StderrText += str => output.Append(str);
cmd.StartAndWait();
output.Append("\n\ngit reset --hard origin/master\n==============================\n");
cmd = new CommandRunner
{
Command = "git reset --hard origin/master",
WorkingDirectory = _config.BaseDir
};
cmd.StdoutText += str => output.Append(str);
cmd.StderrText += str => output.Append(str);
cmd.StartAndWait();
}
generateTranslationCache();
generateModuleInfoCache();
return HttpResponse.PlainText(runGitPull ? output.ToString() : "Module info refreshed.");
}
catch (Exception e)
{
return HttpResponse.PlainText($"{e.Message}\n\n{e.GetType().FullName}");
}
finally
{
_pullActive = false;
}
}
}
}