autocommit: pull-rebase before push to avoid races with other vault writers
This commit is contained in:
parent
6bb9a127a0
commit
716cf74864
1 changed files with 17 additions and 6 deletions
|
|
@ -440,14 +440,25 @@ async fn spawn_git_autocommit(source_slug: &str, para_id: &str) {
|
|||
let slug = source_slug.to_string();
|
||||
let pid = para_id.to_string();
|
||||
tokio::spawn(async move {
|
||||
let _ = tokio::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"cd {dir} && git add -A && git commit -m 'note: {slug} {pid}' && git push 2>&1",
|
||||
// Pull-rebase before push to avoid racing with other writers
|
||||
// (e.g. Mac's vault-push timer). Rebase auto-stashes local
|
||||
// changes so our pending commit survives. If rebase conflicts
|
||||
// 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),
|
||||
slug = shell_escape(&slug),
|
||||
pid = shell_escape(&pid),
|
||||
))
|
||||
);
|
||||
let _ = tokio::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(&script)
|
||||
.output()
|
||||
.await;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue