Small SBT AutoPlugin for Git-backed project versions and a few everyday Git commands inside the SBT shell.
The plugin has two jobs:
- derive
versionfrom the current Git repository - expose a
gitinput task for common repository operations
Add the plugin to project/plugins.sbt:
addSbtPlugin("io.github.zero-deps" % "sbt-git" % "<version>")Then use it from build.sbt:
version := zero.git.version()The plugin is an AutoPlugin with allRequirements, so it is enabled
automatically after it is added to the build.
zero.git.version() calls JGit describe for the repository rooted at the
current directory. By default it:
- uses annotated tags, not lightweight tags
- strips a leading
vfrom the described tag - converts Git describe separators from
-to. - pads the version to at least three dot-separated parts
- appends
-dirtywhen the working tree has uncommitted changes
Example outputs:
1.2.3
1.2.3.4.gabcdef0
gabcdef0.0.0
1.2.3-dirty
The helper can be configured when a build needs different formatting:
version := zero.git.version(
dir = ".",
tags = false,
stripPrefix = "v",
dotted = true,
parts = Some(3)
)Parameters:
dir: repository directory to opentags: passtrueto include lightweight tags in describe resultsstripPrefix: prefix removed from the described tag before formattingdotted: passfalseto keep Git describe-separatorsparts: minimum number of dot-separated parts, orNoneto avoid padding
If no tag can describe HEAD, the version falls back to the abbreviated commit
hash.
After the plugin is loaded, run git commands from the SBT shell:
sbt> git status
sbt> git s
sbt> git add <pathspec>...
sbt> git commit -m <message>
sbt> git diff [--staged|--cached] [<pathspec>...]
sbt> git log [-n <count>]
sbt> git log --max-count <count>
sbt> git branch
sbt> git fetch
sbt> git pull
sbt> git push
sbt> git tag
sbt> git help
Notes:
git sis a shortcut forgit status.git addstages new, modified, and removed files for the given pathspecs.git commitcurrently supports-mmessages.git diff --stagedandgit diff --cachedboth show staged changes.git logdefaults to 10 commits.
The command surface is intentionally small. For advanced Git operations, use the normal Git CLI.
Compile the plugin:
sbt compileRun tests:
sbt testPublish to the local Ivy/Maven cache for testing in another build:
sbt publishLocalThe project uses Scala compiler warnings for features, deprecations, and unused imports. Keep new code warning-free.
Release publishing uses SBT's Central Portal support plus PGP signing. Keep Central Portal credentials and local key material outside the repository.
Stage and upload signed artifacts:
sbt> publishSigned
sbt> sonaUpload
Upload and release in one step:
sbt> sonaRelease
Published under the MIT license.