Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
44 changes: 42 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,36 @@
<artifactId>git-commit-id-plugin</artifactId>
<packaging>pom</packaging>

<version>2.1.8-SNAPSHOT</version>
<version>2.1.10</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).
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
developers life easier.

The data currently exported is like this (that's the end effect from the GitRepositoryState Bean):
{
"branch" : "testing-maven-git-plugin",
"commitTime" : "06.01.1970 @ 16:16:26 CET",
"commitId" : "787e39f61f99110e74deed68ab9093088d64b969",
"commitUserName" : "Konrad Malawski",
"commitUserEmail" : "konrad.malawski@java.pl",
"commitMessageFull" : "releasing my fun plugin :-) + fixed some typos + cleaned up directory structure + added
license etc",
"commitMessageShort" : "releasing my fun plugin :-)",
"buildTime" : "06.01.1970 @ 16:17:53 CET",
"buildUserName" : "Konrad Malawski",
"buildUserEmail" : "konrad.malawski@java.pl"
}

Note that the data is exported via maven resource filtering and is really easy to use with spring -
which I've explained in detail in this readme https://github.com/ktoso/maven-git-commit-id-plugin
</description>
<url>http://www.blog.project13.pl</url>

<modules>
Expand Down Expand Up @@ -64,6 +91,12 @@
<version>${maven-plugin-api.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand All @@ -81,7 +114,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0</version>
<version>15.0</version>
</dependency>

<!-- IntelliJ Annotations -->
Expand Down Expand Up @@ -135,6 +168,13 @@
<type>jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>pl.pragmatists</groupId>
<artifactId>JUnitParams</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/pl/project13/jgit/DescribeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public DescribeCommand always(boolean always) {
public DescribeCommand forceLongFormat(@Nullable Boolean forceLongFormat) {
if (forceLongFormat != null) {
this.forceLongFormat = forceLongFormat;
log("--long = %s", forceLongFormat);
log("--long =", forceLongFormat);
}
return this;
}
Expand Down Expand Up @@ -312,21 +312,22 @@ public DescribeResult call() throws GitAPIException {
// check if dirty
boolean dirty = findDirtyState(repo);

if (hasTags(headCommit, tagObjectIdToName)) {
if (hasTags(headCommit, tagObjectIdToName) && !forceLongFormat) {
String tagName = tagObjectIdToName.get(headCommit).iterator().next();
log("The commit we're on is a Tag ([",tagName,"]), returning.");
log("The commit we're on is a Tag ([",tagName,"]) and forceLongFormat == false, returning.");

return new DescribeResult(tagName, dirty, dirtyOption);
}

if (foundZeroTags(tagObjectIdToName)) {
// get commits, up until the nearest tag
List<RevCommit> commits = findCommitsUntilSomeTag(repo, headCommit, tagObjectIdToName);

// if there is no tags or any tag is not on that branch then return generic describe
if (foundZeroTags(tagObjectIdToName) || commits.isEmpty()) {
return new DescribeResult(objectReader, headCommitId, dirty, dirtyOption)
.withCommitIdAbbrev(abbrev);
}

// get commits, up until the nearest tag
List<RevCommit> commits = findCommitsUntilSomeTag(repo, headCommit, tagObjectIdToName);

// check how far away from a tag we are

int distance = distanceBetween(repo, headCommit, commits.get(0));
Expand All @@ -350,7 +351,7 @@ private DescribeResult createDescribeResult(ObjectReader objectReader, ObjectId
.withCommitIdAbbrev(abbrev);

} else if (howFarFromWhichTag.first > 0 || forceLongFormat) {
return new DescribeResult(objectReader, howFarFromWhichTag.second, howFarFromWhichTag.first, headCommitId, dirty, dirtyOption)
return new DescribeResult(objectReader, howFarFromWhichTag.second, howFarFromWhichTag.first, headCommitId, dirty, dirtyOption, forceLongFormat)
.withCommitIdAbbrev(abbrev); // we're a bit away from a tag

} else if (howFarFromWhichTag.first == 0) {
Expand Down Expand Up @@ -425,7 +426,7 @@ private List<RevCommit> findCommitsUntilSomeTag(Repository repo, RevCommit head,
}
}

throw new RuntimeException("Did not find any commits until some tag");
return Collections.emptyList();
} catch (Exception e) {
throw new RuntimeException("Unable to find commits until some tag", e);
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/pl/project13/jgit/DescribeResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class DescribeResult {
private boolean dirty;
private String dirtyMarker;

private boolean forceLongFormat;

private ObjectReader objectReader;

public static final DescribeResult EMPTY = new DescribeResult("");
Expand All @@ -58,7 +60,7 @@ public DescribeResult(@NotNull String tagName) {
}

public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, @Nullable ObjectId commitId) {
this(objectReader, tagName, commitsAwayFromTag, commitId, false, Optional.<String>absent());
this(objectReader, tagName, commitsAwayFromTag, commitId, false, Optional.<String>absent(), false);
}

public DescribeResult(@NotNull ObjectReader objectReader, @NotNull ObjectId commitId) {
Expand All @@ -69,13 +71,14 @@ public DescribeResult(@NotNull ObjectReader objectReader, @NotNull ObjectId comm
}

public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, ObjectId commitId, boolean dirty, String dirtyMarker) {
this(objectReader, tagName, commitsAwayFromTag, commitId, dirty, Optional.of(dirtyMarker));
this(objectReader, tagName, commitsAwayFromTag, commitId, dirty, Optional.of(dirtyMarker), false);
}

public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, ObjectId commitId, boolean dirty, Optional<String> dirtyMarker) {
public DescribeResult(@NotNull ObjectReader objectReader, String tagName, int commitsAwayFromTag, ObjectId commitId, boolean dirty, Optional<String> dirtyMarker, boolean forceLongFormat) {
this(objectReader, commitId, dirty, dirtyMarker);
this.tagName = Optional.of(tagName);
this.commitsAwayFromTag = commitsAwayFromTag;
this.forceLongFormat = forceLongFormat;
}

public DescribeResult(@NotNull ObjectReader objectReader, @NotNull ObjectId commitId, boolean dirty, @NotNull Optional<String> dirtyMarker) {
Expand Down Expand Up @@ -145,6 +148,9 @@ private boolean abbrevZeroHidesCommitsPartOfDescribe() {

@Nullable
public String commitsAwayFromTag() {
if (forceLongFormat) {
return String.valueOf(commitsAwayFromTag);
}
return commitsAwayFromTag == 0 ? null : String.valueOf(commitsAwayFromTag);
}

Expand Down
Loading