autocommit: pull-rebase before push to avoid races with other vault writers

This commit is contained in:
Alexey 2026-04-23 23:41:03 +05:00
parent 6bb9a127a0
commit 716cf74864

View file

@ -440,14 +440,25 @@ async fn spawn_git_autocommit(source_slug: &str, para_id: &str) {
let slug = source_slug.to_string(); let slug = source_slug.to_string();
let pid = para_id.to_string(); let pid = para_id.to_string();
tokio::spawn(async move { tokio::spawn(async move {
let _ = tokio::process::Command::new("sh") // Pull-rebase before push to avoid racing with other writers
.arg("-c") // (e.g. Mac's vault-push timer). Rebase auto-stashes local
.arg(format!( // changes so our pending commit survives. If rebase conflicts
"cd {dir} && git add -A && git commit -m 'note: {slug} {pid}' && git push 2>&1", // somehow (shouldn't for append-only files), the push will
// simply fail and we'll catch it on the next save.
let script = format!(
"set -e; cd {dir}; \
git add -A; \
git diff --cached --quiet && exit 0; \
git commit -m 'note: {slug} {pid}'; \
git pull --rebase --autostash origin main 2>&1 || true; \
git push origin main 2>&1",
dir = shell_escape(&dir), dir = shell_escape(&dir),
slug = shell_escape(&slug), slug = shell_escape(&slug),
pid = shell_escape(&pid), pid = shell_escape(&pid),
)) );
let _ = tokio::process::Command::new("sh")
.arg("-c")
.arg(&script)
.output() .output()
.await; .await;
}); });