001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.provider.git; 020 021import org.apache.maven.scm.ScmFileSet; 022import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository; 023import org.apache.maven.scm.provider.git.util.GitUtil; 024import org.apache.maven.scm.providers.gitlib.settings.Settings; 025import org.codehaus.plexus.util.cli.Commandline; 026 027/** 028 * Command utilities for git commands. 029 * 030 * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a> 031 */ 032public class GitCommandUtils { 033 034 private GitCommandUtils() {} 035 036 public static Commandline getBaseCommand(String commandName, GitScmProviderRepository repo, ScmFileSet fileSet) { 037 return getBaseCommand(commandName, repo, fileSet, null); 038 } 039 040 public static Commandline getBaseCommand( 041 String commandName, GitScmProviderRepository repo, ScmFileSet fileSet, String options) { 042 Settings settings = GitUtil.getSettings(); 043 044 Commandline cl = new Commandline(); 045 046 cl.setExecutable(settings.getGitCommand()); 047 048 cl.setWorkingDirectory(fileSet.getBasedir().getAbsolutePath()); 049 050 if (settings.getTraceGitCommand() != null) { 051 cl.addEnvironment("GIT_TRACE", settings.getTraceGitCommand()); 052 } 053 054 cl.createArg().setLine(options); 055 cl.createArg().setValue(commandName); 056 057 return cl; 058 } 059 060 public static String getRevParseDateFormat() { 061 return GitUtil.getSettings().getRevParseDateFormat(); 062 } 063}