|
| 1 | +# git-depth |
| 2 | + |
| 3 | +Computes depths of git revision graphs |
| 4 | + |
| 5 | +## Motivation |
| 6 | + |
| 7 | +In the days of Subversion, it was easy to derive version numbers from the Subversion revision number. |
| 8 | +Ever since distributed version control became the norm, this is no longer possible. |
| 9 | +Instead, a mechanism external to version control is typically used to allocate version numbers, |
| 10 | +which makes builds irreproducible. |
| 11 | + |
| 12 | +This project proposes a different approach: the build number is derived from |
| 13 | +the structure of the git commit graph. Therefore, repeated builds starting at the same |
| 14 | +commit derive the same version number. |
| 15 | + |
| 16 | +We guarantee that walking along a branch will produce strictly increasing |
| 17 | +numbers, except when one of the user-specified files change. |
| 18 | +In that case the version number resets. |
| 19 | + |
| 20 | +Typically, this file will be a `VERSION` file containing the current major and minor version numbers. |
| 21 | +The result of `git-depth` can then be used as a patch number |
| 22 | +and appended to the contents of this file to produce a complete version. |
| 23 | +Incrementing major or minor version will automatically reset patch to zero. |
| 24 | + |
| 25 | +## Getting Started |
| 26 | + |
| 27 | +1. Download binaries from [releases][1] and place them somewhere in your path. |
| 28 | +2. Create your version file. |
| 29 | + |
| 30 | + $ echo 1.0 >VERSION |
| 31 | + $ git add VERSION |
| 32 | + $ git commit -m "Add VERSION file" |
| 33 | + |
| 34 | +3. Use `git-depth` to calculate the version patch number. |
| 35 | + |
| 36 | + $ git-depth HEAD VERSION |
| 37 | + 0 |
| 38 | + |
| 39 | +4. You can also automatically prepend the contents of the VERSION file. |
| 40 | + |
| 41 | + $ git-depth -c HEAD VERSION |
| 42 | + 1.0.0 |
| 43 | + |
| 44 | +4. Add more commits. |
| 45 | + |
| 46 | + $ echo fix >>file.txt |
| 47 | + $ git commit -am "Fixes to file.txt" |
| 48 | + $ git-depth -c HEAD VERSION |
| 49 | + 1.0.1 |
| 50 | + $ echo the previous fix did not work >>file.txt |
| 51 | + $ git commit -am "More fixes to file.txt" |
| 52 | + $ git-depth -c HEAD VERSION |
| 53 | + 1.0.2 |
| 54 | + |
| 55 | +5. Increase the minor version and observe the patch number reset. |
| 56 | + |
| 57 | + $ echo 1.1 >VERSION |
| 58 | + $ git commit -am "Bump version to 1.1" |
| 59 | + $ git-depth -c HEAD VERSION |
| 60 | + 1.1.0 |
| 61 | + |
| 62 | +## License |
| 63 | + |
| 64 | +The project itself is licensed under the MIT license. |
| 65 | +However, the released binaries embed libgit2, which is licensed under GPL, |
| 66 | +and as such the binary releases are licensed as GPL a well. |
| 67 | + |
| 68 | + [1]: https://github.com/avast/git-depth/releases |
0 commit comments