001 package org.apache.maven.scm.provider.git.gitexe.command.status; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import org.apache.maven.scm.ScmException; 023 import org.apache.maven.scm.ScmFileSet; 024 import org.apache.maven.scm.command.status.AbstractStatusCommand; 025 import org.apache.maven.scm.command.status.StatusScmResult; 026 import org.apache.maven.scm.provider.ScmProviderRepository; 027 import org.apache.maven.scm.provider.git.command.GitCommand; 028 import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository; 029 import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils; 030 import org.codehaus.plexus.util.cli.CommandLineUtils; 031 import org.codehaus.plexus.util.cli.Commandline; 032 033 /** 034 * @author <a href="mailto:brett@apache.org">Brett Porter</a> 035 * @version $Id: GitStatusCommand.java 1375087 2012-08-20 16:10:26Z olamy $ 036 */ 037 public class GitStatusCommand 038 extends AbstractStatusCommand 039 implements GitCommand 040 { 041 /** {@inheritDoc} */ 042 protected StatusScmResult executeStatusCommand( ScmProviderRepository repo, ScmFileSet fileSet ) 043 throws ScmException 044 { 045 Commandline cl = createCommandLine( (GitScmProviderRepository) repo, fileSet ); 046 047 GitStatusConsumer consumer = new GitStatusConsumer( getLogger(), fileSet.getBasedir() ); 048 049 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); 050 051 int exitCode; 052 053 exitCode = GitCommandLineUtils.execute( cl, consumer, stderr, getLogger() ); 054 if ( exitCode != 0 ) 055 { 056 // git-status returns non-zero if nothing to do 057 if ( getLogger().isInfoEnabled() ) 058 { 059 getLogger().info( "nothing added to commit but untracked files present (use \"git add\" to track)" ); 060 } 061 } 062 063 return new StatusScmResult( cl.toString(), consumer.getChangedFiles() ); 064 } 065 066 // ---------------------------------------------------------------------- 067 // 068 // ---------------------------------------------------------------------- 069 070 public static Commandline createCommandLine( GitScmProviderRepository repository, ScmFileSet fileSet ) 071 { 072 Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "status" ); 073 cl.addArguments( new String[] { "--porcelain" } ); 074 return cl; 075 } 076 }