Skip to content

Commit

Permalink
Implemented #133 tags on current commit in jgit and native
Browse files Browse the repository at this point in the history
It's hacky as in native... oh well, <3 jgit.

Resolves #133
  • Loading branch information
ktoso committed Oct 21, 2014
1 parent fba077c commit 6b1da67
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 173 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ maven git commit id plugin
==================================
[![Build Status](https://secure.travis-ci.org/ktoso/maven-git-commit-id-plugin.svg?branch=master)](http://travis-ci.org/ktoso/maven-git-commit-id-plugin)

git-commit-id-plugin is a plugin quite similar to https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 fo example but as buildnumber only supports svn (which is very sad) and cvs (which is even more sad, and makes bunnies cry) I had to quickly develop an git version of such a plugin. For those who don't know the previous plugins, let me explain what this plugin does:
git-commit-id-plugin is a plugin quite similar to https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 fo example but as buildnumber at the time when I started this plugin only supported CVS and SVN, something had to be done.
I had to quickly develop an git version of such a plugin. For those who don't know the previous plugins, let me explain what this plugin does:

Use cases
=========
Expand Down Expand Up @@ -35,7 +36,7 @@ A detailed description of using the pluing is available in the <a href="https://

Versions
--------
The current version is **2.1.10**.
The current version is **2.1.11**:

You can check the available versions by visiting [search.maven.org](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22pl.project13.maven%22%20AND%20a%3A%22git-commit-id-plugin%22), though using the newest is obviously the best choice.

Expand Down Expand Up @@ -93,7 +94,7 @@ It's really simple to setup this plugin; below is a sample pom that you may base
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.1.10</version>
<version>2.1.11</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -239,6 +240,7 @@ Now you just have to include such a properties file in your project under `/src/

```
git.branch=${git.branch}
git.commit.tags=${git.tags}
git.commit.id.describe=${git.commit.id.describe}
Expand Down Expand Up @@ -270,6 +272,7 @@ Start out with with adding the above steps to your project, next paste this **gi

<bean name="gitRepositoryInformation" class="pl.project13.maven.example.git.GitRepositoryState">
<property name="branch" value="${git.branch}"/>
<property name="tags" value="${git.tags}"/>
<property name="describe" value="${git.commit.id.describe}"/>
<property name="commitId" value="${git.commit.id}"/>
<property name="commitIdAbbrev" value="${git.commit.id.abbrev}"/>
Expand Down Expand Up @@ -300,6 +303,7 @@ import org.codehaus.jackson.annotate.JsonWriteNullProperties;
@JsonWriteNullProperties(true)
public class GitRepositoryState {
String branch; // =${git.branch}
String branch; // =${git.tags} // comma separated tag names
String describe; // =${git.commit.id.describe}
String shortDescribe; // =${git.commit.id.describe-short}
String commitId; // =${git.commit.id}
Expand Down Expand Up @@ -352,6 +356,7 @@ In the end *this is what this service would return*:
```json
{
"branch" : "testing-maven-git-plugin",
"tags" : "v2.1.11,testing",
"describe" : "v2.1.0-2-g2346463",
"describeShort" : "v2.1.0-2",
"commitTime" : "06.01.1970 @ 16:16:26 CET",
Expand Down
48 changes: 21 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>2.1.11-SNAPSHOT</version>
<version>2.1.10-SNAPSHOT</version>
<name>Git Commit Id Plugin Maven Mojo</name>
<description>
git-commit-id-plugin is a plugin quite similar to
https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 for example but as buildnumber
only supports svn (which is very sad) and cvs (which is even more sad).
https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4 for example but as buildnumber at
the time when I started this plugin only supported CVS and SVN, something had to be done.
This plugin makes basic repository information available through maven resources. This can be used to display
"what version is this?" or "who has deployed this and when, from which branch?" information at runtime - making
it easy to find things like "oh, that isn't deployed yet, I'll test it tomorrow" and making both testers and
Expand Down Expand Up @@ -46,7 +46,7 @@
<id>ktoso</id>
<name>Konrad Malawski</name>
<email>[email protected]</email>
<organization>Project13.pl</organization>
<organization>project13.pl</organization>
<url>http://blog.project13.pl</url>
</developer>
</developers>
Expand Down Expand Up @@ -100,12 +100,6 @@
<version>2.2.3</version>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>

<!-- Joda Time -->
<dependency>
<groupId>joda-time</groupId>
Expand Down Expand Up @@ -165,7 +159,7 @@
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<type>jar</type>
Expand Down Expand Up @@ -247,22 +241,22 @@
</configuration>
</plugin>

<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>generated-helpmojo</id>
<goals>
<goal>helpmojo</goal>
</goals>
<configuration>
<goalPrefix>git-commit-id</goalPrefix>
<helpPackageName>pl.project13.maven</helpPackageName>
</configuration>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<artifactId>maven-plugin-plugin</artifactId>-->
<!--<version>${maven-plugin-api.version}</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>generated-helpmojo</id>-->
<!--<goals>-->
<!--<goal>helpmojo</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<goalPrefix>git-commit-id</goalPrefix>-->
<!--<helpPackageName>pl.project13.maven</helpPackageName>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
</plugins>
</build>

Expand Down
8 changes: 0 additions & 8 deletions release.properties

This file was deleted.

47 changes: 15 additions & 32 deletions src/main/java/pl/project13/jgit/DescribeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,8 @@

/**
* Implements git's <pre>describe</pre> command.
* <p/>
* <code><pre>
* usage: git describe [options] <committish>*
* or: git describe [options] --dirty
* <p/>
* --contains find the tag that comes after the commit
* --debug debug search strategy on stderr
* --all use any ref in .git/refs
* --tags use any tag in .git/refs/tags
* --long always use long format
* --abbrev[=<n>] use <n> digits to display SHA-1s
* --exact-match only output exact matches
* --candidates <n> consider <n> most recent tags (default: 10)
* --match <pattern> only consider tags matching <pattern>
* --always show abbreviated commit object as fallback
* --dirty[=<mark>] append <mark> on dirty working tree (default: "-dirty")
* </pre></code>
*
* @author <a href="mailto:[email protected]">Konrad 'ktoso' Malawski</a>
* @author Konrad Malawski
*/
public class DescribeCommand extends GitCommand<DescribeResult> {

Expand Down Expand Up @@ -153,9 +136,9 @@ public DescribeCommand withLoggerBridge(LoggerBridge bridge) {

/**
* <pre>--always</pre>
* <p/>
*
* Show uniquely abbreviated commit object as fallback.
* <p/>
*
* <pre>true</pre> by default.
*/
@NotNull
Expand All @@ -167,13 +150,13 @@ public DescribeCommand always(boolean always) {

/**
* <pre>--long</pre>
* <p/>
*
* Always output the long format (the tag, the number of commits and the abbreviated commit name)
* even when it matches a tag. This is useful when you want to see parts of the commit object name
* in "describe" output, even when the commit in question happens to be a tagged version. Instead
* of just emitting the tag name, it will describe such a commit as v1.2-0-gdeadbee (0th commit
* since tag v1.2 that points at object deadbee....).
* <p/>
*
* <pre>false</pre> by default.
*/
@NotNull
Expand All @@ -187,11 +170,11 @@ public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {

/**
* <pre>--abbrev=N</pre>
* <p/>
*
* Instead of using the default <em>7 hexadecimal digits</em> as the abbreviated object name,
* use <b>N</b> digits, or as many digits as needed to form a unique object name.
* <p/>
* An <n> of 0 will suppress long format, only showing the closest tag.
*
* An `n` of 0 will suppress long format, only showing the closest tag.
*/
@NotNull
public DescribeCommand abbrev(@Nullable Integer n) {
Expand All @@ -210,22 +193,22 @@ public DescribeCommand abbrev(@Nullable Integer n) {
* Instead of using only the annotated tags, use any tag found in .git/refs/tags.
* This option enables matching a lightweight (non-annotated) tag.
* </p>
* <p/>
*
* <p>Searching for lightweight tags is <b>false</b> by default.</p>
* <p/>
*
* Example:
* <pre>
* b6a73ed - (HEAD, master)
* d37a598 - (v1.0-fixed-stuff) - a lightweight tag (with no message)
* 9597545 - (v1.0) - an annotated tag
*
* > git describe
* $ git describe
* annotated-tag-2-gb6a73ed # the nearest "annotated" tag is found
*
* > git describe --tags
* $ git describe --tags
* lightweight-tag-1-gb6a73ed # the nearest tag (including lightweights) is found
* </pre>
* <p/>
*
* <p>
* Using only annotated tags to mark builds may be useful if you're using tags to help yourself with annotating
* things like "i'll get back to that" etc - you don't need such tags to be exposed. But if you want lightweight
Expand All @@ -249,7 +232,7 @@ public DescribeCommand tags() {
}

/**
* Apply all configuration options passed in with {@param config}.
* Apply all configuration options passed in with `config`.
* If a setting is null, it will not be applied - so for abbrev for example, the default 7 would be used.
*
* @return itself, after applying the settings
Expand Down Expand Up @@ -342,7 +325,7 @@ public DescribeResult call() throws GitAPIException {
* Prepares the final result of this command.
* It tries to put as much information as possible into the result,
* and will fallback to a plain commit hash if nothing better is returnable.
* <p/>
*
* The exact logic is following what <pre>git-describe</pre> would do.
*/
private DescribeResult createDescribeResult(ObjectReader objectReader, ObjectId headCommitId, boolean dirty, @Nullable Pair<Integer, String> howFarFromWhichTag) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/pl/project13/jgit/DescribeResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* Represents the result of a <code>git describe</code> command.
* <p/>
*
* See {@link pl.project13.jgit.DescribeResult#toString()} for a detailed information how this result looks like.
*/
public class DescribeResult {
Expand Down Expand Up @@ -115,15 +115,15 @@ public DescribeResult withCommitIdAbbrev(int n) {
* | |--------------- the number of commits away from the found tag. So "2414721" is 14 commits ahead of "v1.0.4", in this example.
* |-------------------- the "nearest" tag, to the mentioned commit.
* </pre>
* <p/>
*
* Other outputs may look like:
* <pre>
* v1.0.4 -- if the repository is "on a tag"
* v1.0.4-DEV -- if the repository is "on a tag", but in "dirty" state
* 2414721 -- a plain commit id hash if not tags were defined (of determined "near" this commit).
* It does NOT include the "g" prefix, that is used in the "full" describe output format!
* </pre>
* <p/>
*
* For more details (on when what output will be returned etc), see <code>man git-describe</code>.
* In general, you can assume it's a "best effort" approach, to give you as much info about the repo state as possible.
*
Expand Down Expand Up @@ -170,7 +170,7 @@ public String dirtyMarker() {
* This is following git's behaviour - so any git tooling should be happy with this output.
* </p>
* <p>
* Notes about the abbriverated object id:<br/>
* Notes about the abbriverated object id:
* Git will try to use your given abbrev lenght, but when it's to short to guarantee uniqueness -
* a longer one will be used (which WILL guarantee uniqueness).
* If you need the full commit id, it's always available via {@link pl.project13.jgit.DescribeResult#commitObjectId()}.
Expand Down
Loading

0 comments on commit 6b1da67

Please sign in to comment.