-
Notifications
You must be signed in to change notification settings - Fork 304
add boolean property: 'files.dirty' if working dir is dirty #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ public abstract class GitDataProvider { | |
| protected abstract String getGitDescribe() throws MojoExecutionException; | ||
| protected abstract String getCommitId(); | ||
| protected abstract String getAbbrevCommitId() throws MojoExecutionException; | ||
| protected abstract boolean isDirty() throws MojoExecutionException; | ||
| protected abstract String getCommitAuthorName(); | ||
| protected abstract String getCommitAuthorEmail(); | ||
| protected abstract String getCommitMessageFull(); | ||
|
|
@@ -65,6 +66,8 @@ public void loadGitData(@NotNull Properties properties) throws IOException, Mojo | |
| put(properties, GitCommitIdMojo.COMMIT_ID, getCommitId()); | ||
| // git.commit.id.abbrev | ||
| put(properties, GitCommitIdMojo.COMMIT_ID_ABBREV, getAbbrevCommitId()); | ||
| // git.files.dirty | ||
| put(properties, GitCommitIdMojo.FILES_DIRTY, isDirty()? "true" : "false"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is same as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true. It's also autoboxing just to extract the textual value |
||
| // git.commit.author.name | ||
| put(properties, GitCommitIdMojo.COMMIT_AUTHOR_NAME, getCommitAuthorName()); | ||
| // git.commit.author.email | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,16 @@ protected String getAbbrevCommitId() throws MojoExecutionException { | |
| return abbrevCommitId; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isDirty() throws MojoExecutionException { | ||
| Git gitObject = Git.wrap(git); | ||
| try { | ||
| return !gitObject.status().call().isClean(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks ok, though we should probably measure performance impact of wrapping at some point... |
||
| } catch (GitAPIException e) { | ||
| throw new MojoExecutionException("Failed to get git status: " + e.getMessage(), e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected String getCommitAuthorName() { | ||
| String commitAuthor = headCommit.getAuthorIdent().getName(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,12 @@ protected String getAbbrevCommitId() throws MojoExecutionException { | |
| return abbrevCommitId; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isDirty() throws MojoExecutionException { | ||
| String output = tryToRunGitCommand(canonical, "status --porcelain"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was very expensive, I have reimplemented it to not kill performance on large dirty repositories :-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable. But I'm curious if
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not the speed up change.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I missed that.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return !output.trim().isEmpty(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getCommitAuthorName() { | ||
| return tryToRunGitCommand(canonical, "log -1 --pretty=format:\"%cn\""); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does not match any naming convention.
please previx with commit.id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it doesn't match any naming convention, but it's also not part of the commit id or anything like that. This particular property has more to do with the files on the filesystem than anything else though. It's easy enough for me to change the name, but I don't think that "commit.id.files.dirty" (or anything starting "commit.id") is really intuitive. "commit.files.dirty" maybe?