forked from xziino/ff14-mitigator
add commit and push commands from web
This commit is contained in:
parent
c2cf4db458
commit
e18252b491
35
admin.php
35
admin.php
@ -63,6 +63,11 @@ function branch_from_remote(string $remoteBranch): string {
|
|||||||
return $parts[1] ?? $remoteBranch;
|
return $parts[1] ?? $remoteBranch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function git_last_commit(): string {
|
||||||
|
$out = git_output(['log', '-1', '--oneline', '--decorate=short']);
|
||||||
|
return $out !== '' ? $out : '(unknown)';
|
||||||
|
}
|
||||||
|
|
||||||
$message = null;
|
$message = null;
|
||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
@ -78,6 +83,23 @@ if ($allowed && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
} elseif ($action === 'pull') {
|
} elseif ($action === 'pull') {
|
||||||
$result = git_run(['pull', '--ff-only']);
|
$result = git_run(['pull', '--ff-only']);
|
||||||
$message = 'git pull --ff-only';
|
$message = 'git pull --ff-only';
|
||||||
|
} elseif ($action === 'push') {
|
||||||
|
$result = git_run(['push']);
|
||||||
|
$message = 'git push';
|
||||||
|
} elseif ($action === 'commit') {
|
||||||
|
$commitMessage = trim((string)($_POST['message'] ?? ''));
|
||||||
|
if ($commitMessage === '') {
|
||||||
|
$result = ['code' => 1, 'output' => 'Commit message is required.'];
|
||||||
|
} else {
|
||||||
|
$add = git_run(['add', '-A']);
|
||||||
|
if ($add['code'] !== 0) {
|
||||||
|
$result = $add;
|
||||||
|
$message = 'git add -A';
|
||||||
|
} else {
|
||||||
|
$result = git_run(['commit', '-m', $commitMessage]);
|
||||||
|
$message = 'git commit';
|
||||||
|
}
|
||||||
|
}
|
||||||
} elseif ($action === 'switch') {
|
} elseif ($action === 'switch') {
|
||||||
$ref = trim((string)($_POST['branch'] ?? ''));
|
$ref = trim((string)($_POST['branch'] ?? ''));
|
||||||
$localBranches = git_local_branches();
|
$localBranches = git_local_branches();
|
||||||
@ -121,7 +143,7 @@ if ($allowed) {
|
|||||||
$status = git_output(['status', '-sb']);
|
$status = git_output(['status', '-sb']);
|
||||||
$branches = git_local_branches();
|
$branches = git_local_branches();
|
||||||
$remoteBranches = git_remote_branches();
|
$remoteBranches = git_remote_branches();
|
||||||
$lastCommit = git_output(['log', '-1', '--pretty=%h %s (%cr)']);
|
$lastCommit = git_last_commit();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@ -199,6 +221,7 @@ if ($allowed) {
|
|||||||
<input type="hidden" name="csrf" value="<?= admin_h($csrf) ?>">
|
<input type="hidden" name="csrf" value="<?= admin_h($csrf) ?>">
|
||||||
<button class="btn" name="action" value="fetch" type="submit">Fetch</button>
|
<button class="btn" name="action" value="fetch" type="submit">Fetch</button>
|
||||||
<button class="btn btn-gold" name="action" value="pull" type="submit">Pull</button>
|
<button class="btn btn-gold" name="action" value="pull" type="submit">Pull</button>
|
||||||
|
<button class="btn" name="action" value="push" type="submit">Push</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form method="post" class="admin-actions section-gap">
|
<form method="post" class="admin-actions section-gap">
|
||||||
@ -225,6 +248,16 @@ if ($allowed) {
|
|||||||
</div>
|
</div>
|
||||||
<button class="btn" type="submit">Switch</button>
|
<button class="btn" type="submit">Switch</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form method="post" class="section-gap">
|
||||||
|
<input type="hidden" name="csrf" value="<?= admin_h($csrf) ?>">
|
||||||
|
<input type="hidden" name="action" value="commit">
|
||||||
|
<div class="fg">
|
||||||
|
<label for="commit-message">Commit message</label>
|
||||||
|
<input id="commit-message" name="message" type="text" placeholder="Describe the change…" required>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-gold section-gap" type="submit">Commit all changes</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user