-
Notifications
You must be signed in to change notification settings - Fork 540
git describe #816
base: master
Are you sure you want to change the base?
git describe #816
Conversation
RFC.
I'll squash at the end. Nothing fancy yet xD |
030324a
to
0b1ee9f
Compare
repository.go
Outdated
} | ||
|
||
// Tag map for rapid (?) query | ||
tagIterator, err := r.Tags() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can be implemented at Repository
with a function Tag(referenceName)
, or a helper function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like TagObject but for lightweight tags will be ideal.
Then we just need to walk down the log checking for annotated tags or lw-tags deppending on the --tag
option always preferring annotated ones as described in the git documentation. This search algorithm is nicely described doing a git describe --tags --debug
:
$ git describe --tags --debug
searching to describe HEAD
lightweight 2 v4.3.1
lightweight 12 v4.3.0
lightweight 18 v4.2.1
lightweight 35 v4.2.0
lightweight 56 v4.1.1
lightweight 77 v4.1.0
lightweight 90 v4.0.0
lightweight 271 v4.0.0-rc15
lightweight 282 v4.0.0-rc14
lightweight 330 v4.0.0-rc13
traversed 393 commits
more than 10 tags found; listed 10 most recent
gave up search at d3c7400c39f86a4c59340c7a9cda8497186e00fc
v4.3.1-2-g87cc819
I did not dig into the details of TagObject
. I'll check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks ok but requires a lot of more work, git describe
is a complex command.
Thanks for contributing.
Indeed! Is more RFC on the feature branch than a production-ready PR. Comments and PRs to the branch are also welcome. :) |
bcbda0d
to
6104842
Compare
Still some improvements to do and some more options to enable like |
9425c85
to
8e14928
Compare
- `Describe` method under repository allows to describe references based on tags. - Options ported from `git describe` as close as possible. - Basic test for `Describe` Signed-off-by: Eduardo Lezcano <[email protected]>
Very cool @edupo keep the good work. |
I was looking at using go-git to fetch tag information using (I will just use bash or ldflags to solve my problem for now). |
Have there been any updates for this feature? We'd love to use inbuilt library functions; we were thinking about using this workaround. |
Previously the version of the application was determined by calling `git` commands in a new shell process. This works in most cases, but might fail if Git is not installed on the running system. To prevent further enlargement of the required development environment setup dependencies by adding more checks for external dependencies, the `go-git` library v4 [1] (`github.com/src-d/go-git/v4`) has been added: "A highly extensible Git implementation in pure Go" It allows to interact with the project repository and extrac required information like the latest tag and commit of the current branch to assemble the application version. To simplify the processing and parsing of the version, the `semver` library v3 [2] (`github.com/Masterminds/semver/v3`) has also been added. The new `getAppVersionFromGit()` function assembles the version of the application from the metadata of the Git repository. It searches for the latest "SemVer" [3] compatible version tag in the current branch and falls back to the default version from the application configuration if none is found. If at least one tag is found but it is not the latest commit of the current branch, the build metadata will be appended, consisting of the amount of commits ahead and the shortened reference hash (8 digits) of the latest commit from the current branch. The function is a early implementation of the Git `describe` command because support in `go-git` [1] has not been implemented yet. See the full compatibility comparison documentation with Git [4] as well as the proposed Git `describe` command implementation [5] for more details. [1]: https://github.com/src-d/go-git/v4 [2]: https://github.com/Masterminds/semver/v3 [3]: https://semver.org [4]: https://github.com/src-d/go-git/blob/master/COMPATIBILITY.md [5]: src-d/go-git#816 Epic GH-33 GH-92
App version with pure Go Git and SemVer libraries Previously the version of the application was determined by calling `git` commands in a new shell process. This works in most cases, but might fail if Git is not installed on the running system. To prevent further enlargement of the required development environment setup dependencies by adding more checks for external dependencies, the `go-git` library v4 [1] (`github.com/src-d/go-git/v4`) has been added: "A highly extensible Git implementation in pure Go" It allows to interact with the project repository and extrac required information like the latest tag and commit of the current branch to assemble the application version. To simplify the processing and parsing of the version, the `semver` library v3 [2] (`github.com/Masterminds/semver/v3`) has also been added. The new `getAppVersionFromGit()` function assembles the version of the application from the metadata of the Git repository. It searches for the latest "SemVer" [3] compatible version tag in the current branch and falls back to the default version from the application configuration if none is found. If at least one tag is found but it is not the latest commit of the current branch, the build metadata will be appended, consisting of the amount of commits ahead and the shortened reference hash (8 digits) of the latest commit from the current branch. The function is a early implementation of the Git `describe` command because support in `go-git` [1] has not been implemented yet. See the full compatibility comparison documentation with Git [4] as well as the proposed Git `describe` command implementation [5] for more details. The function returned a composed struct to store application version information and metadata that allows to use the version metadata for other tasks. It consists of a embedded `semver.Version` struct and additional fields that stores Git related information: - `GitCommitHash` (type `plumbing.Hash`) - The latest commit hash of the current branch. - `GitCommitsAhead` (type `int`) - The count of commits ahead to the latest Git tag from the current branch. - `GitLatestVersionTag` (type `plumbing.Reference`) - The latest Git version tag in the current branch. [1]: https://github.com/src-d/go-git/v4 [2]: https://github.com/Masterminds/semver/v3 [3]: https://semver.org [4]: https://github.com/src-d/go-git/blob/master/COMPATIBILITY.md [5]: src-d/go-git#816 Epic GH-33 Resolves GH-92
Signed-off-by: Eduardo Lezcano [email protected]