git-sync-web 自动提交 2026-09-09 20:14:20
This commit is contained in:
+23
-7
@@ -871,6 +871,17 @@ async function loadFile(name, path) {
|
||||
}
|
||||
}
|
||||
|
||||
async function commitCurrentFile() {
|
||||
const name = current;
|
||||
const path = fileCurrent;
|
||||
if (!name || !path) throw new Error('请先在左侧选择一个文件');
|
||||
await api(`/api/repos/${name}/commit`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ path, message: $('#file-msg').value })
|
||||
});
|
||||
}
|
||||
|
||||
async function saveFile(commit) {
|
||||
const name = current;
|
||||
const path = fileCurrent;
|
||||
@@ -887,16 +898,12 @@ async function saveFile(commit) {
|
||||
showDraftNote(false);
|
||||
draftServer = content;
|
||||
if (commit) {
|
||||
await api(`/api/repos/${name}/commit`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ path, message: $('#file-msg').value })
|
||||
});
|
||||
toast('已保存并提交');
|
||||
await commitCurrentFile();
|
||||
toast('已保存并提交:' + path);
|
||||
} else {
|
||||
$('#f-diff-scope').value = 'working';
|
||||
showTab('diff');
|
||||
toast('已保存到磁盘(未提交)。可在「差异」tab 查看改动,或稍后由自动同步提交。');
|
||||
toast('已保存到磁盘(未提交)。可在「差异」tab 查看改动;提交请用「提交」或「保存并提交」。');
|
||||
}
|
||||
} catch (err) { toast('保存失败:' + err.message); }
|
||||
}
|
||||
@@ -944,6 +951,15 @@ $('#file-list').addEventListener('click', (e) => {
|
||||
});
|
||||
$('#btn-file-save').addEventListener('click', () => saveFile(false));
|
||||
$('#btn-file-commit').addEventListener('click', () => saveFile(true));
|
||||
$('#btn-file-commit-only').addEventListener('click', async () => {
|
||||
if (!current || !fileCurrent) { toast('请先在左侧选择一个文件'); return; }
|
||||
try {
|
||||
await commitCurrentFile();
|
||||
toast('已提交:' + fileCurrent);
|
||||
if (Editor.value === draftServer) await loadFile(current, fileCurrent);
|
||||
refresh();
|
||||
} catch (err) { toast('提交失败:' + err.message, 'error'); }
|
||||
});
|
||||
|
||||
$('#file-editor').addEventListener('input', scheduleDraft);
|
||||
$('#file-editor').addEventListener('keydown', (e) => {
|
||||
|
||||
Reference in New Issue
Block a user