-
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 all commits
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 |
|---|---|---|
|
|
@@ -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\""); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * This file is part of git-commit-id-plugin by Konrad Malawski <konrad.malawski@java.pl> | ||
| * | ||
| * git-commit-id-plugin is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * git-commit-id-plugin is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with git-commit-id-plugin. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package pl.project13.maven.git; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.Maps; | ||
| import org.apache.maven.project.MavenProject; | ||
| import org.eclipse.jgit.lib.Repository; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
|
|
||
| import static org.fest.assertions.Assertions.assertThat; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| /** | ||
| * @author Adam Batkin | ||
| */ | ||
| public class GitCommitIdMojoDirtyFilesTest { | ||
|
|
||
| @Test | ||
| public void testDetectCleanWorkingDirectory() throws Exception { | ||
| File dotGitDirectory = AvailableGitTestRepo.GIT_WITH_NO_CHANGES.getDir(); | ||
| GitDescribeConfig gitDescribeConfig = new GitDescribeConfig(); | ||
| gitDescribeConfig.setSkip(false); | ||
|
|
||
| String prefix = "git"; | ||
| int abbrevLength = 7; | ||
| String dateFormat = "dd.MM.yyyy '@' HH:mm:ss z"; | ||
| boolean verbose = true; | ||
|
|
||
| GitCommitIdMojo mojo = new GitCommitIdMojo(); | ||
| mojo.setDotGitDirectory(dotGitDirectory); | ||
| mojo.setPrefix(prefix); | ||
| mojo.setAbbrevLength(abbrevLength); | ||
| mojo.setDateFormat(dateFormat); | ||
| mojo.setVerbose(verbose); | ||
| mojo.useNativeGit(false); | ||
| mojo.setGitDescribe(gitDescribeConfig); | ||
|
|
||
|
|
||
| mojo.runningTests = true; | ||
| mojo.project = mock(MavenProject.class, RETURNS_MOCKS); | ||
| when(mojo.project.getPackaging()).thenReturn("jar"); | ||
|
|
||
| mojo.execute(); | ||
|
|
||
| Properties properties = mojo.getProperties(); | ||
|
|
||
| assertThat(properties.get("git.commit.files.dirty")).isEqualTo("false"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDetectDirtyWorkingDirectory() throws Exception { | ||
| File dotGitDirectory = AvailableGitTestRepo.GIT_WITH_CHANGES.getDir(); | ||
| GitDescribeConfig gitDescribeConfig = new GitDescribeConfig(); | ||
| gitDescribeConfig.setSkip(false); | ||
|
|
||
| String prefix = "git"; | ||
| int abbrevLength = 7; | ||
| String dateFormat = "dd.MM.yyyy '@' HH:mm:ss z"; | ||
| boolean verbose = true; | ||
|
|
||
| GitCommitIdMojo mojo = new GitCommitIdMojo(); | ||
| mojo.setDotGitDirectory(dotGitDirectory); | ||
| mojo.setPrefix(prefix); | ||
| mojo.setAbbrevLength(abbrevLength); | ||
| mojo.setDateFormat(dateFormat); | ||
| mojo.setVerbose(verbose); | ||
| mojo.useNativeGit(false); | ||
| mojo.setGitDescribe(gitDescribeConfig); | ||
|
|
||
|
|
||
| mojo.runningTests = true; | ||
| mojo.project = mock(MavenProject.class, RETURNS_MOCKS); | ||
| when(mojo.project.getPackaging()).thenReturn("jar"); | ||
|
|
||
| mojo.execute(); | ||
|
|
||
| Properties properties = mojo.getProperties(); | ||
|
|
||
| assertThat(properties.get("git.commit.files.dirty")).isEqualTo("true"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add file.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ref: refs/heads/master |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 79c5c38ca494525c1d2d3127af13476f9759957d |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [core] | ||
| repositoryformatversion = 0 | ||
| filemode = true | ||
| bare = false | ||
| logallrefupdates = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Unnamed repository; edit this file 'description' to name the repository. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # git ls-files --others --exclude-from=.git/info/exclude | ||
| # Lines that start with '#' are comments. | ||
| # For a project mostly in C, the following would be a good set of | ||
| # exclude patterns (uncomment them if you want to use them): | ||
| # *.[oa] | ||
| # *~ | ||
| /_git_dir/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 79c5c38ca494525c1d2d3127af13476f9759957d refs/heads/master |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0000000000000000000000000000000000000000 79c5c38ca494525c1d2d3127af13476f9759957d Adam Batkin <adam@batkin.net> 1417588098 -0500 commit (initial): add file.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0000000000000000000000000000000000000000 79c5c38ca494525c1d2d3127af13476f9759957d Adam Batkin <adam@batkin.net> 1417588098 -0500 commit (initial): add file.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| P pack-ca141c03c134fe0537a3990df45432bf0bf0396e.pack | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # pack-refs with: peeled fully-peeled | ||
| 79c5c38ca494525c1d2d3127af13476f9759957d refs/heads/master |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| add file.txt | ||
|
|
||
| # Please enter the commit message for your changes. Lines starting | ||
| # with '#' will be ignored, and an empty message aborts the commit. | ||
| # | ||
| # Date: Wed Dec 3 00:35:29 2014 -0500 | ||
| # | ||
| # On branch master | ||
| # | ||
| # Initial commit | ||
| # | ||
| # Changes to be committed: | ||
| # new file: file.txt | ||
| # | ||
| # Untracked files: | ||
| # _git_dir/ | ||
| # |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ref: refs/heads/master |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [core] | ||
| repositoryformatversion = 0 | ||
| filemode = true | ||
| bare = false | ||
| logallrefupdates = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Unnamed repository; edit this file 'description' to name the repository. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # git ls-files --others --exclude-from=.git/info/exclude | ||
| # Lines that start with '#' are comments. | ||
| # For a project mostly in C, the following would be a good set of | ||
| # exclude patterns (uncomment them if you want to use them): | ||
| # *.[oa] | ||
| # *~ | ||
| /_git_dir/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| e65f5b15be7a302936db2cf50430eae7ef4ecc6f refs/heads/master |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 0000000000000000000000000000000000000000 ff21f63ce400e3ff07b0b318dd4c61a0fb368bd2 Adam Batkin <adam@batkin.net> 1417584929 -0500 commit (initial): add file.txt | ||
| ff21f63ce400e3ff07b0b318dd4c61a0fb368bd2 95412a0871d9c4e1421d71d4fc513556e8d6f985 Adam Batkin <adam@batkin.net> 1417588894 -0500 commit (amend): add file.txt | ||
| 95412a0871d9c4e1421d71d4fc513556e8d6f985 e65f5b15be7a302936db2cf50430eae7ef4ecc6f Adam Batkin <adam@batkin.net> 1417588980 -0500 commit (amend): add file.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 0000000000000000000000000000000000000000 ff21f63ce400e3ff07b0b318dd4c61a0fb368bd2 Adam Batkin <adam@batkin.net> 1417584929 -0500 commit (initial): add file.txt | ||
| ff21f63ce400e3ff07b0b318dd4c61a0fb368bd2 95412a0871d9c4e1421d71d4fc513556e8d6f985 Adam Batkin <adam@batkin.net> 1417588894 -0500 commit (amend): add file.txt | ||
| 95412a0871d9c4e1421d71d4fc513556e8d6f985 e65f5b15be7a302936db2cf50430eae7ef4ecc6f Adam Batkin <adam@batkin.net> 1417588980 -0500 commit (amend): add file.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| P pack-789f4a0163258377aa2befda15661493c77f3ee1.pack | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # pack-refs with: peeled fully-peeled | ||
| e65f5b15be7a302936db2cf50430eae7ef4ecc6f refs/heads/master |
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.
looks ok, though we should probably measure performance impact of wrapping at some point...