maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject [2/7] git commit: simplify and add more tests
Date Fri, 18 Jul 2014 16:40:37 GMT
simplify and add more tests


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

Branch: refs/heads/master
Commit: d114bfbb052b7eef8d73d2ade38f94159704abf0
Parents: 6a4ccf5
Author: imod <domi@fortysix.ch>
Authored: Fri Jul 18 06:15:20 2014 +0200
Committer: imod <domi@fortysix.ch>
Committed: Fri Jul 18 06:15:20 2014 +0200

----------------------------------------------------------------------
 .../command/checkin/JGitCheckInCommand.java     | 34 +++---------
 ...GitCheckInCommandCommitterAuthorTckTest.java | 58 ++++++++++++--------
 2 files changed, 44 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/d114bfbb/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
index 7e91cf0..d6e55d4 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommand.java
@@ -47,7 +47,6 @@ import java.util.Set;
 /**
  * This provider uses the following strategy to discover the committer and author name/mail
for a commit:
  * <ol>
- *   <li>"maven-scm" section in .gitconfig</li>
  *   <li>"user" section in .gitconfig</li>
  *   <li>"username" passed to maven execution</li>
  *   <li>default git config (system user and hostname for email)</li>
@@ -55,10 +54,6 @@ import java.util.Set;
  * 
  * the "maven-scm" config can be configured like this:
  * 
- * the user to be used:<br>
- * <code>git config --global maven-scm.name "dude"</code>
- * <br>
- * <code>git config --global maven-scm.email "dude@mydomain.com"</code>
  * <br>
  * the default email domain to be used (will be used to create an email from the username
passed to maven):<br>
  * <code>git config --global maven-scm.maildomain "mycomp.com"</code>
@@ -75,10 +70,6 @@ public class JGitCheckInCommand
 	
 	protected static final String GIT_MAVEN_SECTION = "maven-scm";
 	
-	protected static final String GIT_USERNAME = "name";
-	
-	protected static final String GIT_EMAIL = "email";
-	
 	protected static final String GIT_MAILDOMAIN = "maildomain";
 	
     /**
@@ -180,12 +171,10 @@ public class JGitCheckInCommand
     
     private UserInfo getCommitter( ScmProviderRepository repo, Git git ) 
     {
-    	// mvn scm git config
-    	String committerName = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION,
null, GIT_USERNAME );
-    	
     	// git config
     	UserConfig user = git.getRepository().getConfig().get(UserConfig.KEY);
-    	if ( StringUtils.isBlank( committerName ) && !user.isCommitterNameImplicit()
)
+    	String committerName = null;
+    	if ( !user.isCommitterNameImplicit() )
     	{
     		committerName = user.getCommitterName();
     	}
@@ -201,13 +190,10 @@ public class JGitCheckInCommand
     	{
     		committerName = user.getCommitterName();
     	}
-    	
 
-    	// maven scm git config
-    	String committerMail = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION,
null, GIT_EMAIL );
-    	
     	// git config
-    	if ( StringUtils.isBlank( committerMail ) && !user.isCommitterEmailImplicit()
)
+    	String committerMail = null;
+    	if (  !user.isCommitterEmailImplicit() )
     	{
     		committerMail = user.getCommitterEmail();
     	}
@@ -226,12 +212,10 @@ public class JGitCheckInCommand
     
     private UserInfo getAuthor( ScmProviderRepository repo, Git git ) 
     {
-       	// mvn scm config
-    	String authorName = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null,
GIT_USERNAME );
-    	
     	// git config
     	UserConfig user = git.getRepository().getConfig().get(UserConfig.KEY);
-    	if ( StringUtils.isBlank( authorName ) && !user.isAuthorNameImplicit() )
+    	String authorName = null;
+    	if ( !user.isAuthorNameImplicit() )
     	{
     		authorName = user.getAuthorName();
     	}
@@ -248,11 +232,9 @@ public class JGitCheckInCommand
     		authorName = user.getAuthorName();
     	}
     	
-    	// maven scm git config
-    	String authorMail = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null,
GIT_EMAIL );
-    	
     	// git config
-    	if ( StringUtils.isBlank( authorMail ) && !user.isAuthorEmailImplicit() )
+    	String authorMail = null;
+    	if ( !user.isAuthorEmailImplicit() )
     	{
     		authorMail = user.getAuthorEmail();
     	}

http://git-wip-us.apache.org/repos/asf/maven-scm/blob/d114bfbb/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommandCommitterAuthorTckTest.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommandCommitterAuthorTckTest.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommandCommitterAuthorTckTest.java
index 260be1c..37e1842 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommandCommitterAuthorTckTest.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkin/JGitCheckInCommandCommitterAuthorTckTest.java
@@ -117,27 +117,6 @@ public class JGitCheckInCommandCommitterAuthorTckTest
     	assertEquals( "dbartholdi", head.getCommitterIdent().getName() );
     	assertFalse( "no mail domain is configured, git system default should be used", head.getCommitterIdent().getEmailAddress().contains(
"dbartholdi" ) );
     	JGitUtils.closeRepo( git );		
-
-    	
-    	
-    	// set a user in the maven section of the git config 
-        git = Git.open( getWorkingCopy() );
-        config = git.getRepository().getConfig();
-        unsetConfig(config);
-		config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_USERNAME,
"Dude" );
-		config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_EMAIL,
"dude@mydomain.com" );
-		config.save();
-		
-		// make a change
-		createAndCommitFile( fooJava, null );
-				
-		// check new commit is done with new maven user in config
-    	head = getHeadCommit( git.getRepository() );
-    	assertEquals( "Dude", head.getCommitterIdent().getName() );
-    	assertEquals( "Dude", head.getAuthorIdent().getName() );
-    	assertEquals( "dude@mydomain.com", head.getCommitterIdent().getEmailAddress() );
-    	assertEquals( "dude@mydomain.com", head.getAuthorIdent().getEmailAddress() );
-    	JGitUtils.closeRepo( git );		
     	
     	
     	// unset a user and maven user but set default mail domain 
@@ -158,13 +137,27 @@ public class JGitCheckInCommandCommitterAuthorTckTest
     	assertEquals( "dude@comp.com", head.getAuthorIdent().getEmailAddress() );    	
     	JGitUtils.closeRepo( git );		
 
+    	// unset a user and maven user but set default mail domain 
+        git = Git.open( getWorkingCopy() );
+        config = git.getRepository().getConfig();
+        unsetConfig(config);
+		config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_MAILDOMAIN,
"anycomp.com" );
+		config.save();
+
+		// make a change with no username given
+		createAndCommitFile( fooJava, null );
+				
+		// check new commit does not contain the configured email domain
+    	head = getHeadCommit( git.getRepository() );
+    	assertFalse( head.getCommitterIdent().getEmailAddress().contains("anycomp.com") );
+    	assertFalse( head.getAuthorIdent().getEmailAddress().contains("anycomp.com") );
+    	JGitUtils.closeRepo( git );	
     	
     	// unset a user and full maven section 
         git = Git.open( getWorkingCopy() );
         config = git.getRepository().getConfig();
         unsetConfig(config);
 		config.save();
-		config.getString("user", null, "name");
 
 		// make a change with an user on the commandline
 		createAndCommitFile( fooJava, "dundy" );
@@ -176,8 +169,29 @@ public class JGitCheckInCommandCommitterAuthorTckTest
     	assertTrue( "the maven user (from parameter) name must be in the committer mail when
nothing else is configured", head.getCommitterIdent().getEmailAddress().contains( "dundy"
) );
     	assertTrue( "the user name (from parameter) must be in the author mail when nothing
else is configured", head.getAuthorIdent().getEmailAddress().contains( "dundy" ) );
     	JGitUtils.closeRepo( git );
+    	
+    	
+    	// unset all configs 
+        git = Git.open( getWorkingCopy() );
+        config = git.getRepository().getConfig();
+        unsetConfig(config);
+		config.save();
+
+		// make a change with no user on the commandline
+		createAndCommitFile( fooJava, null );
+				
+		// check new commit is has a committer/author with email set
+    	head = getHeadCommit( git.getRepository() );
+    	assertNotNull( head.getCommitterIdent().getName() );
+    	assertNotNull( head.getAuthorIdent().getName() );
+    	assertNotNull( head.getCommitterIdent().getEmailAddress() );
+    	assertNotNull( head.getAuthorIdent().getEmailAddress() );
+    	JGitUtils.closeRepo( git );
     }
 
+    /**
+     * make sure the local .gitconfig is in a clean state 
+     */
 	private void unsetConfig(StoredConfig config) {
 		config.unsetSection( "user", null );
 		config.unset( "user", null, "name" );


Mime
View raw message