自动提交

This commit is contained in:
2025-11-15 18:26:42 +08:00
parent 23d6d8b4df
commit 34a3001d11
3 changed files with 138 additions and 0 deletions

44
test_git_add_commit.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
// 测试Git添加和提交操作
$apiUrl = 'http://localhost:8080/index.php';
// 测试Git添加
echo "测试Git添加操作\n";
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(['action' => 'git_operation', 'operation' => 'add']),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded']
]);
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$result = json_decode($response, true);
echo "Git添加结果\n";
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
}
// 测试Git提交
echo "测试Git提交操作\n";
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query([
'action' => 'git_operation',
'operation' => 'commit',
'message' => '测试提交修复Git仓库路径问题'
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded']
]);
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$result = json_decode($response, true);
echo "Git提交结果\n";
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
}
echo "Git操作测试完成\n";
?>

57
test_git_operations.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
// 测试Git操作功能
$apiUrl = 'http://localhost:8080/index.php';
// 测试1: 获取文件列表
echo "测试1: 获取文件列表\n";
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(['action' => 'get_files']),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded']
]);
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$result = json_decode($response, true);
echo "文件列表结果:\n";
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
}
// 测试2: 获取分支列表
echo "测试2: 获取分支列表\n";
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(['action' => 'get_branches']),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded']
]);
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$result = json_decode($response, true);
echo "分支列表结果:\n";
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
}
// 测试3: Git状态
echo "测试3: Git状态\n";
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(['action' => 'git_operation', 'operation' => 'status']),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded']
]);
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$result = json_decode($response, true);
echo "Git状态结果\n";
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
}
echo "测试完成!\n";
?>

37
test_upload.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
// 测试文件上传功能
$uploadUrl = 'http://localhost:8080/index.php';
// 准备测试文件
$testContent = "这是测试文件内容\n用于验证Git上传功能\n时间:" . date('Y-m-d H:i:s');
file_put_contents('test_upload.txt', $testContent);
// 创建cURL请求
curl_setopt_array($ch = curl_init(), [
CURLOPT_URL => $uploadUrl,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'action' => 'upload',
'files' => new CURLFile('test_upload.txt')
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: multipart/form-data'
]
]);
echo "正在测试文件上传功能...\n";
$response = curl_exec($ch);
curl_close($ch);
if ($response) {
$result = json_decode($response, true);
echo "上传结果:\n";
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
} else {
echo "上传失败:无法连接到服务器\n";
}
// 清理测试文件
@unlink('test_upload.txt');
?>