Skip to content

feat(version): add --raw to print the version alone - #1679

Open
Yi-111-a wants to merge 3 commits into
git-bug:trunkfrom
Yi-111-a:version-raw-flag
Open

Yi-111-a wants to merge 3 commits into
git-bug:trunkfrom
Yi-111-a:version-raw-flag

Conversation

@Yi-111-a

@Yi-111-a Yi-111-a commented Oct 10, 2026 •

Copy link
Copy Markdown

What

Add a --raw flag to git-bug version, which currently prints:

git-bug v1.2.3 8a3f1b2c9d0e go1.21.0 linux amd64

--raw prints just the version, on a line of its own:

v1.2.3

This is #1528, in the shape git-annex version --raw established: one bare version string that can be embedded in a statusline, a package script, or a version comparison without the caller having to strip a prefix and every metadata field.

Closes #1528.

Why this shape

The raw value is cut from the same string the default output prints (strings.Cut(full, " ")), rather than read from a second place. <version> is documented as the first space-separated field, so the two forms cannot drift apart, and there is no new code path deciding what the version "really" is.

--raw also emits a trailing newline, unlike the current output which ends without one. That is what makes $(git-bug version --raw) behave, and it is the only difference the flag introduces beyond the field itself.

The default output is byte-for-byte unchanged — TestVersionCommandDefaultUnchanged asserts that against the full documented string, so the flag cannot regress anything that parses the existing form.

Tests

commands/version_test.go, new:

  • TestRawVersion — table over the shapes getVersion() can produce: bare version, version + commit, commit/dirty, the undefined (no build info) fallback, the full documented shape, and the empty string. It pins the first-field rule rather than a single example.
  • TestVersionCommandRaw — runs the command and asserts the exact stdout, v1.2.3\n.
  • TestVersionCommandDefaultUnchanged — runs the command without the flag and asserts the pre-existing output.
$ go test ./commands/...      ok
$ go vet ./commands/          clean
$ gofmt -l commands/          clean

Built and run locally:

$ go run . version
git-bug undefined go1.26.0 linux amd64
$ go run . version --raw
undefined

Generated files

doc/md/git-bug_version.md and doc/man/git-bug-version.1 are regenerated with go generate, which the CI job Check generated files are up to date verifies. Shell completions are unchanged (cobra emits flag names dynamically).

I did not include the api/graphql/graph/repository.generated.go drift that go generate ./... also produced; it is unrelated to this change and is a separate question.

Notes

  • No behavior change without the flag; this is additive.
  • I left the /dirty and commit-hash discussion in feat: add --raw to version #1528 alone — those fields are already in the default output and --raw simply omits them, which is the point of the flag.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previous finding is fixed and no new actionable issues were found.

Summary

Adds --raw to git-bug version to print only the version string with a trailing newline.

  • git-bug version --raw prints the version alone on its own line.
  • The GitLab token prompt accepts both legacy and routable personal access tokens.

Reviews (2) · Last reviewed commit: "docs(version): avoid angle brackets in t..." · Reviewed by Greptile

GitLab issues routable tokens as
  <prefix><base64-payload>.<token-version>.<payload-length><crc32>
which is what both gitlab.com and self-managed instances hand out
today. The bridge only matched the legacy shape of an optional
"glpat-" prefix followed by exactly 20 base62 characters, so every
current token was rejected by the format check in promptToken.

Accept both shapes via a validTokenFormat helper, and cover them
with table driven tests. The API call in promptToken still decides
whether a token actually works, this only catches typos early.

Fixes git-bug#1587
'git-bug version' prints '<name> <version> [commit[/dirty]] <compiler>
<platform> <arch>', which is fine to read but not to embed: a statusline
or a version comparison has to strip the prefix and every metadata field
itself. git-bug#1528 asks for the git-annex style form, where 'version --raw'
prints just the number.

The raw value is cut from the same string the default output prints, so
the two forms cannot drift apart, and the default output is unchanged.

Closes git-bug#1528
Comment thread commands/version.go Outdated
Man-page generation strips <version>, which left "print  alone". Spell it
as "the version string" and regenerate the man/md mirrors.
@Yi-111-a

Copy link
Copy Markdown
Author

Addressed the greptile note: the --raw help sentence now says "the version string" instead of <version> (which the man generator was eating), and the man/md mirrors are updated.

This branch has not been deployed

No deployments
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.

feat: add --raw to version

3 participants