fix(update): clear a stale .git/index.lock before Update Code (#801)

* fix(update): clear a stale .git/index.lock before Update Code

A git that subprocess.run's timeout kills (SIGKILL) cannot remove
.git/index.lock, so every later update failed with "Unable to create
.../.git/index.lock: File exists" until the file was removed by hand.

Update Code and the automatic update's rollback now remove the lock when
no git process is running in the checkout and the file is more than a
few seconds old. While another git is running, Update Code says so
instead of failing; when the lock could not be checked, the error names
the rm command that fixes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvFtgthKUNEPhJu6RuX9Sk

* fix(update): count a git that names the checkout in its arguments as running

git --git-dir/--work-tree can work on the checkout from any working
directory, so the cwd check alone could take such a git's live lock for
a stale one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvFtgthKUNEPhJu6RuX9Sk

* fix(update): resolve a git's relative path arguments against its cwd

`git -C LEDMatrix ...` or a relative --git-dir started outside the
checkout works on it too; resolve each argument against the process's
working directory before deciding a lock is stale, and count unreadable
arguments as naming the checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SvFtgthKUNEPhJu6RuX9Sk

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-10-26 20:13:40 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 4c883ec2c2
commit fa51ebab5f
6 changed files with 389 additions and 2 deletions
+4 -1
View File
@@ -42,7 +42,7 @@ import time
from datetime import datetime
from pathlib import Path
from web_interface import update_channel
from web_interface import git_index_lock, update_channel
logger = logging.getLogger(__name__)
@@ -615,6 +615,9 @@ class AutoUpdater:
if core.get('status') != 'success':
message = core.get('message') or 'The LEDMatrix update failed.'
if new_head and new_head != old_head:
# A pull killed by its timeout leaves .git/index.lock behind,
# and the rollback's reset would fail on it.
git_index_lock.clear_stale_index_lock(self.project_root)
ok, detail = rollback()
message += (' The partial update was rolled back.' if ok
else f' Rolling back the partial update also failed: {detail}.')