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 java.io.File;
23 import java.net.URI;
24
25 import org.apache.maven.scm.ScmException;
26 import org.apache.maven.scm.ScmFileSet;
27 import org.apache.maven.scm.command.status.AbstractStatusCommand;
28 import org.apache.maven.scm.command.status.StatusScmResult;
29 import org.apache.maven.scm.provider.ScmProviderRepository;
30 import org.apache.maven.scm.provider.git.command.GitCommand;
31 import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils;
32 import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
33 import org.codehaus.plexus.util.cli.CommandLineUtils;
34 import org.codehaus.plexus.util.cli.Commandline;
35
36
37
38
39
40 public class GitStatusCommand
41 extends AbstractStatusCommand
42 implements GitCommand
43 {
44
45 protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet )
46 throws ScmException
47 {
48 Commandline clRevparse = createRevparseShowToplevelCommand(fileSet);
49
50 CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
51 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
52
53 URI relativeRepositoryPath = null;
54
55 int exitCode;
56
57 exitCode = GitCommandLineUtils.execute( clRevparse, stdout, stderr, getLogger() );
58 if ( exitCode != 0 )
59 {
60
61 if ( getLogger().isInfoEnabled() )
62 {
63 getLogger().info( "Could not resolve toplevel" );
64 }
65 }
66 else
67 {
68 relativeRepositoryPath = GitStatusConsumer.resolveURI( stdout.getOutput().trim(), fileSet.getBasedir().toURI() );
69 }
70
71 Commandline cl = createCommandLine( (GitScmProviderRepository) repo, fileSet );
72
73 GitStatusConsumer consumer = new GitStatusConsumer( getLogger(), fileSet.getBasedir(), relativeRepositoryPath );
74
75 stderr = new CommandLineUtils.StringStreamConsumer();
76
77 exitCode = GitCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
78 if ( exitCode != 0 )
79 {
80
81 if ( getLogger().isInfoEnabled() )
82 {
83 getLogger().info( "nothing added to commit but untracked files present (use \"git add\" to track)" );
84 }
85 }
86
87 return new StatusScmResult( cl.toString(), consumer.getChangedFiles() );
88 }
89
90
91
92
93
94 public static Commandline createCommandLine( GitScmProviderRepository repository, ScmFileSet fileSet )
95 {
96 Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "status" );
97 cl.addArguments( new String[] { "--porcelain", "." } );
98 return cl;
99 }
100
101 public static Commandline createRevparseShowToplevelCommand( ScmFileSet fileSet )
102 {
103 Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "rev-parse" );
104 cl.addArguments( new String[] { "--show-toplevel" } );
105 return cl;
106 }
107 }