{"id":23059168,"url":"https://github.com/slimhazard/gogitversion","last_synced_at":"2025-07-16T22:39:16.422Z","repository":{"id":57513099,"uuid":"145622408","full_name":"slimhazard/gogitversion","owner":"slimhazard","description":"gogitversion generates a Go source file that declares a const for a version string, whose contents are the output of 'git describe'.","archived":false,"fork":false,"pushed_at":"2023-11-30T09:31:17.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T20:16:35.047Z","etag":null,"topics":["git-describe","go","go-generate","golang","version"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slimhazard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-21T21:40:08.000Z","updated_at":"2023-11-30T09:31:21.000Z","dependencies_parsed_at":"2024-06-20T18:54:50.782Z","dependency_job_id":null,"html_url":"https://github.com/slimhazard/gogitversion","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimhazard%2Fgogitversion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimhazard%2Fgogitversion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimhazard%2Fgogitversion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slimhazard%2Fgogitversion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slimhazard","download_url":"https://codeload.github.com/slimhazard/gogitversion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246945082,"owners_count":20858878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git-describe","go","go-generate","golang","version"],"created_at":"2024-12-16T02:20:27.454Z","updated_at":"2025-04-03T06:22:08.572Z","avatar_url":"https://github.com/slimhazard.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"gogitversion generates a Go source file that declares a const for a version string, whose contents are the output of 'git describe'. It is intended to be useful for 'go generate'.\n\nTo use it with go generate, include a directive like this in one of your source files:\n\n    //go:generate gogitversion\n\nThere must be no space between \"//\" and \"go\". Then issue the 'go generate' command before 'go build'.\n\nBy default, gogitversion takes the base name of the current working directory as the package for which it generates code. If the package name is \"foo\", then by default a file named \"foo\\_version.go\" is generated with content like this:\n\n    package foo\n\n    const version = \"v1.0.4-14-g2414721\"\n\n... where \"v1.0.4-14-g2414721\" is the output from 'git describe'. The version const can now be used in package foo.\n\nSee git-describe(1) for details about the git command.\n\n### Options\n\nThe code generation can be configured with command-line flags:\n\n    -p pkg\n\nUse 'pkg' as the package name. This name also appears in the name of the generated file. The default package name is the base name of the current working directory. For example, use '-p main' to declare the const in package main.\n\n    -c name\n\nUse 'name' as the generated const name. For example, use '-c Version' to create the const Version (which is then exported). The default const name is 'version' (and hence is not exported).\n\n    -s suffix\n\nUse 'suffix' as the part of the file name that follows the package name and precedes \".go\". For example, if you use '-p foo' and '-s Version', then the generated file is named 'fooVersion.go'. Use -s ” (the empty string) to leave out the suffix. The default suffix is '\\_version' (to create file names like 'foo\\_version.go').\n\n    -u fallback\n\nUse \"fallback\" as the version string if the 'git describe' invocation fails. The default fallback string is \"unknown\".\n\n    -d dir\n\nCreate the generated Go source in directory 'dir'. By default, it is created in the current working directory.\n\n    --opts opt1,opt2,opt3=val\n\nUse '--opt1', '--opt2' and '--opt3=val' as command line options in the 'git describe' invocation. The contents of --opts are comma-separated, and should not have '--' (otherwise they may be interpreted as options for gogitversion, probably leading to failure). Options that have an argument (such as --abbrev and --match) should include the equals sign followed by the argument.\n\nFor example, '-opts all,abbrev=8,match=prod' will cause 'git describe' to be called with '--all --abbrev=8 --match=prod'.\n\nThe default value of 'opts' is 'always' (so that 'git describe' will always return a value, even if you have never created a tag). If you use -opts to add other options and want to retain '--always', remember to include 'always' in the list. Use -opts ” (the empty string) to call 'git describe' without any options.\n\n    --args arg1,arg2,arg3\n\nUse 'arg1', 'arg2' and 'arg3' as arguments in the 'git describe' invocation, following the options. The contents of -args are comma-separated. By default, 'git describe' is called with no arguments (only the '--always' option).\n\n    --path /opt/bin\n\nUse '/opt/bin' as the path for 'git' (in other words, call '/opt/bin/git'). By default, 'git' is invoked without a path, so the binary is found via the $PATH variable.\n\nThe --version option causes gogitversion to print its version and exit (this tool eats its own dog food).\n\n### Examples\n\nGenerate the file \"main\\_version.go\" in which the const 'version' containing the output of 'git describe --always' is declared in package main:\n\n    gogitversion -p main\n\nGenerate the file \"/tmp/fooversion.go\" in which the exported const 'Version' containing the output of 'git describe --always' is declared in package foo:\n\n    gogitversion -p foo -s version -v Version -d /tmp\n\nWith the base name of the current working directory as the package name, generate a version const using options and an argument for 'git describe':\n\n    gogitversion --opts all,abbrev=4 --args HEAD^\n\nThe version string contains the output of:\n\n    git describe --all --abbrev=4 HEAD^\n\n### Building gogitversion\n\nBootstrapping is a bit tricky here, because the tool uses itself to generate its version string. For best results, use the accompanying Makefile (default target or 'all'), which takes care of things if you have never built or installed gogitversion.\n\nYou must call 'go generate' before 'go build' (the Makefile does this for you).\n\nIf you have been testing gogitversion and have been generating Go sources in your working directory, make sure to delete them before building gogitversion again (with make or 'go build'). Otherwise, 'go build' will attempt to compile them as sources for gogitversion, likely leading to errors. Using the -d option helps to avoid this problem.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimhazard%2Fgogitversion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslimhazard%2Fgogitversion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslimhazard%2Fgogitversion/lists"}