You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by im...@apache.org on 2014/07/18 18:40:36 UTC
[1/7] git commit: SCM-765 fix JGit provider to use the correct
commiter/author when committing changes
Repository: maven-scm
Updated Branches:
refs/heads/master abea2d9c8 -> 037ba69bc
SCM-765 fix JGit provider to use the correct commiter/author when committing changes
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/6a4ccf50
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/6a4ccf50
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/6a4ccf50
Branch: refs/heads/master
Commit: 6a4ccf507b73d92d33ee050dac8e2d977f7fb245
Parents: 692b76a
Author: imod <do...@fortysix.ch>
Authored: Fri Jul 18 00:45:07 2014 +0200
Committer: imod <do...@fortysix.ch>
Committed: Fri Jul 18 00:45:07 2014 +0200
----------------------------------------------------------------------
.../command/checkin/JGitCheckInCommand.java | 155 +++++++++++-
...GitCheckInCommandCommitterAuthorTckTest.java | 246 +++++++++++++++++++
2 files changed, 400 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/6a4ccf50/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 98c0f98..7e91cf0 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
@@ -33,15 +33,37 @@ import org.codehaus.plexus.util.StringUtils;
import org.eclipse.jgit.api.AddCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.UserConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.RefSpec;
import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;
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>
+ * </ol>
+ *
+ * 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>
+ * <br>
+ *
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
* @author Dominik Bartholdi (imod)
* @since 1.9
@@ -50,6 +72,15 @@ public class JGitCheckInCommand
extends AbstractCheckInCommand
implements GitCommand
{
+
+ 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";
+
/**
* {@inheritDoc}
*/
@@ -96,7 +127,10 @@ public class JGitCheckInCommand
List<ScmFile> checkedInFiles = Collections.emptyList();
if ( doCommit )
{
- RevCommit commitRev = git.commit().setMessage( message ).call();
+ UserInfo author = getAuthor(repo, git);
+ UserInfo committer = getCommitter(repo, git);
+
+ RevCommit commitRev = git.commit().setMessage( message ).setAuthor(author.name, author.email).setCommitter(committer.name, committer.email).call();
getLogger().info( "commit done: " + commitRev.getShortMessage() );
checkedInFiles = JGitUtils.getFilesInCommit( git.getRepository(), commitRev );
if ( getLogger().isDebugEnabled() )
@@ -132,4 +166,123 @@ public class JGitCheckInCommand
}
}
+ private static final class UserInfo
+ {
+ final String name;
+ final String email;
+
+ public UserInfo(String name, String email)
+ {
+ this.name = name;
+ this.email = email;
+ }
+ }
+
+ 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() )
+ {
+ committerName = user.getCommitterName();
+ }
+
+ // mvn parameter
+ if ( StringUtils.isBlank( committerName ) )
+ {
+ committerName = repo.getUser();
+ }
+
+ // git default
+ if ( StringUtils.isBlank( committerName ) )
+ {
+ 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() )
+ {
+ committerMail = user.getCommitterEmail();
+ }
+
+ if ( StringUtils.isBlank( committerMail ) )
+ {
+ String defaultDomain = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN );
+ defaultDomain = StringUtils.isNotBlank( defaultDomain ) ? defaultDomain : getHostname();
+
+ // mvn parameter (constructed with username) or git default
+ committerMail = StringUtils.isNotBlank( repo.getUser() ) ? repo.getUser() + "@" + defaultDomain : user.getCommitterEmail();
+ }
+
+ return new UserInfo( committerName, committerMail );
+ }
+
+ 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() )
+ {
+ authorName = user.getAuthorName();
+ }
+
+ // mvn parameter
+ if ( StringUtils.isBlank( authorName ) )
+ {
+ authorName = repo.getUser();
+ }
+
+ // git default
+ if ( StringUtils.isBlank( authorName ) )
+ {
+ 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() )
+ {
+ authorMail = user.getAuthorEmail();
+ }
+
+ if ( StringUtils.isBlank( authorMail ) )
+ {
+ String defaultDomain = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN );
+ defaultDomain = StringUtils.isNotBlank( defaultDomain ) ? defaultDomain : getHostname();
+
+ // mvn parameter (constructed with username) or git default
+ authorMail = StringUtils.isNotBlank( repo.getUser() ) ? repo.getUser() + "@" + defaultDomain : user.getAuthorEmail();
+ }
+
+ return new UserInfo( authorName, authorMail );
+ }
+
+ private String getHostname()
+ {
+ String hostname;
+ try
+ {
+ InetAddress localhost = java.net.InetAddress.getLocalHost();
+ hostname = localhost.getHostName();
+ }
+ catch ( UnknownHostException e )
+ {
+ getLogger().warn( "failed to resolve hostname to create mail address, defaulting to 'maven-scm-provider-jgit'" );
+ hostname = "maven-scm-provider-jgit";
+ }
+ return hostname;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/6a4ccf50/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
new file mode 100644
index 0000000..260be1c
--- /dev/null
+++ 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
@@ -0,0 +1,246 @@
+package org.apache.maven.scm.provider.git.jgit.command.checkin;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+import org.apache.maven.scm.provider.git.GitScmTestUtils;
+import org.apache.maven.scm.provider.git.command.checkin.GitCheckInCommandTckTest;
+import org.apache.maven.scm.provider.git.jgit.command.JGitUtils;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.codehaus.plexus.util.IOUtil;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.AnyObjectId;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.util.FileUtils;
+
+/**
+ * @author Dominik Bartholdi (imod)
+ */
+public class JGitCheckInCommandCommitterAuthorTckTest
+ extends GitCheckInCommandTckTest
+{
+ /**
+ * {@inheritDoc}
+ */
+ public String getScmUrl()
+ throws Exception
+ {
+ return GitScmTestUtils.getScmUrl( getRepositoryRoot(), "jgit" );
+ }
+
+ @Override
+ protected void deleteDirectory( File directory )
+ throws IOException
+ {
+ if( directory.exists() )
+ {
+ FileUtils.delete( directory, FileUtils.RECURSIVE | FileUtils.RETRY );
+ }
+ }
+
+ @Override
+ public void testCheckInCommandTest() throws Exception
+ {
+ File fooJava = new File( getWorkingCopy(), "src/main/java/Foo.java" );
+ assertFalse( "check Foo.java doesn't yet exist", fooJava.canRead() );
+
+ Git git = Git.open( getWorkingCopy() );
+
+ RevCommit head = getHeadCommit( git.getRepository() );
+ // Mark created the test repo...
+ assertEquals( "Mark Struberg", head.getCommitterIdent().getName() );
+ JGitUtils.closeRepo(git);
+
+ createAndCommitFile( fooJava, null );
+
+ // change user in config
+ git = Git.open( getWorkingCopy() );
+ StoredConfig config = git.getRepository().getConfig();
+ unsetConfig(config);
+ config.setString( "user", null, "name", "Dominik" );
+ config.setString( "user", null, "email", "domi@mycomp.com" );
+ config.save();
+
+ // make a commit
+ createAndCommitFile( fooJava, null );
+
+ // check new commit is done with new user in config
+ head = getHeadCommit( git.getRepository() );
+ assertEquals( "Dominik", head.getCommitterIdent().getName() );
+ assertEquals( "Dominik", head.getAuthorIdent().getName() );
+ assertEquals( "domi@mycomp.com", head.getAuthorIdent().getEmailAddress() );
+ assertEquals( "domi@mycomp.com", head.getCommitterIdent().getEmailAddress() );
+ JGitUtils.closeRepo( git );
+
+
+ // change user in config
+ git = Git.open( getWorkingCopy() );
+ config = git.getRepository().getConfig();
+ unsetConfig(config);
+ config.setString( "user", null, "name", "dbartholdi" );
+ config.save();
+
+ // make a change
+ createAndCommitFile( fooJava, null );
+
+ // check new commit is done with new user in config
+ head = getHeadCommit( git.getRepository() );
+ 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
+ git = Git.open( getWorkingCopy() );
+ config = git.getRepository().getConfig();
+ unsetConfig(config);
+ config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_MAILDOMAIN, "comp.com" );
+ config.save();
+
+ // make a change with an user on the commandline
+ createAndCommitFile( fooJava, "dude" );
+
+ // check new commit is done with new maven user in config
+ head = getHeadCommit( git.getRepository() );
+ assertEquals( "dude", head.getCommitterIdent().getName() );
+ assertEquals( "dude@comp.com", head.getCommitterIdent().getEmailAddress() );
+ assertEquals( "dude", head.getAuthorIdent().getName() );
+ assertEquals( "dude@comp.com", head.getAuthorIdent().getEmailAddress() );
+ 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" );
+
+ // check new commit is done with new maven user in config
+ head = getHeadCommit( git.getRepository() );
+ assertEquals( "dundy", head.getCommitterIdent().getName() );
+ assertEquals( "dundy", head.getAuthorIdent().getName() );
+ 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 );
+ }
+
+ private void unsetConfig(StoredConfig config) {
+ config.unsetSection( "user", null );
+ config.unset( "user", null, "name" );
+ // somehow unset does not always work on "user"
+ config.setString("user", null, "name", null);
+ config.setString("user", null, "email", null);
+ config.unsetSection( JGitCheckInCommand.GIT_MAVEN_SECTION, null );
+ }
+
+
+
+
+ private void createAndCommitFile(File file, String username) throws Exception,
+ ScmException, IOException {
+ createFooJava( file );
+
+ ScmRepository scmRepository = getScmRepository();
+ scmRepository.getProviderRepository().setUser(username);
+ AddScmResult addResult = getScmManager().add( scmRepository,
+ new ScmFileSet( getWorkingCopy(), "**/*.java" ) );
+
+ assertResultIsSuccess( addResult );
+
+ CheckInScmResult result =
+ getScmManager().checkIn( scmRepository, new ScmFileSet( getWorkingCopy(), "**/Foo.java" ), "Commit message" );
+
+ assertResultIsSuccess( result );
+ }
+
+
+ private RevCommit getHeadCommit(Repository repository) throws Exception
+ {
+ RevWalk rw = new RevWalk(repository);
+ AnyObjectId headId = repository.resolve(Constants.HEAD);
+ RevCommit head = rw.parseCommit(headId);
+ rw.release();;
+ return head;
+ }
+
+ private void createFooJava( File fooJava )
+ throws Exception
+ {
+ FileWriter output = new FileWriter( fooJava );
+
+ PrintWriter printer = new PrintWriter( output );
+ try
+ {
+ printer.println( "public class Foo" );
+ printer.println( "{" );
+
+ printer.println( " public void foo()" );
+ printer.println( " {" );
+ printer.println( " //" + System.currentTimeMillis() );
+ printer.println( " int i = 10;" );
+ printer.println( " }" );
+
+ printer.println( "}" );
+ }
+ finally
+ {
+ IOUtil.close( output );
+ IOUtil.close( printer );
+ }
+ }
+
+}
[4/7] git commit: fix formatting
Posted by im...@apache.org.
fix formatting
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/f2bc97d3
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/f2bc97d3
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/f2bc97d3
Branch: refs/heads/master
Commit: f2bc97d3a2e34848459ac8a52bd7f214ac0285d6
Parents: da08837
Author: imod <do...@fortysix.ch>
Authored: Fri Jul 18 06:20:41 2014 +0200
Committer: imod <do...@fortysix.ch>
Committed: Fri Jul 18 06:20:41 2014 +0200
----------------------------------------------------------------------
...GitCheckInCommandCommitterAuthorTckTest.java | 267 +++++++++----------
1 file changed, 133 insertions(+), 134 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/f2bc97d3/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 37e1842..87bb9c0 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
@@ -61,157 +61,156 @@ public class JGitCheckInCommandCommitterAuthorTckTest
protected void deleteDirectory( File directory )
throws IOException
{
- if( directory.exists() )
+ if ( directory.exists() )
{
FileUtils.delete( directory, FileUtils.RECURSIVE | FileUtils.RETRY );
}
}
-
+
@Override
- public void testCheckInCommandTest() throws Exception
+ public void testCheckInCommandTest()
+ throws Exception
{
- File fooJava = new File( getWorkingCopy(), "src/main/java/Foo.java" );
- assertFalse( "check Foo.java doesn't yet exist", fooJava.canRead() );
+ File fooJava = new File( getWorkingCopy(), "src/main/java/Foo.java" );
+ assertFalse( "check Foo.java doesn't yet exist", fooJava.canRead() );
- Git git = Git.open( getWorkingCopy() );
+ Git git = Git.open( getWorkingCopy() );
- RevCommit head = getHeadCommit( git.getRepository() );
- // Mark created the test repo...
- assertEquals( "Mark Struberg", head.getCommitterIdent().getName() );
- JGitUtils.closeRepo(git);
+ RevCommit head = getHeadCommit( git.getRepository() );
+ // Mark created the test repo...
+ assertEquals( "Mark Struberg", head.getCommitterIdent().getName() );
+ JGitUtils.closeRepo( git );
createAndCommitFile( fooJava, null );
-
- // change user in config
+
+ // change user in config
git = Git.open( getWorkingCopy() );
StoredConfig config = git.getRepository().getConfig();
- unsetConfig(config);
- config.setString( "user", null, "name", "Dominik" );
- config.setString( "user", null, "email", "domi@mycomp.com" );
- config.save();
-
- // make a commit
- createAndCommitFile( fooJava, null );
-
- // check new commit is done with new user in config
- head = getHeadCommit( git.getRepository() );
- assertEquals( "Dominik", head.getCommitterIdent().getName() );
- assertEquals( "Dominik", head.getAuthorIdent().getName() );
- assertEquals( "domi@mycomp.com", head.getAuthorIdent().getEmailAddress() );
- assertEquals( "domi@mycomp.com", head.getCommitterIdent().getEmailAddress() );
- JGitUtils.closeRepo( git );
-
-
- // change user in config
+ unsetConfig( config );
+ config.setString( "user", null, "name", "Dominik" );
+ config.setString( "user", null, "email", "domi@mycomp.com" );
+ config.save();
+
+ // make a commit
+ createAndCommitFile( fooJava, null );
+
+ // check new commit is done with new user in config
+ head = getHeadCommit( git.getRepository() );
+ assertEquals( "Dominik", head.getCommitterIdent().getName() );
+ assertEquals( "Dominik", head.getAuthorIdent().getName() );
+ assertEquals( "domi@mycomp.com", head.getAuthorIdent().getEmailAddress() );
+ assertEquals( "domi@mycomp.com", head.getCommitterIdent().getEmailAddress() );
+ JGitUtils.closeRepo( git );
+
+ // change user in config
git = Git.open( getWorkingCopy() );
config = git.getRepository().getConfig();
- unsetConfig(config);
- config.setString( "user", null, "name", "dbartholdi" );
- config.save();
-
- // make a change
- createAndCommitFile( fooJava, null );
-
- // check new commit is done with new user in config
- head = getHeadCommit( git.getRepository() );
- 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 );
-
-
- // unset a user and maven user but set default mail domain
+ unsetConfig( config );
+ config.setString( "user", null, "name", "dbartholdi" );
+ config.save();
+
+ // make a change
+ createAndCommitFile( fooJava, null );
+
+ // check new commit is done with new user in config
+ head = getHeadCommit( git.getRepository() );
+ 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 );
+
+ // 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, "comp.com" );
- config.save();
-
- // make a change with an user on the commandline
- createAndCommitFile( fooJava, "dude" );
-
- // check new commit is done with new maven user in config
- head = getHeadCommit( git.getRepository() );
- assertEquals( "dude", head.getCommitterIdent().getName() );
- assertEquals( "dude@comp.com", head.getCommitterIdent().getEmailAddress() );
- assertEquals( "dude", head.getAuthorIdent().getName() );
- assertEquals( "dude@comp.com", head.getAuthorIdent().getEmailAddress() );
- JGitUtils.closeRepo( git );
-
- // unset a user and maven user but set default mail domain
+ unsetConfig( config );
+ config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_MAILDOMAIN, "comp.com" );
+ config.save();
+
+ // make a change with an user on the commandline
+ createAndCommitFile( fooJava, "dude" );
+
+ // check new commit is done with new maven user in config
+ head = getHeadCommit( git.getRepository() );
+ assertEquals( "dude", head.getCommitterIdent().getName() );
+ assertEquals( "dude@comp.com", head.getCommitterIdent().getEmailAddress() );
+ assertEquals( "dude", head.getAuthorIdent().getName() );
+ 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
+ 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();
-
- // make a change with an user on the commandline
- createAndCommitFile( fooJava, "dundy" );
-
- // check new commit is done with new maven user in config
- head = getHeadCommit( git.getRepository() );
- assertEquals( "dundy", head.getCommitterIdent().getName() );
- assertEquals( "dundy", head.getAuthorIdent().getName() );
- 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
+ unsetConfig( config );
+ config.save();
+
+ // make a change with an user on the commandline
+ createAndCommitFile( fooJava, "dundy" );
+
+ // check new commit is done with new maven user in config
+ head = getHeadCommit( git.getRepository() );
+ assertEquals( "dundy", head.getCommitterIdent().getName() );
+ assertEquals( "dundy", head.getAuthorIdent().getName() );
+ 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 );
+ 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
+ * make sure the local .gitconfig is in a clean state
*/
- private void unsetConfig(StoredConfig config) {
- config.unsetSection( "user", null );
- config.unset( "user", null, "name" );
- // somehow unset does not always work on "user"
- config.setString("user", null, "name", null);
- config.setString("user", null, "email", null);
- config.unsetSection( JGitCheckInCommand.GIT_MAVEN_SECTION, null );
- }
-
-
-
-
- private void createAndCommitFile(File file, String username) throws Exception,
- ScmException, IOException {
- createFooJava( file );
+ private void unsetConfig( StoredConfig config )
+ {
+ config.unsetSection( "user", null );
+ config.unset( "user", null, "name" );
+ // somehow unset does not always work on "user"
+ config.setString( "user", null, "name", null );
+ config.setString( "user", null, "email", null );
+ config.unsetSection( JGitCheckInCommand.GIT_MAVEN_SECTION, null );
+ }
+
+ private void createAndCommitFile( File file, String username )
+ throws Exception, ScmException, IOException
+ {
+ createFooJava( file );
ScmRepository scmRepository = getScmRepository();
- scmRepository.getProviderRepository().setUser(username);
- AddScmResult addResult = getScmManager().add( scmRepository,
- new ScmFileSet( getWorkingCopy(), "**/*.java" ) );
+ scmRepository.getProviderRepository().setUser( username );
+ AddScmResult addResult = getScmManager().add( scmRepository, new ScmFileSet( getWorkingCopy(), "**/*.java" ) );
assertResultIsSuccess( addResult );
@@ -219,20 +218,20 @@ public class JGitCheckInCommandCommitterAuthorTckTest
getScmManager().checkIn( scmRepository, new ScmFileSet( getWorkingCopy(), "**/Foo.java" ), "Commit message" );
assertResultIsSuccess( result );
- }
-
-
- private RevCommit getHeadCommit(Repository repository) throws Exception
+ }
+
+ private RevCommit getHeadCommit( Repository repository )
+ throws Exception
{
- RevWalk rw = new RevWalk(repository);
- AnyObjectId headId = repository.resolve(Constants.HEAD);
- RevCommit head = rw.parseCommit(headId);
- rw.release();;
- return head;
+ RevWalk rw = new RevWalk( repository );
+ AnyObjectId headId = repository.resolve( Constants.HEAD );
+ RevCommit head = rw.parseCommit( headId );
+ rw.release();
+ return head;
}
-
+
private void createFooJava( File fooJava )
- throws Exception
+ throws Exception
{
FileWriter output = new FileWriter( fooJava );
[7/7] git commit: Merge branch 'SCM-765'
Posted by im...@apache.org.
Merge branch 'SCM-765'
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/037ba69b
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/037ba69b
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/037ba69b
Branch: refs/heads/master
Commit: 037ba69bced119de1618526e6977940908eeb7bc
Parents: abea2d9 e669c9a
Author: imod <do...@fortysix.ch>
Authored: Fri Jul 18 18:18:49 2014 +0200
Committer: imod <do...@fortysix.ch>
Committed: Fri Jul 18 18:18:49 2014 +0200
----------------------------------------------------------------------
.../command/checkin/JGitCheckInCommand.java | 147 +++++++++-
.../src/site/markdown/index.md.vm | 14 +
...GitCheckInCommandCommitterAuthorTckTest.java | 279 +++++++++++++++++++
3 files changed, 439 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
[6/7] git commit: allow enforcement of username as committer/author
Posted by im...@apache.org.
allow enforcement of username as committer/author
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/e669c9a0
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/e669c9a0
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/e669c9a0
Branch: refs/heads/master
Commit: e669c9a0bfd215bfd72a29fc7e9b12cc9f7c0117
Parents: 3047841
Author: imod <do...@fortysix.ch>
Authored: Fri Jul 18 07:03:06 2014 +0200
Committer: imod <do...@fortysix.ch>
Committed: Fri Jul 18 07:03:06 2014 +0200
----------------------------------------------------------------------
.../command/checkin/JGitCheckInCommand.java | 14 +++++++++++---
.../src/site/markdown/index.md.vm | 4 ++++
...GitCheckInCommandCommitterAuthorTckTest.java | 20 ++++++++++++++++++++
3 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e669c9a0/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 a85ebd4..b998638 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
@@ -53,7 +53,9 @@ import java.util.Set;
* </ol>
* the "maven-scm" config can be configured like this: <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> <br>
+ * <code>git config --global maven-scm.maildomain mycomp.com</code> <br>
+ * you can also enforce the usage of the username for the author and committer:<br>
+ * <code>git config --global maven-scm.forceUsername true</code> <br>
*
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
* @author Dominik Bartholdi (imod)
@@ -68,6 +70,8 @@ public class JGitCheckInCommand
protected static final String GIT_MAILDOMAIN = "maildomain";
+ protected static final String GIT_FORCE = "forceUsername";
+
/**
* {@inheritDoc}
*/
@@ -170,10 +174,12 @@ public class JGitCheckInCommand
private UserInfo getCommitter( ScmProviderRepository repo, Git git )
{
+ boolean forceMvnUser = git.getRepository().getConfig().getBoolean( GIT_MAVEN_SECTION, GIT_FORCE, false );
+
// git config
UserConfig user = git.getRepository().getConfig().get( UserConfig.KEY );
String committerName = null;
- if ( !user.isCommitterNameImplicit() )
+ if ( !forceMvnUser && !user.isCommitterNameImplicit() )
{
committerName = user.getCommitterName();
}
@@ -213,10 +219,12 @@ public class JGitCheckInCommand
private UserInfo getAuthor( ScmProviderRepository repo, Git git )
{
+ boolean forceMvnUser = git.getRepository().getConfig().getBoolean( GIT_MAVEN_SECTION, GIT_FORCE, false );
+
// git config
UserConfig user = git.getRepository().getConfig().get( UserConfig.KEY );
String authorName = null;
- if ( !user.isAuthorNameImplicit() )
+ if ( !forceMvnUser && !user.isAuthorNameImplicit() )
{
authorName = user.getAuthorName();
}
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e669c9a0/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
index e104bc2..d95a1a6 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
@@ -86,6 +86,10 @@ If you don't define a user in the .gitconfig, then the user passed as "username"
the hostname to be used as the domain. you can configure a default domain in the .gitconfig as follows:
git config --global maven-scm.maildomain mycomp.com
+
+You can also enforce the usage of the "username" for the author and committer (omit the default in the .gitconfig):
+
+ git config --global maven-scm.forceUsername true
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/e669c9a0/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 87bb9c0..10fdb85 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
@@ -141,6 +141,26 @@ public class JGitCheckInCommandCommitterAuthorTckTest
git = Git.open( getWorkingCopy() );
config = git.getRepository().getConfig();
unsetConfig( config );
+ config.setString( "user", null, "name", "dbartholdi" );
+ config.setBoolean( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_FORCE, true );
+ config.setString( JGitCheckInCommand.GIT_MAVEN_SECTION, null, JGitCheckInCommand.GIT_MAILDOMAIN, "anycomp.com" );
+ config.save();
+
+ // make a change with an user on the commandline
+ createAndCommitFile( fooJava, "dude" );
+
+ // check new commit is done with new maven user in config
+ head = getHeadCommit( git.getRepository() );
+ assertEquals( "dude", head.getCommitterIdent().getName() );
+ assertEquals( "dude@anycomp.com", head.getCommitterIdent().getEmailAddress() );
+ assertEquals( "dude", head.getAuthorIdent().getName() );
+ assertEquals( "dude@anycomp.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();
[2/7] git commit: simplify and add more tests
Posted by im...@apache.org.
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 <do...@fortysix.ch>
Authored: Fri Jul 18 06:15:20 2014 +0200
Committer: imod <do...@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" );
[3/7] git commit: add documentation
Posted by im...@apache.org.
add documentation
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/da088373
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/da088373
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/da088373
Branch: refs/heads/master
Commit: da088373469ec4901e46241d6c7503920508c813
Parents: d114bfb
Author: imod <do...@fortysix.ch>
Authored: Fri Jul 18 06:15:37 2014 +0200
Committer: imod <do...@fortysix.ch>
Committed: Fri Jul 18 06:15:37 2014 +0200
----------------------------------------------------------------------
.../src/site/markdown/index.md.vm | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/da088373/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
index 8734528..e104bc2 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/site/markdown/index.md.vm
@@ -68,6 +68,7 @@ Usage with the `maven-scm-plugin`
Examples
____
+
changelog
mvn org.apache.maven.plugins:maven-scm-plugin:${project.version}:changelog
@@ -76,7 +77,16 @@ release
mvn release:prepare release:perform -Dresume=false -Dusername=XXX -Dpassword=XXX
-
+
+Committer / Author
+____
+
+The jgit provider per default uses the information of the "user" section in the .gitconfig. If you explicitly configure a user there, this user will be used as author and committer.
+If you don't define a user in the .gitconfig, then the user passed as "username" with the maven execution is used. The email per default will be 'username'@hostname. If you don't like
+the hostname to be used as the domain. you can configure a default domain in the .gitconfig as follows:
+
+ git config --global maven-scm.maildomain mycomp.com
+
[5/7] git commit: formatting
Posted by im...@apache.org.
formatting
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/3047841b
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/3047841b
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/3047841b
Branch: refs/heads/master
Commit: 3047841b65c1e1b39e0e1559b04c76636d1f2ff1
Parents: f2bc97d
Author: imod <do...@fortysix.ch>
Authored: Fri Jul 18 06:52:49 2014 +0200
Committer: imod <do...@fortysix.ch>
Committed: Fri Jul 18 06:52:49 2014 +0200
----------------------------------------------------------------------
.../command/checkin/JGitCheckInCommand.java | 244 ++++++++++---------
1 file changed, 123 insertions(+), 121 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/3047841b/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 d6e55d4..a85ebd4 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,17 +47,13 @@ import java.util.Set;
/**
* This provider uses the following strategy to discover the committer and author name/mail for a commit:
* <ol>
- * <li>"user" section in .gitconfig</li>
- * <li>"username" passed to maven execution</li>
- * <li>default git config (system user and hostname for email)</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>
* </ol>
- *
- * the "maven-scm" config can be configured like this:
- *
- * <br>
+ * the "maven-scm" config can be configured like this: <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>
- * <br>
+ * <code>git config --global maven-scm.maildomain "mycomp.com"</code> <br>
*
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
* @author Dominik Bartholdi (imod)
@@ -67,11 +63,11 @@ public class JGitCheckInCommand
extends AbstractCheckInCommand
implements GitCommand
{
-
- protected static final String GIT_MAVEN_SECTION = "maven-scm";
-
- protected static final String GIT_MAILDOMAIN = "maildomain";
-
+
+ protected static final String GIT_MAVEN_SECTION = "maven-scm";
+
+ protected static final String GIT_MAILDOMAIN = "maildomain";
+
/**
* {@inheritDoc}
*/
@@ -118,10 +114,12 @@ public class JGitCheckInCommand
List<ScmFile> checkedInFiles = Collections.emptyList();
if ( doCommit )
{
- UserInfo author = getAuthor(repo, git);
- UserInfo committer = getCommitter(repo, git);
-
- RevCommit commitRev = git.commit().setMessage( message ).setAuthor(author.name, author.email).setCommitter(committer.name, committer.email).call();
+ UserInfo author = getAuthor( repo, git );
+ UserInfo committer = getCommitter( repo, git );
+
+ RevCommit commitRev =
+ git.commit().setMessage( message ).setAuthor( author.name, author.email ).setCommitter( committer.name,
+ committer.email ).call();
getLogger().info( "commit done: " + commitRev.getShortMessage() );
checkedInFiles = JGitUtils.getFilesInCommit( git.getRepository(), commitRev );
if ( getLogger().isDebugEnabled() )
@@ -157,114 +155,118 @@ public class JGitCheckInCommand
}
}
- private static final class UserInfo
+ private static final class UserInfo
+ {
+ final String name;
+
+ final String email;
+
+ public UserInfo( String name, String email )
+ {
+ this.name = name;
+ this.email = email;
+ }
+ }
+
+ private UserInfo getCommitter( ScmProviderRepository repo, Git git )
{
- final String name;
- final String email;
-
- public UserInfo(String name, String email)
- {
- this.name = name;
- this.email = email;
- }
+ // git config
+ UserConfig user = git.getRepository().getConfig().get( UserConfig.KEY );
+ String committerName = null;
+ if ( !user.isCommitterNameImplicit() )
+ {
+ committerName = user.getCommitterName();
+ }
+
+ // mvn parameter
+ if ( StringUtils.isBlank( committerName ) )
+ {
+ committerName = repo.getUser();
+ }
+
+ // git default
+ if ( StringUtils.isBlank( committerName ) )
+ {
+ committerName = user.getCommitterName();
+ }
+
+ // git config
+ String committerMail = null;
+ if ( !user.isCommitterEmailImplicit() )
+ {
+ committerMail = user.getCommitterEmail();
+ }
+
+ if ( StringUtils.isBlank( committerMail ) )
+ {
+ String defaultDomain = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN );
+ defaultDomain = StringUtils.isNotBlank( defaultDomain ) ? defaultDomain : getHostname();
+
+ // mvn parameter (constructed with username) or git default
+ committerMail =
+ StringUtils.isNotBlank( repo.getUser() ) ? repo.getUser() + "@" + defaultDomain
+ : user.getCommitterEmail();
+ }
+
+ return new UserInfo( committerName, committerMail );
}
-
- private UserInfo getCommitter( ScmProviderRepository repo, Git git )
+
+ private UserInfo getAuthor( ScmProviderRepository repo, Git git )
{
- // git config
- UserConfig user = git.getRepository().getConfig().get(UserConfig.KEY);
- String committerName = null;
- if ( !user.isCommitterNameImplicit() )
- {
- committerName = user.getCommitterName();
- }
-
- // mvn parameter
- if ( StringUtils.isBlank( committerName ) )
- {
- committerName = repo.getUser();
- }
-
- // git default
- if ( StringUtils.isBlank( committerName ) )
- {
- committerName = user.getCommitterName();
- }
-
- // git config
- String committerMail = null;
- if ( !user.isCommitterEmailImplicit() )
- {
- committerMail = user.getCommitterEmail();
- }
-
- if ( StringUtils.isBlank( committerMail ) )
- {
- String defaultDomain = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN );
- defaultDomain = StringUtils.isNotBlank( defaultDomain ) ? defaultDomain : getHostname();
-
- // mvn parameter (constructed with username) or git default
- committerMail = StringUtils.isNotBlank( repo.getUser() ) ? repo.getUser() + "@" + defaultDomain : user.getCommitterEmail();
- }
-
- return new UserInfo( committerName, committerMail );
+ // git config
+ UserConfig user = git.getRepository().getConfig().get( UserConfig.KEY );
+ String authorName = null;
+ if ( !user.isAuthorNameImplicit() )
+ {
+ authorName = user.getAuthorName();
+ }
+
+ // mvn parameter
+ if ( StringUtils.isBlank( authorName ) )
+ {
+ authorName = repo.getUser();
+ }
+
+ // git default
+ if ( StringUtils.isBlank( authorName ) )
+ {
+ authorName = user.getAuthorName();
+ }
+
+ // git config
+ String authorMail = null;
+ if ( !user.isAuthorEmailImplicit() )
+ {
+ authorMail = user.getAuthorEmail();
+ }
+
+ if ( StringUtils.isBlank( authorMail ) )
+ {
+ String defaultDomain = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN );
+ defaultDomain = StringUtils.isNotBlank( defaultDomain ) ? defaultDomain : getHostname();
+
+ // mvn parameter (constructed with username) or git default
+ authorMail =
+ StringUtils.isNotBlank( repo.getUser() ) ? repo.getUser() + "@" + defaultDomain : user.getAuthorEmail();
+ }
+
+ return new UserInfo( authorName, authorMail );
}
-
- private UserInfo getAuthor( ScmProviderRepository repo, Git git )
+
+ private String getHostname()
{
- // git config
- UserConfig user = git.getRepository().getConfig().get(UserConfig.KEY);
- String authorName = null;
- if ( !user.isAuthorNameImplicit() )
- {
- authorName = user.getAuthorName();
- }
-
- // mvn parameter
- if ( StringUtils.isBlank( authorName ) )
- {
- authorName = repo.getUser();
- }
-
- // git default
- if ( StringUtils.isBlank( authorName ) )
- {
- authorName = user.getAuthorName();
- }
-
- // git config
- String authorMail = null;
- if ( !user.isAuthorEmailImplicit() )
- {
- authorMail = user.getAuthorEmail();
- }
-
- if ( StringUtils.isBlank( authorMail ) )
- {
- String defaultDomain = git.getRepository().getConfig().getString( GIT_MAVEN_SECTION, null, GIT_MAILDOMAIN );
- defaultDomain = StringUtils.isNotBlank( defaultDomain ) ? defaultDomain : getHostname();
-
- // mvn parameter (constructed with username) or git default
- authorMail = StringUtils.isNotBlank( repo.getUser() ) ? repo.getUser() + "@" + defaultDomain : user.getAuthorEmail();
- }
-
- return new UserInfo( authorName, authorMail );
+ String hostname;
+ try
+ {
+ InetAddress localhost = java.net.InetAddress.getLocalHost();
+ hostname = localhost.getHostName();
+ }
+ catch ( UnknownHostException e )
+ {
+ getLogger().warn( "failed to resolve hostname to create mail address, defaulting to 'maven-scm-provider-jgit'" );
+ hostname = "maven-scm-provider-jgit";
+ }
+ return hostname;
}
-
- private String getHostname()
- {
- String hostname;
- try
- {
- InetAddress localhost = java.net.InetAddress.getLocalHost();
- hostname = localhost.getHostName();
- }
- catch ( UnknownHostException e )
- {
- getLogger().warn( "failed to resolve hostname to create mail address, defaulting to 'maven-scm-provider-jgit'" );
- hostname = "maven-scm-provider-jgit";
- }
- return hostname;
- }
}