Skip to content

Fix stat mtime detection on Linux (sync-age display broken)#49

Merged
ykdojo merged 1 commit into
ykdojo:mainfrom
thomasthinks:fix/stat-mtime-linux-portability
Jul 23, 2026
Merged

Fix stat mtime detection on Linux (sync-age display broken)#49
ykdojo merged 1 commit into
ykdojo:mainfrom
thomasthinks:fix/stat-mtime-linux-portability

Conversation

@thomasthinks

Copy link
Copy Markdown
Contributor

On GNU/Linux, stat -f is a valid flag (it prints filesystem status), so it succeeds instead of erroring — the || stat -c %Y fallback never fires. $fetch_time then captures multi-line filesystem output, $((now - fetch_time)) throws syntax error in expression, and the git sync-age (synced Nm ago) never renders.

Fix: try the GNU form (-c %Y) first, fall back to BSD/macOS (-f %m):

-fetch_time=$(stat -f %m "$fetch_head" 2>/dev/null || stat -c %Y "$fetch_head" 2>/dev/null)
+fetch_time=$(stat -c %Y "$fetch_head" 2>/dev/null || stat -f %m "$fetch_head" 2>/dev/null)

Correct on both platforms: Linux hits -c first; macOS errors on -c (BSD stat has no -c) and falls through to -f %m. One-line change, no behavior change on macOS.

On GNU/Linux, `stat -f` is a valid flag (filesystem status) that
succeeds rather than erroring, so the `|| stat -c %Y` fallback never
fired and $fetch_time captured multi-line filesystem output. That broke
the $((now - fetch_time)) arithmetic and the sync-age display.

Try the GNU form (`-c %Y`) first, fall back to the BSD/macOS form
(`-f %m`). Correct on both platforms: Linux hits -c first; macOS errors
on -c and falls through to -f.
@ykdojo
ykdojo merged commit 3df8f17 into ykdojo:main Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants