Skip to content

feat: Add git branch to version information on settings screen#1225

Merged
daveallie merged 2 commits intocrosspoint-reader:masterfrom
jpirnay:feat-gitinfo
Mar 1, 2026
Merged

feat: Add git branch to version information on settings screen#1225
daveallie merged 2 commits intocrosspoint-reader:masterfrom
jpirnay:feat-gitinfo

Conversation

@jpirnay
Copy link
Contributor

@jpirnay jpirnay commented Feb 28, 2026

Summary

  • What is the goal of this PR? During my development I am frequently jumping from branch to branch flashing test versions on my device. It becomes sometimes quite difficult to figure out which version of the software I am currently looking at.

  • What changes are included?

    • Dev builds now display the current git branch in the version string shown on the Settings screen (e.g. 1.1.0-dev+feat-my-feature), making it easier to identify which firmware is running on the device when switching between branches frequently.
    • Release, RC, and slim builds are unaffected — they continue to set their version string statically in platformio.ini.
after

Additional Context

A new PlatformIO pre-build script (scripts/git_branch.py) runs automatically before every dev build. It reads the base version from the [crosspoint] section of platformio.ini, queries git rev-parse --abbrev-ref HEAD for the current branch, and injects the combined string as the CROSSPOINT_VERSION preprocessor define. In a detached HEAD state it falls back to the short commit SHA. If git is unavailable it warns and falls back to unknown.

The script can also be run directly with python scripts/git_branch.py for validation without triggering a full build.


AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? < YES | PARTIALLY | NO >

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

📝 Walkthrough

Walkthrough

Adds a PlatformIO pre-build script that reads base version from config, obtains the current git branch (or short SHA), composes a "-dev+" version string, and injects it into the default environment build as the CROSSPOINT_VERSION CPP define.

Changes

Cohort / File(s) Summary
Configuration
platformio.ini
Bumped crosspoint.version to 1.1.1, added scripts/git_branch.py to extra_scripts, and removed the explicit -DCROSSPOINT_VERSION define in the [env:default] section (comment indicates script injects it).
Build Script
scripts/git_branch.py
New pre-build script. Reads base version from [crosspoint] in platformio.ini, obtains/sanitizes git branch or short SHA, constructs <base_version>-dev+<branch>, and appends CPPDEFINES with CROSSPOINT_VERSION (escaped string) for default env only. Includes warnings and fallbacks for missing git/INI and a runnable main for local testing.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer/CI
    participant PIO as PlatformIO (pre-build)
    participant Script as scripts/git_branch.py
    participant INI as platformio.ini
    participant Git as Git repo
    participant Env as Build Environment

    Dev->>PIO: start build for PIOENV=default
    PIO->>Script: run inject_version(env)
    Script->>INI: read [crosspoint] version
    Script->>Git: get current branch or short SHA
    Git-->>Script: branch/sha (or error)
    INI-->>Script: base version (or default)
    Script->>Script: sanitize & construct "<base>-dev+<branch>"
    Script->>Env: append CPPDEFINES CROSSPOINT_VERSION="..."
    Env-->>PIO: updated build defines
    PIO->>Dev: continue build with injected CROSSPOINT_VERSION
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding git branch information to the version display on the settings screen for dev builds.
Description check ✅ Passed The PR description clearly explains the goal of adding git branch information to dev build version strings and describes the implementation details with the new PlatformIO script.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@znelson znelson changed the title fea: Add git branch to version information on settings screen feat: Add git branch to version information on settings screen Feb 28, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
scripts/git_branch.py (1)

39-41: Consider narrowing the exception type.

The generic Exception catch is a defensive fallback, but it may mask unexpected issues. Since FileNotFoundError and CalledProcessError cover the expected git failures, consider replacing with OSError to catch remaining I/O-related errors while letting truly unexpected exceptions propagate.

♻️ Optional: Narrow exception scope
-    except Exception as e:
-        warn(f'Unexpected error reading git branch: {e}; branch suffix will be "unknown"')
-        return 'unknown'
+    except OSError as e:
+        warn(f'OS error reading git branch: {e}; branch suffix will be "unknown"')
+        return 'unknown'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/git_branch.py` around lines 39 - 41, Replace the broad "except
Exception as e" handler that logs via warn(...) and returns 'unknown' with a
narrower "except OSError as e" so only I/O-related errors (e.g., missing git or
filesystem issues) are caught while letting other unexpected exceptions
propagate; keep the existing warn(...) message and the return 'unknown' behavior
but change the exception type to OSError to narrow the scope.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@scripts/git_branch.py`:
- Around line 39-41: Replace the broad "except Exception as e" handler that logs
via warn(...) and returns 'unknown' with a narrower "except OSError as e" so
only I/O-related errors (e.g., missing git or filesystem issues) are caught
while letting other unexpected exceptions propagate; keep the existing warn(...)
message and the return 'unknown' behavior but change the exception type to
OSError to narrow the scope.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e168aa and 48c4f1b.

📒 Files selected for processing (2)
  • platformio.ini
  • scripts/git_branch.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cppcheck
  • GitHub Check: build
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-02-23T19:55:14.329Z
Learnt from: martinbrook
Repo: crosspoint-reader/crosspoint-reader PR: 1136
File: scripts/patch_jpegdec.py:20-23
Timestamp: 2026-02-23T19:55:14.329Z
Learning: PlatformIO pre-build scripts in the crosspoint-reader project use the standard SCons pattern `Import("env")` and callback signature `def patch_jpegdec(source, target, env):` without noqa comments or underscore-prefixing unused parameters, following the convention used in other scripts in the project.

Applied to files:

  • scripts/git_branch.py
  • platformio.ini
📚 Learning: 2026-02-23T19:55:03.054Z
Learnt from: martinbrook
Repo: crosspoint-reader/crosspoint-reader PR: 1136
File: scripts/patch_jpegdec.py:20-23
Timestamp: 2026-02-23T19:55:03.054Z
Learning: In the crosspoint-reader project, enable Python linters (e.g., Ruff or Flake8) in CI for all Python scripts. Run linting as part of the CI workflow and fix reported issues to maintain code quality. Do not skip linting for any Python files.

Applied to files:

  • scripts/git_branch.py
🪛 Ruff (0.15.2)
scripts/git_branch.py

[error] 22-22: Starting a process with a partial executable path

(S607)


[error] 28-28: Starting a process with a partial executable path

(S607)


[warning] 39-39: Do not catch blind exception: Exception

(BLE001)

🔇 Additional comments (6)
platformio.ini (1)

49-49: LGTM!

The pre-build script integration is clean. Adding it to [base] ensures it runs for all environments, while the script's internal check for PIOENV == 'default' correctly limits version injection to dev builds. Release environments retain their explicit CROSSPOINT_VERSION definitions in build_flags.

Also applies to: 66-66

scripts/git_branch.py (5)

1-12: LGTM!

Clear docstring with example output format, and minimal standard-library-only dependencies.


15-16: LGTM!

Simple and appropriate warning function for build script output.


44-54: LGTM!

Robust version reading with appropriate fallbacks and warnings. The path handling is platform-independent.


57-69: LGTM!

Clean environment check, well-formatted version string following semver conventions (-dev prerelease + +branch metadata), and correct SCons CPPDEFINES escaping.


72-83: LGTM!

The dual-mode entry point is well-designed. The Import('env') pattern is standard SCons, and the noqa comments are appropriate since Import is a runtime-injected builtin. The _Env mock enables standalone validation without requiring a full PlatformIO build.

Copy link
Contributor

@znelson znelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This sounds useful because I find myself in the same situation, questioning which version I most recently flashed. What would you think about adding the short commit SHA, too, like "30d8a8d"?

@daveallie daveallie merged commit 3da2cd3 into crosspoint-reader:master Mar 1, 2026
7 checks passed
@jpirnay jpirnay deleted the feat-gitinfo branch March 1, 2026 09:08
laird pushed a commit to laird/crosspoint-claw that referenced this pull request Mar 1, 2026
…point-reader#1225)

* **What is the goal of this PR?** During my development I am frequently
jumping from branch to branch flashing test versions on my device. It
becomes sometimes quite difficult to figure out which version of the
software I am currently looking at.

* **What changes are included?**
- Dev builds now display the current git branch in the version string
shown on the Settings screen (e.g. 1.1.0-dev+feat-my-feature), making it
easier to identify which firmware is running on the device when
switching between branches frequently.
- Release, RC, and slim builds are unaffected — they continue to set
their version string statically in platformio.ini.
<img width="480" height="800" alt="after"
src="https://github.com/user-attachments/assets/d2ab3d69-ab6b-47a1-8eb7-1b40b1d3b106"
/>

A new PlatformIO pre-build script (scripts/git_branch.py) runs
automatically before every dev build. It reads the base version from the
[crosspoint] section of platformio.ini, queries git rev-parse
--abbrev-ref HEAD for the current branch, and injects the combined
string as the CROSSPOINT_VERSION preprocessor define. In a detached HEAD
state it falls back to the short commit SHA. If git is unavailable it
warns and falls back to unknown.

The script can also be run directly with python scripts/git_branch.py
for validation without triggering a full build.

---

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< YES | PARTIALLY | NO
>**_
laird added a commit to laird/crosspoint-claw that referenced this pull request Mar 1, 2026
Cherry-picked upstream fixes and features applied via rescue-1.0.0 worktree:
- fix: properly implement requestUpdateAndWait() (crosspoint-reader#1218)
- fix: Hide unusable button hints in empty directory (crosspoint-reader#1253)
- fix: add missing keyboard metrics to Lyra3CoversTheme (crosspoint-reader#1101)
- fix: remove bookProgressBarHeight from Lyra3CoversTheme
- feat: replace picojpeg with JPEGDEC for JPEG decoding (crosspoint-reader#1136)
- feat: WIFI pill, feed log fix, JPEGDEC version string
- feat: Add git branch to version string (crosspoint-reader#1225)
- fix: navigate directly to QR code after DZ auto-connect
- perf: Removed unused ConfirmationActivity member (crosspoint-reader#1234)
- refactor: Simplify new setting introduction (crosspoint-reader#1086)
- fix: UI fonts, settings stack overflow, PULSR theme name
- fix: convert SettingsList to push_back (prevent stack overflow)

All commits built and verified on device (confirmed 1.1.0-dev+d1e786a).
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.

4 participants