make commit conditional, to stop unrequired commits

Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/f6a8425e
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/f6a8425e
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/f6a8425e

Branch: refs/heads/master
Commit: f6a8425e40158241e193fb90c4dd3432cf2fb06a
Parents: 7ccb6e7
Author: imod <d...@fortysix.ch>
Authored: Tue Jun 18 20:05:09 2013 +0200
Committer: imod <d...@fortysix.ch>
Committed: Tue Jun 18 20:05:09 2013 +0200

----------------------------------------------------------------------
 .../git/jgit/command/checkin/JGitCheckInCommand.java     | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/f6a8425e/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
 
b/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
index d44cb3a..ae42d19 100644
--- 
a/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
+++ 
b/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
@@ -39,6 +39,7 @@ import org.eclipse.jgit.api.AddCommand;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.PushCommand;
 import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.transport.CredentialsProvider;
 import org.eclipse.jgit.transport.RefSpec;
 import org.eclipse.jgit.transport.RemoteConfig;
@@ -56,9 +57,11 @@ public class JGitCheckInCommand extends 
AbstractCheckInCommand implements GitCom
                try {
                        Git git = Git.open(fileSet.getBasedir());
 
+                       boolean doCommit = false;
                        if (!fileSet.getFileList().isEmpty()) {
                                AddCommand add = git.add();
                                for (File file : fileSet.getFileList()) {
+                                       doCommit = true;
                                        add.addFilepattern(file.getPath());
                                }
                                add.call();
@@ -67,16 +70,22 @@ public class JGitCheckInCommand extends 
AbstractCheckInCommand implements GitCom
                                Set<String> changeds = 
git.status().call().getModified();
                                if (changeds.isEmpty()) {
                                        // warn there is nothing to add
+                                       getLogger().warn("there are no files to 
be added");
+                                       doCommit = false;
                                } else {
                                        AddCommand add = git.add();
                                        for (String changed : changeds) {
                                                add.addFilepattern(changed);
+                                               doCommit = true;
                                        }
                                        add.call();
                                }
                        }
 
-                       git.commit().setMessage(message).call();
+                       if (doCommit) {
+                               RevCommit call = 
git.commit().setMessage(message).call();
+                               getLogger().info("commit done: " + 
call.getShortMessage());
+                       }
 
                        if (repo.isPushChanges()) {
                                String branch = version != null ? 
version.getName() : null;

Reply via email to