Skip to content

Commit 6a5101a

Browse files
committed
introduce DETACHED_HEAD metadata
1 parent 7913c84 commit 6a5101a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/main/java/fr/brouillard/oss/jgitver/impl/ScriptVersionStrategy.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ public Version build(Commit head, List<Commit> parents) throws VersionCalculatio
131131
metaProps.put(Metadatas.COMMIT_TIMESTAMP.name(), GitUtils.getTimestamp(rc.getAuthorIdent().getWhen().toInstant()));
132132
}
133133

134-
// Extra convenient metadata
135-
metaProps.put("DETACHED_HEAD",
136-
GitUtils.isDetachedHead(getRepository()));
137-
138134
metaProps.put("BASE_COMMIT_ON_HEAD",
139135
isBaseCommitOnHead(head, base));
140136

@@ -283,6 +279,7 @@ public ScriptVersionStrategy setScript(String script) {
283279
return TO_INTEGER;
284280
case DIRTY:
285281
case ANNOTATED:
282+
case DETACHED_HEAD:
286283
return TO_BOOLEAN;
287284
default: return IDENTITY;
288285
}

src/main/java/fr/brouillard/oss/jgitver/impl/VersionStrategy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package fr.brouillard.oss.jgitver.impl;
1717

18+
import java.io.IOException;
1819
import java.util.Comparator;
1920
import java.util.List;
2021
import java.util.Optional;
@@ -135,6 +136,11 @@ protected Version getBaseVersionAndRegisterMetadata(Commit base, Ref tagToUse) {
135136
getRegistrar().registerMetadata(Metadatas.BASE_TAG, tagName);
136137
}
137138

139+
try {
140+
getRegistrar().registerMetadata(Metadatas.DETACHED_HEAD, "" + GitUtils.isDetachedHead(getRepository()));
141+
} catch (IOException ioe) {
142+
// ignore
143+
}
138144
getRegistrar().registerMetadata(Metadatas.ANNOTATED,"" + GitUtils.isAnnotated(tagToUse));
139145
getRegistrar().registerMetadata(Metadatas.BASE_VERSION, baseVersion.toString());
140146
getRegistrar().registerMetadata(Metadatas.CURRENT_VERSION_MAJOR, Integer.toString(baseVersion.getMajor()));

src/main/java/fr/brouillard/oss/jgitver/metadata/Metadatas.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ public enum Metadatas {
166166
/**
167167
* True if the current HEAD is on an annotated tag, false otherwise
168168
*/
169-
ANNOTATED
169+
ANNOTATED,
170+
/**
171+
* True if the current HEAD is detached, false otherwise
172+
*/
173+
DETACHED_HEAD
170174
;
171175
}

0 commit comments

Comments
 (0)