1 package org.apache.maven.scm.provider.git.gitexe.command.status;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
35
36
37 public class GitStatusCommand
38 extends AbstractStatusCommand
39 implements GitCommand
40 {
41
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
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 }