View Javadoc

1   package org.apache.maven.scm.provider.git.gitexe.command.status;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.ScmException;
23  import org.apache.maven.scm.ScmFileSet;
24  import org.apache.maven.scm.command.status.AbstractStatusCommand;
25  import org.apache.maven.scm.command.status.StatusScmResult;
26  import org.apache.maven.scm.provider.ScmProviderRepository;
27  import org.apache.maven.scm.provider.git.command.GitCommand;
28  import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
29  import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils;
30  import org.codehaus.plexus.util.cli.CommandLineUtils;
31  import org.codehaus.plexus.util.cli.Commandline;
32  
33  /**
34   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
35   *
36   */
37  public class GitStatusCommand
38      extends AbstractStatusCommand
39      implements GitCommand
40  {
41      /** {@inheritDoc} */
42      protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet )
43          throws ScmException
44      {
45          Commandline cl = createCommandLine( (GitScmProviderRepository) repo, fileSet );
46  
47          GitStatusConsumer consumer = new GitStatusConsumer( getLogger(), fileSet.getBasedir() );
48  
49          CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
50  
51          int exitCode;
52  
53          exitCode = GitCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
54          if ( exitCode != 0 )
55          {
56              // git-status returns non-zero if nothing to do
57              if ( getLogger().isInfoEnabled() )
58              {
59                  getLogger().info( "nothing added to commit but untracked files present (use \"git add\" to track)" );
60              }
61          }
62  
63          return new StatusScmResult( cl.toString(), consumer.getChangedFiles() );
64      }
65  
66      // ----------------------------------------------------------------------
67      //
68      // ----------------------------------------------------------------------
69  
70      public static Commandline createCommandLine( GitScmProviderRepository repository, ScmFileSet fileSet )
71      {
72          Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "status" );
73          cl.addArguments( new String[] { "--porcelain" } );
74          return cl;
75      }
76  }