Skip to content

Commit 00fae69

Browse files
committed
add boolean property: 'files.dirty' if working dir is dirty
1 parent 3be6bad commit 00fae69

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/main/java/pl/project13/maven/git/GitCommitIdMojo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class GitCommitIdMojo extends AbstractMojo {
5959
public static final String BRANCH = "branch";
6060
public static final String COMMIT_ID = "commit.id";
6161
public static final String COMMIT_ID_ABBREV = "commit.id.abbrev";
62+
public static final String FILES_DIRTY = "files.dirty";
6263
public static final String COMMIT_DESCRIBE = "commit.id.describe";
6364
public static final String COMMIT_SHORT_DESCRIBE = "commit.id.describe-short";
6465
public static final String BUILD_AUTHOR_NAME = "build.user.name";

src/main/java/pl/project13/maven/git/GitDataProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public abstract class GitDataProvider {
3737
protected abstract String getGitDescribe() throws MojoExecutionException;
3838
protected abstract String getCommitId();
3939
protected abstract String getAbbrevCommitId() throws MojoExecutionException;
40+
protected abstract boolean isDirty() throws MojoExecutionException;
4041
protected abstract String getCommitAuthorName();
4142
protected abstract String getCommitAuthorEmail();
4243
protected abstract String getCommitMessageFull();
@@ -65,6 +66,8 @@ public void loadGitData(@NotNull Properties properties) throws IOException, Mojo
6566
put(properties, GitCommitIdMojo.COMMIT_ID, getCommitId());
6667
// git.commit.id.abbrev
6768
put(properties, GitCommitIdMojo.COMMIT_ID_ABBREV, getAbbrevCommitId());
69+
// git.files.dirty
70+
put(properties, GitCommitIdMojo.FILES_DIRTY, isDirty()? "true" : "false");
6871
// git.commit.author.name
6972
put(properties, GitCommitIdMojo.COMMIT_AUTHOR_NAME, getCommitAuthorName());
7073
// git.commit.author.email

src/main/java/pl/project13/maven/git/JGitProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ protected String getAbbrevCommitId() throws MojoExecutionException {
135135
return abbrevCommitId;
136136
}
137137

138+
@Override
139+
protected boolean isDirty() throws MojoExecutionException {
140+
Git gitObject = Git.wrap(git);
141+
try {
142+
return !gitObject.status().call().isClean();
143+
} catch (GitAPIException e) {
144+
throw new MojoExecutionException("Failed to get git status: " + e.getMessage(), e);
145+
}
146+
}
147+
138148
@Override
139149
protected String getCommitAuthorName() {
140150
String commitAuthor = headCommit.getAuthorIdent().getName();

src/main/java/pl/project13/maven/git/NativeGitProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ protected String getAbbrevCommitId() throws MojoExecutionException {
175175
return abbrevCommitId;
176176
}
177177

178+
@Override
179+
protected boolean isDirty() throws MojoExecutionException {
180+
String output = tryToRunGitCommand(canonical, "status --porcelain");
181+
return !output.trim().isEmpty();
182+
}
183+
178184
@Override
179185
protected String getCommitAuthorName() {
180186
return tryToRunGitCommand(canonical, "log -1 --pretty=format:\"%cn\"");

0 commit comments

Comments
 (0)